Ensure safety before reuse of pipe
This commit is contained in:
parent
201333fdee
commit
8e82d76788
|
@ -177,7 +177,10 @@ func (c *Checker) CheckAddrZeroLinger(addr string, timeout time.Duration, zeroLi
|
|||
func (c *Checker) waitConnectResult(fd int, timeout time.Duration) error {
|
||||
// get a pipe of connect result
|
||||
resultPipe := c.getPipe()
|
||||
defer c.putBackPipe(resultPipe)
|
||||
defer func() {
|
||||
c.deregisterResultPipe(fd)
|
||||
c.putBackPipe(resultPipe)
|
||||
}()
|
||||
|
||||
// this must be done before registerEvents
|
||||
c.registerResultPipe(fd, resultPipe)
|
||||
|
@ -190,6 +193,10 @@ func (c *Checker) waitConnectResult(fd int, timeout time.Duration) error {
|
|||
return c.waitPipeTimeout(resultPipe, timeout)
|
||||
}
|
||||
|
||||
func (c *Checker) deregisterResultPipe(fd int) {
|
||||
c.fdResultPipes.Delete(fd)
|
||||
}
|
||||
|
||||
func (c *Checker) registerResultPipe(fd int, pipe chan error) {
|
||||
// NOTE: the pipe should have been put back if c.fdResultPipes[fd] exists.
|
||||
c.fdResultPipes.Store(fd, pipe)
|
||||
|
|
|
@ -19,5 +19,13 @@ func (p *pipePool) getPipe() chan error {
|
|||
}
|
||||
|
||||
func (p *pipePool) putBackPipe(pipe chan error) {
|
||||
p.cleanPipe(pipe)
|
||||
p.pool.Put(pipe)
|
||||
}
|
||||
|
||||
func (p *pipePool) cleanPipe(pipe chan error) {
|
||||
select {
|
||||
case <-pipe:
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue