Description
As described in #33, our context implementation in honeybadger-go is a bit naive; because it's global, it is prone to collisions when multiple goroutines update it (which is especially common in server implementations). Consider this scenario from @odarriba:
- request A starts (one goroutine) -> set context A
- request B starts (another goroutine) -> set context B
- request A fails -> sends to HB with context B
The way we solve this issue in Ruby is using a thread local variable which solves the concurrent access problem, and then we reset the context after each request which solves the local request context issue. We do something similar in Elixir--the context is stored in the process dictionary.
I've been reading up on how Go handles passing request context across goroutines, specifically:
https://blog.golang.org/context
http://www.gorillatoolkit.org/pkg/context
From what understand, Go does not provide anything similar to thread local variables or a process dictionary, preferring to pass a context value as described in the blog post.
There may be a way we can integrate with this, but I'm still wrapping my head around it, so I'm not sure what that might be yet. I'm open to suggestions!
In the meantime, we have to live with the caveat that honeybadger.SetContext
will not work reliably across goroutines.