Skip to content

Commit

Permalink
Don't call onActive for connection that aren't active
Browse files Browse the repository at this point in the history
When waiting for an initRes, if the connection is closed, then the
state change fails. Previously, we ignored the state change failure
and called onActive. This caused inactive connections to be added to
the channel's connection list and peer list which would never be closed
since the channel may already have closed.

The fix ensures that any unexpected state while changing the state
will cause the connection to return an error and onActive will not
be called.
  • Loading branch information
prashantv committed May 26, 2016
1 parent fc3f767 commit ed60552
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions connection.go
Expand Up @@ -522,12 +522,12 @@ func (c *Connection) handleInitRes(frame *Frame) bool {
return true
}

c.withStateLock(func() error {
if err := c.withStateLock(func() error {
if c.state != connectionWaitingToRecvInitRes {
return nil
return errConnectionUnknownState{"handleInitRes expecting waitingToRecvInitRes", c.state}
}
if c.ignoreRemotePeer {
return nil
return errConnectionUnknownState{"handleInitRes asked to ignore remote peer", c.state}
}

c.remotePeerInfo.HostPort = res.initParams[InitParamHostPort]
Expand All @@ -539,13 +539,18 @@ func (c *Connection) handleInitRes(frame *Frame) bool {

c.state = connectionActive
return nil
})
}); err != nil {
// The connection was no longer in a state to handle the init res.
// Fail the connection.
c.connectionError("handleInitRes", err)
return true
}
c.callOnActive()

// We forward the peer frame, as the other side is blocked waiting on this frame.
// Rather than add another mechanism, we use the mex to block the sender till we get initRes.
if err := c.outbound.forwardPeerFrame(frame); err != nil {
c.connectionError("forard init res", errCannotHandleInitRes)
c.connectionError("forward init res", errCannotHandleInitRes)
return true
}

Expand Down

0 comments on commit ed60552

Please sign in to comment.