fix: G118: Goroutine uses context.Background/TODO (gosec)#6666
fix: G118: Goroutine uses context.Background/TODO (gosec)#6666thaJeztah wants to merge 2 commits into
Conversation
thaJeztah
commented
Apr 7, 2026
60f575d to
dbe48a9
Compare
| defer func() { | ||
| if err != nil { | ||
| l.Discard() | ||
| _ = l.Discard(ctx) |
There was a problem hiding this comment.
defers should not use original context
| func (l *LeaseRef) Discard() error { | ||
| return l.lm.Delete(context.Background(), l.l) | ||
| func (l *LeaseRef) Discard(ctx context.Context) error { | ||
| return l.lm.Delete(context.WithoutCancel(ctx), l.l) |
There was a problem hiding this comment.
This WithoutCancel should not be added in Discard
dbe48a9 to
4bbba58
Compare
|
bcaa960 to
35daa44
Compare
| proxy.Director = func(req *http.Request) { | ||
| director(req) | ||
| req.Host = target.Host | ||
| proxy.Rewrite = func(pr *httputil.ProxyRequest) { |
There was a problem hiding this comment.
Iiuc NewSingleHostReverseProxy can't be used anymore and struct should be used directly.
Otherwise both Rewrite and Director would be set and https://github.com/golang/go/blob/go1.26.4/src/net/http/httputil/reverseproxy.go#L464-L467 is reached.
I don't know why this doesn't fail the test though. @crazy-max Looks like there is potentially a secondary issue with the test.
There was a problem hiding this comment.
Good catch; didn't realise NewSingleHostReverseProxy still set Director https://github.com/golang/go/blob/go1.26.4/src/net/http/httputil/reverseproxy.go#L333-L338
cache/manager.go:238:3: G118: Goroutine uses context.Background/TODO while request-scoped context is available (gosec)
go link.Release(context.TODO())
^
cache/refs.go:1519:2: G118: Goroutine uses context.Background/TODO while request-scoped context is available (gosec)
go func() {
^
session/testutil/testutil.go:22:3: G118: Goroutine uses context.Background/TODO while request-scoped context is available (gosec)
go func() {
^
solver/edge.go:975:4: G118: Goroutine uses context.Background/TODO while request-scoped context is available (gosec)
go results[i].Release(context.TODO())
^
util/leaseutil/manager.go:79:2: G118: Goroutine uses context.Background/TODO while request-scoped context is available (gosec)
go l.Discard()
^
Signed-off-by: Sebastiaan van Stijn <[email protected]>
client/build_test.go:2363:14: SA1019: proxy.Director has been deprecated since Go 1.26 and an alternative has been available since Go 1.20: Use Rewrite instead. (staticcheck) Signed-off-by: Sebastiaan van Stijn <[email protected]>