-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
[config/configtls] Enable goleak check #9220
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #9220 +/- ##
==========================================
- Coverage 91.71% 91.69% -0.03%
==========================================
Files 406 406
Lines 18947 18958 +11
==========================================
+ Hits 17378 17383 +5
- Misses 1209 1214 +5
- Partials 360 361 +1 ☔ View full report in Codecov by Sentry. |
Sorry about the go.mod conflict. Once that is fixed, this can be merged. Thank you! |
config/configtls/configtls.go
Outdated
if err != nil { | ||
return nil, err | ||
} | ||
if c.ReloadClientCAFile { | ||
err = reloader.startWatching() | ||
err = c.reloader.startWatching() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Strange logic that we create a reloader even when not starting, maybe split the logic? Separate PR would be preferred for that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To make sure I understand, you're saying it's possible to get here even when the collector is not starting, so we should fix this logic to make sure the reloader only starts watching during start, am I following your thought?
@jpkrohling removed the ready-to-use since I believe this does not work for multiple calls to get settings, because of that I think is better to design a different API. |
This PR was marked stale due to lack of activity. It will be closed in 14 days. |
f00f265
to
f805a97
Compare
@@ -132,7 +132,7 @@ func (r *clientCAsFileReloader) handleWatcherEvents() { | |||
|
|||
func (r *clientCAsFileReloader) shutdown() error { | |||
if r.shutdownCH == nil { | |||
return fmt.Errorf("client CAs file watcher is not running") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should return an error if the shutdown channel is nil.
// This method must be safe to call:
// - without Start() having been called
// - if the component is in a shutdown state already
Maybe I'm misinterpreting what safe to call
means, but I don't think we should return an error unless there's an issue shutting down. I don't think we should error if shutdown is successful. (Which I believe is the second point from docs here).
Even though this itself isn't specifically a collector component, I believe docs still apply as it's a part of collector shutdown.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think your change makes sense. I interpret that comment to mean "calling shutdown on something not started should not error".
04a3d73
to
5cefecb
Compare
This PR was marked stale due to lack of activity. It will be closed in 14 days. |
@jpkrohling and @bogdandrutu: I believe I've addressed the concerns mentioned, another look would be appreciated when you're able! |
This PR was marked stale due to lack of activity. It will be closed in 14 days. |
receiver/otlpreceiver/otlp.go
Outdated
if r.cfg != nil { | ||
if r.cfg.HTTP != nil && r.cfg.HTTP.TLSSetting != nil { | ||
err = r.cfg.HTTP.TLSSetting.Shutdown() | ||
} | ||
|
||
if r.cfg.GRPC != nil && r.cfg.GRPC.TLSSetting != nil { | ||
err = multierr.Append(err, r.cfg.GRPC.TLSSetting.Shutdown()) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at this some more I really don't like that any component that uses configtls
has to add this check. I am worried about components not realizing that the configtls.TLSSetting
embedded in confighttp.ServerConfig
needs a Shutdown
call.
I think it is out of scope of this PR, which is only trying to solve a leak added by existing functionality, but I think we should take another look at how config
modules should handle goroutines and Shutdown
.
9683569
to
d3e9273
Compare
This PR was marked stale due to lack of activity. It will be closed in 14 days. |
Q: why do we implement reloading of client CA file with a background goroutine instead of using the same approach as
This would avoid a goroutine leak and the unpleasant side-effects of having to call Shutdown on a "config" object. |
This PR was marked stale due to lack of activity. It will be closed in 14 days. |
This PR was marked stale due to lack of activity. It will be closed in 14 days. |
@crobert-1 What's the status of this PR? Does it need more reviews? Do you need to fix something? (No rush, just trying to clean up our backlog) |
Just waiting for reviews 👍 |
Can you take a look at Yuri's question above? |
@crobert-1 Mind taking a look at #9220 (comment) ? |
My apologies for the delay, thanks for the ping! I'm taking a look at this. There's no context from the original issue or implementing PR why this design was chosen. However, the issue says it should be done like the I'm working on implementing this to simply read the file on Marking as draft until I get a chance to properly prove the alternative approach will work. |
This PR was marked stale due to lack of activity. It will be closed in 14 days. |
Closed as inactive. Feel free to reopen if this PR is still being worked on. |
@crobert-1 Sorry for all the troubles my PR is causing, I didn't realize that the shutdown concern wasn't addressed before it got merged (#6708 (comment)) |
Description:
This change enables goleak to check the config/configtls package for memory and goroutine leaks. There was originally a goroutine leak which is fixed by calling the newly added method
TLSServerSetting.Shutdown
.The major change of this PR is to make the
*clientCAsFileReloader
object a member of theTLSServerSetting
struct, as well as adding a publicShutdown
method toTLSServerSetting
. This was the cleanest way I could add a way to shut down the reloader, otherwise it will be a leaked goroutine.Also, I had to change
LoadTLSConfig()
to be a pointer type receiver, so that it could modify the given object by reference instead of only having the value copy of theTLSServerSetting
object it was called on.Link to tracking Issue:
#9165
Testing:
Goleak is passing successfully, as well as all existing tests.