Skip to content

Commit df09843

Browse files
committed
Bugfix: implemented close method for release of resources
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 Close #28
1 parent a4ac442 commit df09843

File tree

4 files changed

+20
-1
lines changed

4 files changed

+20
-1
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 5.0.2
2+
- Fixed potential resource leak by ensuring scheduler is shutdown when a pipeline encounter an error during the running [#28](https://github.com/logstash-plugins/logstash-integration-jdbc/pull/28)
3+
14
## 5.0.1
25
- Fixed tracking_column regression with Postgresql Numeric types [#17](https://github.com/logstash-plugins/logstash-integration-jdbc/pull/17)
36
- Fixed driver loading when file not accessible [#15](https://github.com/logstash-plugins/logstash-integration-jdbc/pull/15)

lib/logstash/inputs/jdbc.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,10 @@ def run(queue)
283283
end
284284
end # def run
285285

286+
def close
287+
@scheduler.shutdown if @scheduler
288+
end
289+
286290
def stop
287291
close_jdbc_connection
288292
@scheduler.shutdown(:wait) if @scheduler

logstash-integration-jdbc.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Gem::Specification.new do |s|
22
s.name = 'logstash-integration-jdbc'
3-
s.version = '5.0.1'
3+
s.version = '5.0.2'
44
s.licenses = ['Apache License (2.0)']
55
s.summary = "Integration with JDBC - input and filter plugins"
66
s.description = "This gem is a Logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This gem is not a stand-alone program"

spec/inputs/jdbc_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,18 @@
191191
Timecop.return
192192
end
193193

194+
it "cleans up scheduler resources on close" do
195+
runner = Thread.new do
196+
plugin.run(queue)
197+
end
198+
sleep 1
199+
plugin.do_close
200+
201+
scheduler = plugin.instance_variable_get(:@scheduler)
202+
expect(scheduler).to_not be_nil
203+
expect(scheduler.down?).to be_truthy
204+
end
205+
194206
end
195207

196208
context "when scheduling and previous runs are to be preserved" do

0 commit comments

Comments
 (0)