Skip to content
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

Possible thread leak when ILogger instances are disposed. #63

Closed
CoderNumber1 opened this issue Jul 17, 2017 · 5 comments · Fixed by #67
Closed

Possible thread leak when ILogger instances are disposed. #63

CoderNumber1 opened this issue Jul 17, 2017 · 5 comments · Fixed by #67
Milestone

Comments

@CoderNumber1
Copy link
Contributor

I have a web application which spins up and disposes of logs as needed while it's running. After adding in the Splunk sink I noticed the application running slower with a much higher CPU utilization. It looked like the application's thread count would just grow constantly. Looking at the EventCollectorSink constructor I notice it calls RepeatAction.OnInterval(TimeSpan pollInterval, Action action, CancellationToken token) but doesn't cancel the returned task on dispose. My guess is then each time an ILogger is spun up a new task/thread is created and it continues to attempt to run after the ILogger is disposed until the web app recycles. I wonder if the returned task could be held in a private field by the sink and cancelled on dispose or maybe even let that sink inherit from the Periodic Batch Sink and let that deal with batching log messages.

https://github.com/serilog/serilog-sinks-splunk/blob/092d929ea92624f98970844e46e91e7878db54b4/src/Serilog.Sinks.Splunk/Sinks/Splunk/EventCollectorSink.cs#L193

https://github.com/serilog/serilog-sinks-splunk/blob/092d929ea92624f98970844e46e91e7878db54b4/src/Serilog.Sinks.Splunk/Sinks/Splunk/RepeatAction.cs#L26

@merbla
Copy link
Contributor

merbla commented Jul 18, 2017

Hey @CoderNumber1,
Yes the repeat action was around a bit before the periodic sink. We have chatted about moving the tried and tested period batching sink.

I think is it a good enhancement.

@merbla merbla added this to the 2.4 milestone Jul 19, 2017
@CoderNumber1
Copy link
Contributor Author

@merbla Would you mind if I forked the repo and took a shot an resolving the issue myself? I would enjoy the opportunity to submit a pull request.

@merbla
Copy link
Contributor

merbla commented Jul 21, 2017

@CoderNumber1 absolutely go for it!! 👍

@CoderNumber1
Copy link
Contributor Author

@merbla Sorry for the radio silence, I've had to put this down in favor of some other projects recently so I haven't been able to devote much time to it. I've been doing some testing today though that looks promising. I'm running both the original and periodic batching versions side by side in separate executables trying to re-create a thread leak in each. The former is up over 3000 threads so far while the updated version has been holding steady at 3 for the last 30 minutes or so. I'll try to submit a pull request for this in the next few days.

@merbla
Copy link
Contributor

merbla commented Aug 8, 2017

👍 great work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants