wait for killfunc completion when shutting down current app #670
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR attempts to fix #669 by reworking how the killFunc is signalled that a shutdown has been requested.
Instead of reading directly from e.binStopCh (that creates a data race with the writer) it closes on a returned shutdown channel that is used from a new mutexed e.stopBin() func. The shutdown channel takes a channel of int, where the int is the "exit code" passed back to the requestor. It isn't actually the exit code of the process, but a code that can be (and currently is) used to os.Exit the entire process if shutdown failed.
The atomic.Bool change is unrelated to the actual issue, but was required to be able to run the unit tests with -race to detect if there were any races between all the channels and goroutine handling going on in this code.
Reading through the issue list there is a good possibility that this PR will fix, or considerably reduce, the problems seen in #640 #492 #334 and do away with the need for #131 .
This PR has been unit tested and development tested on wsl2 linux and an Apple M2 MBP.