Skip to content

Commit

Permalink
not connected *nats.Conn will Close() and release resources before ov…
Browse files Browse the repository at this point in the history
…erride
  • Loading branch information
octu0 committed Aug 19, 2020
1 parent ee879f0 commit 870e573
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/nats-io/nats.go"
)

// ConnPool implements pool of *nats.Conn of a bounded channel
type ConnPool struct {
pool chan *nats.Conn
url string
Expand Down Expand Up @@ -35,7 +36,10 @@ func (p *ConnPool) Get() (*nats.Conn, error) {
case nc = <-p.pool:
// reuse exists pool
if nc.IsConnected() != true {
// disconnected conn to create new *nats.Conn
// Close to be sure
nc.Close()

// disconnected conn, create new *nats.Conn
nc, err = p.connect()
}
default:
Expand Down

0 comments on commit 870e573

Please sign in to comment.