You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
I have some code that calls span.End()inside a deferred function because I also want to trap and record panics via recover().
Unfortunately this linter does not recognise that span.End() is called in the deferred function, and reports span.End is not called on all paths, possible memory leak
$ spancheck ./...
/home/brendan/git/go-spancheck/testdata/base/defer.go:10:2: span.End is not called on all paths, possible memory leak
/home/brendan/git/go-spancheck/testdata/base/defer.go:14:1: return can be reached without calling span.End
exit status 3
Expected behavior
The linter recognises this as a safe span completion that cannot be skipped and won't leak spans.
The text was updated successfully, but these errors were encountered:
Hey @bmon , thank you for pointing this point and giving a great+detailed example. I tried to address it here: #13
It'll now check FuncLiterals (1 level deep) for span calls like End() as in your example:
// This tests that we detect when the span is closed within a deferred func.// https://github.com/jjti/go-spancheck/issues/12func_() {
_, span:=otel.Tracer("foo").Start(context.Background(), "bar")
deferfunc() {
span.End()
}()
}
// Despite above, we do not wander more than one level deep into the defer stack.func_() {
_, span:=otel.Tracer("foo").Start(context.Background(), "bar") // want "span.End is not called on all paths, possible memory leak"deferfunc() {
deferfunc() {
span.End()
}()
}()
} // want "return can be reached without calling span.End"
I hope you'll try it out! It will be awhile before this fix is available in Golangci, tho
Describe the bug
I have some code that calls
span.End()
inside a deferred function because I also want to trap and record panics viarecover()
.Unfortunately this linter does not recognise that
span.End()
is called in the deferred function, and reportsspan.End is not called on all paths, possible memory leak
To Reproduce
Expected behavior
The linter recognises this as a safe span completion that cannot be skipped and won't leak spans.
The text was updated successfully, but these errors were encountered: