Skip to content
This repository has been archived by the owner on Dec 3, 2019. It is now read-only.

Commit

Permalink
Make sure we wait for the final drain timeout
Browse files Browse the repository at this point in the history
If the checkDrainTimer fires, we exit immediately even if the
drain has not finished yet. But we should wait for the bigger
timeout as well.
  • Loading branch information
Aravind Srinivasan committed Apr 7, 2017
1 parent 82196a0 commit 162eee4
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions client/cherami/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,18 +425,21 @@ func (conn *connection) waitForDrainAndClose() {

checkDrainTimer := time.NewTimer(defaultCheckDrainTimeout)
defer checkDrainTimer.Stop()
select {
case <-conn.closeCh:
// already closed
return
case <-checkDrainTimer.C:
// check if we got the acks for all sent messages
if conn.isAlreadyDrained() {
conn.logger.Infof("Inputhost connection drained completely")
for {
checkDrainTimer.Reset(defaultCheckDrainTimeout)
select {
case <-conn.closeCh:
// already closed
return
case <-checkDrainTimer.C:
// check if we got the acks for all sent messages
if conn.isAlreadyDrained() {
conn.logger.Infof("Inputhost connection drained completely")
return
}
case <-drainTimer.C:
return
}
case <-drainTimer.C:
return
}
}

Expand Down

0 comments on commit 162eee4

Please sign in to comment.