Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug when RUBYOPT is invalid #2813

Merged
merged 3 commits into from
Feb 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -664,6 +665,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