gapi: Unblock from a waiting send on GAPI close

There was a race condition that would sometimes occur in that if we
stopped reading from the gapiChan (on shutdown) but then a new message
was available before we managed to close the GAPI, then we would wait
forever to finish the close because the channel never sent, and the
WaitGroup wouldn't let us exit.

This fixes this horrible, horrible race.
This commit is contained in:
James Shubin
2017-02-05 19:44:48 -05:00
parent 62c3add888
commit 2aff8709a5
5 changed files with 28 additions and 6 deletions

View File

@@ -107,7 +107,11 @@ func (obj *MyGAPI) Next() chan error {
select {
case <-ticker.C:
log.Printf("libmgmt: Generating new graph...")
ch <- nil // trigger a run
select {
case ch <- nil: // trigger a run
case <-obj.closeChan:
return
}
case <-obj.closeChan:
return
}

View File

@@ -100,7 +100,11 @@ func (obj *MyGAPI) Next() chan error {
select {
case <-ticker.C:
log.Printf("libmgmt: Generating new graph...")
ch <- nil // trigger a run
select {
case ch <- nil: // trigger a run
case <-obj.closeChan:
return
}
case <-obj.closeChan:
return
}

View File

@@ -154,7 +154,11 @@ func (obj *MyGAPI) Next() chan error {
select {
case <-ticker.C:
log.Printf("libmgmt: Generating new graph...")
ch <- nil // trigger a run
select {
case ch <- nil: // trigger a run
case <-obj.closeChan:
return
}
case <-obj.closeChan:
return
}