Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: wg.Done() must be outside RecoverRepanic (#247)
This is a small change to the example for correctness. The concurrency issue is subtle, but here is an attempt to explain it. Keep in mind that: - deferred calls happen in reverse order. - to recover from panics in f, RecoverRepanic must defer a func call before calling f. If defer wg.Done() is part of f, the argument passed to RecoverRepanic, it means it will be called before any deferred functions setup by RecoverRepanic itself. If all goroutines started in the loop would call wg.Done() before an event is reported to Sentry, the main goroutine blocked on wg.Wait() would unblock and reach the end of func main, terminating the execution of the program, consequently dropping any other pending work in other goroutines, reporting to Sentry included. Additionally, reinforce that RecoverRepanic may report only one panic. Even though already documented in the body of the function, promoting a note right at the documentation of RecoverRepanic will hopefully raise awareness for anyone trying to use the example.
- Loading branch information