Skip to content

Commit

Permalink
Merge pull request #2813 from ganmacs/fix-when-rubyopt-is-invalid
Browse files Browse the repository at this point in the history
Fix bug when RUBYOPT is invalid
  • Loading branch information
ganmacs authored Feb 4, 2020
2 parents 69f66c1 + d2d9a25 commit 0e072e7
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ branches:
only:
- master

before_install:
- gem update --system=3.1.2

sudo: false
dist: trusty # for TLSv1.2 support

Expand Down
11 changes: 11 additions & 0 deletions lib/fluent/supervisor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#

require 'fileutils'
require 'open3'

require 'fluent/config'
require 'fluent/counter'
Expand Down Expand Up @@ -665,6 +666,16 @@ def supervise
if rubyopt
fluentd_spawn_cmd.concat(rubyopt.split(' '))
end

# Adding `-h` so that it can avoid ruby's command blocking
# e.g. `ruby -Eascii-8bit:ascii-8bit` will block. but `ruby -Eascii-8bit:ascii-8bit -h` won't.
cmd = fluentd_spawn_cmd.join(' ')
_, e, s = Open3.capture3("#{cmd} -h")
if s.exitstatus != 0
$log.error('Invalid option is passed to RUBYOPT', command: cmd, error: e)
exit s.exitstatus
end

fluentd_spawn_cmd << $0
fluentd_spawn_cmd += $fluentdargv
fluentd_spawn_cmd << "--under-supervisor"
Expand Down
22 changes: 20 additions & 2 deletions test/command/test_fluentd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def create_plugin_file(name, content)

def create_cmdline(conf_path, *fluentd_options)
cmd_path = File.expand_path(File.dirname(__FILE__) + "../../../bin/fluentd")
["bundle", "exec", "ruby", cmd_path, "-c", conf_path, *fluentd_options]
["bundle", "exec", cmd_path, "-c", conf_path, *fluentd_options]
end

def execute_command(cmdline, chdir=TMP_DIR, env = {})
Expand Down Expand Up @@ -283,7 +283,7 @@ def assert_fluentd_fails_to_start(cmdline, *pattern_list, timeout: 10)

assert_fluentd_fails_to_start(
create_cmdline(conf_path),
"non directory entry exists:#{@root_path} (Fluent::InvalidRootDirectory)",
"non directory entry exists:#{@root_path}",
)
end
end
Expand Down Expand Up @@ -797,6 +797,24 @@ def multi_workers_ready?
)
end

test 'invalid values are set to RUBYOPT' do
conf = <<CONF
<source>
@type dummy
tag dummy
</source>
<match>
@type null
</match>
CONF
conf_path = create_conf_file('rubyopt_invalid_test.conf', conf)
assert_log_matches(
create_cmdline(conf_path),
'Invalid option is passed to RUBYOPT',
env: { 'RUBYOPT' => 'a' },
)
end

test 'success to start workers when file buffer is configured in non-workers way only for specific worker' do
conf = <<CONF
<system>
Expand Down

0 comments on commit 0e072e7

Please sign in to comment.