From ba7c20176aa6f7ced1d4c39727609a310d9f0c05 Mon Sep 17 00:00:00 2001 From: Masahiro Nakagawa Date: Fri, 10 May 2019 10:07:44 +0900 Subject: [PATCH] storage_local: Don't stop fluentd start when existing file is empty. ref #2373 Signed-off-by: Masahiro Nakagawa --- lib/fluent/plugin/storage_local.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/fluent/plugin/storage_local.rb b/lib/fluent/plugin/storage_local.rb index 7ccad620db..d6107efbb1 100644 --- a/lib/fluent/plugin/storage_local.rb +++ b/lib/fluent/plugin/storage_local.rb @@ -87,7 +87,12 @@ def configure(conf) if File.exist?(@path) raise Fluent::ConfigError, "Plugin storage path '#{@path}' is not readable/writable" unless File.readable?(@path) && File.writable?(@path) begin - data = Yajl::Parser.parse(open(@path, 'r:utf-8'){ |io| io.read }) + data = open(@path, 'r:utf-8') { |io| io.read } + if data.empty? + log.warn "detect empty plugin storage file during startup. Ignored: #{@path}" + return + end + data = Yajl::Parser.parse(data) raise Fluent::ConfigError, "Invalid contents (not object) in plugin storage file: '#{@path}'" unless data.is_a?(Hash) rescue => e log.error "failed to read data from plugin storage file", path: @path, error: e