multi: CancelPending error for no pending conns.

This modifies the CancelPending method of the connection manager to
return an error when there are no pending connections for the provided
address or the connection manager is already shutting down.

This change, in turn, ensures that attempts to remove a pending
connection that doesn't exist via RPC returns an error as expected.
This commit is contained in:
Wisdom Arerosuoghene 2020-05-06 19:30:43 +01:00 committed by GitHub
parent 50fe5b7ad3
commit bb830e670f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 10 deletions

View File

@ -183,7 +183,7 @@ type handleFailed struct {
// handleCancelPending is used to remove failing connections from retries.
type handleCancelPending struct {
addr net.Addr
done chan struct{}
done chan error
}
// ConnManager provides a manager to handle network connections.
@ -369,14 +369,15 @@ out:
idToRemove, connReq = id, req
break
}
}
if connReq != nil {
delete(pending, idToRemove)
connReq.updateState(ConnCanceled)
log.Debugf("Canceled pending connection to %v", msg.addr)
msg.done <- nil
} else {
msg.done <- fmt.Errorf("no pending connection to %v", msg.addr)
}
close(msg.done)
}
case <-cm.quit:
@ -534,11 +535,13 @@ func (cm *ConnManager) Remove(id uint64) {
// CancelPending removes the connection corresponding to the given address
// from the list of pending failed connections.
func (cm *ConnManager) CancelPending(addr net.Addr) {
// Returns an error if the connection manager is stopped or there is no pending
// connection for the given address.
func (cm *ConnManager) CancelPending(addr net.Addr) error {
if atomic.LoadInt32(&cm.stop) != 0 {
return
return fmt.Errorf("connection manager stopped")
}
done := make(chan struct{})
done := make(chan error, 1)
select {
case cm.requests <- handleCancelPending{addr, done}:
@ -548,9 +551,10 @@ func (cm *ConnManager) CancelPending(addr net.Addr) {
// Wait for the connection to be removed from the conn manager's
// internal state.
select {
case <-done:
case err := <-done:
return err
case <-cm.quit:
return
return fmt.Errorf("connection manager stopped")
}
}

View File

@ -1955,8 +1955,7 @@ func (s *server) handleQuery(state *peerState, querymsg interface{}) {
msg.reply <- err
return
}
s.connManager.CancelPending(netAddr)
msg.reply <- nil
msg.reply <- s.connManager.CancelPending(netAddr)
case getOutboundGroup:
count, ok := state.outboundGroups[msg.key]
if ok {