Skip to content

Commit

Permalink
Merge pull request #113 from arangodb/fix-vst-fail-on-created-cb
Browse files Browse the repository at this point in the history
Close the connection when the initial onCreatedCallback fails
  • Loading branch information
ewoutp authored Apr 24, 2018
2 parents 13d52d4 + a3d8689 commit a7d74cb
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion vst/protocol/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,16 @@ func (c *Transport) CloseIdleConnections() (closed, remaining int) {
c.connMutex.Lock()
defer c.connMutex.Unlock()

for i, conn := range c.connections {
for i := 0; i < len(c.connections); {
conn := c.connections[i]
if conn.IsClosed() || conn.IsIdle(c.IdleConnTimeout) {
// Remove connection from list
c.connections = append(c.connections[:i], c.connections[i+1:]...)
// Close connection
go conn.Close()
closed++
} else {
i++
}
}

Expand Down Expand Up @@ -150,6 +153,7 @@ func (c *Transport) getConnection(ctx context.Context) (*Connection, error) {
// Invoke callback
if cb := c.onConnectionCreated; cb != nil {
if err := cb(ctx, conn); err != nil {
conn.Close()
return nil, driver.WithStack(err)
}
}
Expand Down

0 comments on commit a7d74cb

Please sign in to comment.