-
Notifications
You must be signed in to change notification settings - Fork 3
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
http.Request.Context() false positive #3
Comments
can't reproduce in my PC. add some info plz. 😊 |
package main
import (
"context"
"github.com/openzipkin/zipkin-go"
)
func main() {
foo(context.Background())
}
func foo(ctx context.Context) {
_ = WithTrace(nil)
}
func WithTrace(tracer *zipkin.Tracer) func(context.Context) context.Context {
return func(ctx context.Context) context.Context {
parent := zipkin.SpanOrNoopFromContext(
ctx,
)
span := tracer.StartSpan("span",
zipkin.Parent(parent.Context()),
)
_ = span
return ctx
}
} main.go:14:15: Function `WithTrace->WithTrace$1` should pass the context parameter (contextcheck)
_ = WithTrace(nil) |
fixed, wait new ci release |
I also get false positive with code that takes context from incoming http request and sets it into new requests I got contextcheck from golangci-lint has version 1.49.0 faq I suppose but can I make it use latest or at least test/confirm if it's fixed? |
the nolint I think shouldn't be needed (but may totally be wrong about) are fortio/fortio@73c9268#diff-dd948e8af77fe6765332b96b0e84a4f12554c233866ce4ef85731b7016dc572b |
no.. is not use like normal nolint from ci.. contextcheck/testdata/src/a/a.go Lines 112 to 115 in 5cf2741
i guess ci version 1.49.1 may have this fix |
Sorry I wasn't clear. I meant not to ask how to disable a check, that's working fine with golangci-lint I meant to ask why is the code I linked being flagged, and I just check with the latest code and it still is
(btw I don't know how to read that TeeSerialHandler->do->setupRequest->MakeSimpleRequest->makeMirrorRequest->CopyHeaders) |
it's seem have some trouble..i will fix later |
@ldemailly bug fixed..and add new tag for set a func is http handler for analyse i add tag to 3 func: and attach new linter output:
|
I tried the latest version, can you explain why: func MakeSimpleRequest(url string, r *http.Request, copyAllHeaders bool) *http.Request {
req, err := http.NewRequestWithContext(r.Context(), http.MethodGet, url, nil)
... makes it say |
new version can mark it automatically.
// @contextcheck(req_has_ctx)
func MakeSimpleRequest(... |
I am trying to ask and suggest if not that context check understands, without needing any special annotation that it is common to transfer/carry a context from http.Request |
This also occurs with gRPC stream interceptors:
|
This case is too rare. Perhaps it would be better to wrap it in a function call. func StreamServerInterceptor(opts QueryInfoOptions) grpc.StreamServerInterceptor {
return func(srv interface{}, stream grpc.ServerStream, _ *grpc.StreamServerInfo, handler grpc.StreamHandler) error {
wrapcall(stream.Context(), srv, stream, handler)
}
} |
@kkHAIKE awesome, that worked. Thanks. |
How about some third-party http library, for example gin r.GET("/ping", func(c *gin.Context) {
doSomething(c.Request.Context())
c.JSON(http.StatusOK, gin.H{
"message": "pong",
})
}) |
I have code that looks like:
I get this error:
The text was updated successfully, but these errors were encountered: