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

thread_pool: create a new thread group per process #577

Merged
merged 1 commit into from
Apr 22, 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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ Airbrake Ruby Changelog

### master

* Fixed `ThreadError: can't move to the enclosed thread group` when using
`notify` inside a `fork`
([#577](https://github.com/airbrake/airbrake-ruby/pull/577))

### [v4.14.0][v4.14.0] (April 10, 2020)

* Fixed a bug where some default filters are not appended
Expand Down
1 change: 1 addition & 0 deletions lib/airbrake-ruby/thread_pool.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ def has_workers?

if @pid != Process.pid && @workers.list.empty?
@pid = Process.pid
@workers = ThreadGroup.new
spawn_workers
end

Expand Down
30 changes: 25 additions & 5 deletions spec/thread_pool_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,31 @@
expect(subject).not_to have_workers
end

it "respawns workers on fork()", skip: %w[jruby].include?(RUBY_ENGINE) do
pid = fork { expect(subject).to have_workers }
Process.wait(pid)
subject.close
expect(subject).not_to have_workers
describe "forking behavior" do
before do
skip('fork() is unsupported on JRuby') if %w[jruby].include?(RUBY_ENGINE)
unless Process.respond_to?(:last_status)
skip('Process.last_status is unsupported on this Ruby')
end
end

it "respawns workers on fork()" do
pid = fork { expect(subject).to have_workers }
Process.wait(pid)
subject.close

expect(Process.last_status).to be_success
expect(subject).not_to have_workers
end

it "ensures that a new thread group is created per process" do
subject << 1
pid = fork { subject.has_workers? }
Process.wait(pid)
subject.close

expect(Process.last_status).to be_success
end
end
end

Expand Down