-
Notifications
You must be signed in to change notification settings - Fork 8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix broken context.Context implementation #2029
base: master
Are you sure you want to change the base?
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2029 +/- ##
=======================================
Coverage 98.69% 98.69%
=======================================
Files 40 40
Lines 2225 2225
=======================================
Hits 2196 2196
Misses 16 16
Partials 13 13
Continue to review full report at Codecov.
|
Wasn't this done before and was broken due to Gin caching the |
@segevfiner the current master contains just stubs for the context functions. Lines 1033 to 1073 in 6ece26c
The Value function is just a mapping to some gin internal store, but not to the request context.
|
Yeah I know. I remember looking into this myself and seeing that there was a reverted PR for it because it caused some bug due to |
I looked at the #1736 Lines 89 to 91 in 6ece26c
|
1 similar comment
@bbiao it should not happen if btw: not calling |
Running into this still, and its because the standard library creates a go routine when context.WithTimeout or context.WithDeadline is used. I can work around by spamming c.Copy() all over the place whenever I pass a *gin.Context to a function that may call context.WithTimeout but its a pretty lousy solution when all of my code will likely call a library that uses context.WithTimeout. Here's a breaking test.
If you use c.Copy() on the context.WithTimeout line it won't panic. I can't imagine using c.Copy() all over the place is a good idea, we might as well remove Context pooling. I'm trying to work out middle ground patch. Chi has had this issue as well, |
The current implementation of
gin.Context
does satisfy thecontext.Context
interface, but it returns onlydefault
/nil
values.This MR changes this to use the values from the underlying
http.Request
instead.This allows for example to use
opencensus
middleware for cross service tracing which uses the context to transfer tracing-IDs.