Skip to content

Commit be18de7

Browse files
committed
Fix: skip sincedb eviction if read mode completion deletes file during flush
If the value of the setting `sincedb_clean_after` is too short (1 ms) it happens that during the content reading loop (in read mode) the loops itself trigger the cleanup of the same value from the SincedbCollection and then it also try to access it again creating an error. This commit resolves the problem guarding against the presence in the sincebd_collection before accessing it. Fixes: logstash-plugins#272 Closes: logstash-plugins#273
1 parent 15d3eba commit be18de7

File tree

5 files changed

+10
-6
lines changed

5 files changed

+10
-6
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 4.2.1
2+
- Fix: skip sincedb eviction if read mode completion deletes file during flush [#273](https://github.com/logstash-plugins/logstash-input-file/pull/273)
3+
14
## 4.2.0
25
- Fix: watched files performance with huge filesets [#268](https://github.com/logstash-plugins/logstash-input-file/pull/268)
36
- Updated logging to include full traces in debug (and trace) levels

lib/filewatch/read_mode/handlers/read_file.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@ def handle_specifically(watched_file)
1919
watched_file.listener.eof
2020
watched_file.file_close
2121
key = watched_file.sincedb_key
22-
sincedb_collection.reading_completed(key)
23-
sincedb_collection.clear_watched_file(key)
22+
if sincedb_collection.get(key)
23+
sincedb_collection.reading_completed(key)
24+
sincedb_collection.clear_watched_file(key)
25+
end
2426
watched_file.listener.deleted
2527
# NOTE: on top of un-watching we should also remove from the watched files collection
2628
# if the file is getting deleted (on completion), that part currently resides in

lib/filewatch/settings.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class Settings
66
attr_reader :max_active, :max_warn_msg, :lastwarn_max_files
77
attr_reader :sincedb_write_interval, :stat_interval, :discover_interval
88
attr_reader :exclude, :start_new_files_at, :file_chunk_count, :file_chunk_size
9-
attr_reader :sincedb_path, :sincedb_write_interval, :sincedb_expiry_duration
9+
attr_reader :sincedb_path, :sincedb_expiry_duration
1010
attr_reader :file_sort_by, :file_sort_direction
1111
attr_reader :exit_after_read
1212
attr_reader :check_archive_validity
@@ -41,7 +41,6 @@ def add_options(opts)
4141
@file_chunk_size = @opts[:file_chunk_size]
4242
@close_older = @opts[:close_older]
4343
@ignore_older = @opts[:ignore_older]
44-
@sincedb_write_interval = @opts[:sincedb_write_interval]
4544
@stat_interval = @opts[:stat_interval]
4645
@discover_interval = @opts[:discover_interval]
4746
@exclude = Array(@opts[:exclude])

lib/filewatch/sincedb_collection.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ def sincedb_write(time = Time.now.to_i)
216216
@write_method.call
217217
@serializer.expired_keys.each do |key|
218218
@sincedb[key].unset_watched_file
219-
delete(key) # delete
219+
delete(key)
220220
logger.trace? && logger.trace("sincedb_write: cleaned", :key => key)
221221
end
222222
@sincedb_last_write = time

logstash-input-file.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Gem::Specification.new do |s|
22

33
s.name = 'logstash-input-file'
4-
s.version = '4.2.0'
4+
s.version = '4.2.1'
55
s.licenses = ['Apache-2.0']
66
s.summary = "Streams events from files"
77
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"

0 commit comments

Comments
 (0)