Skip to content
Open
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
2 changes: 1 addition & 1 deletion lib/unleash/backup_file_writer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def self.save!(toggle_data)
Unleash.logger.debug "Will save toggles to disk now"

backup_file = Unleash.configuration.backup_file
backup_file_tmp = "#{backup_file}.tmp"
backup_file_tmp = "#{backup_file}.tmp-#{Process.pid}"

File.open(backup_file_tmp, "w") do |file|
file.write(toggle_data)
Expand Down
24 changes: 24 additions & 0 deletions spec/unleash/toggle_fetcher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,30 @@
backup_file = Unleash.configuration.backup_file
expect(File.exist?(backup_file)).to eq(true)
end

# NOTE: this is a frequent issue with Puma (in clustered mode). See Unleash/unleash-ruby-sdk#108
it 'does not log errors due to concurrent forked processes' do
skip 'Fork not supported on current platform' unless Process.respond_to?(:fork)

log_file = ->(pid) { File.join(Dir.tmpdir, "#{pid}.log") }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NOTE: getting the stdout/stderr from child processes is tricky so the temporary log file here is just a dirty way to capture the child process logger output.

pids = Array.new(10) do
fork do
Unleash.logger = Logger.new(log_file.call(Process.pid))
expect(Unleash.logger).not_to receive(:error)
described_class.new engine
end
end

pids.each do |pid|
Process.wait(pid)
process_status = $? # rubocop:disable Style/SpecialGlobalVars
error_log_file = log_file.call(pid)
expect(File.exist?(error_log_file))

error_msg = "Process #{pid} failed with errors:\n#{File.read(error_log_file).lines[1..].join}"
expect(process_status).to be_success, error_msg
end
end
end
end

Expand Down
Loading