-
Notifications
You must be signed in to change notification settings - Fork 54
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
Implemented close method to release scheduler resources on error #28
Implemented close method to release scheduler resources on error #28
Conversation
close method is used to clean in case of error in run phase of the plugin, implemented to avoid leak of threads generated by Rufus scheduler. Fixes logstash-plugins#21 Close logstash-plugins#28
8b96c96
to
4f65c81
Compare
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.
👍 this makes sense - we actually have been seeing stuck threads from jdbc plugin.
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.
The code-change looks sensible.
I'd like to see a small change to the spec to eliminate the monkey-patch introduced here.
We also need a version bump (patch-level is okay) and an entry in the changelog, maybe something like:
Fixed potential resource leak by ensuring scheduler is shut down when a pipeline containing this plugin is shut down or restarted
spec/inputs/jdbc_spec.rb
Outdated
it "should cleanup resources on close" do | ||
class LogStash::Inputs::Jdbc | ||
def scheduler_down? | ||
@scheduler.down? | ||
end | ||
end | ||
|
||
runner = Thread.new do | ||
plugin.run(queue) | ||
end | ||
sleep 1 | ||
|
||
plugin.do_close | ||
|
||
expect(plugin.scheduler_down?).to be_truthy | ||
end | ||
|
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'd rather avoid monkey-patching the plugin in our specs, since this modification to the class will persist beyond the scope of this individual spec.
An alternate solution would be:
it "should cleanup resources on close" do | |
class LogStash::Inputs::Jdbc | |
def scheduler_down? | |
@scheduler.down? | |
end | |
end | |
runner = Thread.new do | |
plugin.run(queue) | |
end | |
sleep 1 | |
plugin.do_close | |
expect(plugin.scheduler_down?).to be_truthy | |
end | |
it 'cleans up scheduler resources on close' do | |
runner = Thread.new do | |
plugin.run(queue) | |
end | |
sleep 1 | |
plugin.do_close | |
scheduler = plugin.instance_variable_get(:@scheduler) | |
expect(scheduler).to_not be_nil | |
expect(scheduler.down?).to be_truthy | |
end | |
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.
Thank's @yaauie good point, I missed it!
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.
@yaauie I've added the suggested changes, if you want you can go forward with the review
close method is used to clean in case of error in run phase of the plugin, implemented to avoid leak of threads generated by Rufus scheduler. Fixes logstash-plugins#21 Close logstash-plugins#28
4f65c81
to
df09843
Compare
Jenkins test this please |
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.
LGTM 👍
Andrea Selva merged this to master! |
Close method is used to clean in case of error in run phase of the plugin, implemented to avoid leak of threads generated by Rufus scheduler.
Fixes #21