Fix connection leak and panic at close operation #171
1 changed files with 5 additions and 1 deletions
|
@ -86,6 +86,8 @@ type client interface {
|
||||||
type clientStatus interface {
|
type clientStatus interface {
|
||||||
// isHealthy checks if the connection can handle requests.
|
// isHealthy checks if the connection can handle requests.
|
||||||
isHealthy() bool
|
isHealthy() bool
|
||||||
|
// isDialed checks if the connection was created.
|
||||||
|
|||||||
|
isDialed() bool
|
||||||
// setUnhealthy marks client as unhealthy.
|
// setUnhealthy marks client as unhealthy.
|
||||||
setUnhealthy()
|
setUnhealthy()
|
||||||
// address return address of endpoint.
|
// address return address of endpoint.
|
||||||
|
@ -2809,9 +2811,11 @@ func (p *Pool) Close() {
|
||||||
// close all clients
|
// close all clients
|
||||||
for _, pools := range p.innerPools {
|
for _, pools := range p.innerPools {
|
||||||
for _, cli := range pools.clients {
|
for _, cli := range pools.clients {
|
||||||
|
if cli.isDialed() {
|
||||||
fyrchik
commented
Wouldn't it be better from the client POV to just allow closing even undialed clients? Wouldn't it be better from the client POV to just allow closing even undialed clients?
alexvanin
commented
It would, but simple solution down below didn't work, so I suppose changes should be done on api-go level as well.
Function comment clearly tells us It would, but simple solution down below didn't work, so I suppose changes should be done on api-go level as well.
```go
func (c *Client) Close() error {
if c.c.Conn() != nil {
return c.c.Conn().Close()
}
return nil
```
Function comment clearly tells us `MUST NOT be called before successful Dial`. So invoker (pool) should check dial state, which it does now.
|
|||||||
_ = cli.close()
|
_ = cli.close()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// SyncContainerWithNetwork applies network configuration received via
|
// SyncContainerWithNetwork applies network configuration received via
|
||||||
|
|
Loading…
Reference in a new issue
isDialled -> isDialed