jordansissel / ruby-grok

Pure-ruby implementation of grok.
Apache License 2.0
54 stars 25 forks source link

Exception when pattern file is not readable #33

Open TheVastyDeep opened 2 years ago

TheVastyDeep commented 2 years ago

Logstash 8.0.0.rc2 with bundled JVM. The add_patterns_from_file function in grok_pure.rb calls file.close in the ensure branch, even if File.new returns nil. This leads to

:exception=>#<NoMethodError: undefined method close' for nil:NilClass>, :backtrace=>["/usr/share/logstash/vendor/bundle/jruby/2.5.0/gems/jls-grok-0.11.5/lib/grok-pure.rb:83:inadd_patterns_from_file'"`

To reproduce

cd /usr/share/logstash/vendor/bundle/jruby/2.5.0/gems/logstash-patterns-core-4.3.2/patterns/ecs-v1
touch zzz
chmod 0 zzz

and run logstash with

input { generator { count => 1 lines => [ '' ] } }
filter { grok { match => { "message" => "%{NUMBER:foo}" } } }
output { stdout { codec => rubydebug { metadata => false } } }

Silently ignoring the unreadable file would be an improvement, but not ideal.