Skip to content

Commit

Permalink
Merge pull request #577 from airbrake/576-enclosed-thread-group-fix
Browse files Browse the repository at this point in the history
thread_pool: create a new thread group per process
  • Loading branch information
kyrylo authored Apr 22, 2020
2 parents 1be7b15 + f9054be commit 965c49d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
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

0 comments on commit 965c49d

Please sign in to comment.