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

notifier: respawn workers if they're all dead #26

Merged
merged 1 commit into from
Jan 14, 2016
Merged

Conversation

kyrylo
Copy link
Contributor

@kyrylo kyrylo commented Jan 13, 2016

Potentially fixes airbrake/airbrake#463
(falling back to sync delivery because there are no running async
workers)

I noticed I can reliably reproduce this message when I invoke the Rails
console and manually send a notice via Airbrake.notify. It happens
because by default Rails launches Spring, which preloads the app
by using the fork() system call. And when that happens, as we know,
our worker threads die.

The fix is simply to respawn workers. It works reliably with the Rails
console and I assume it will fix the above mentioned issue.

@kyrylo kyrylo force-pushed the respawn-workers branch 2 times, most recently from e42b3f2 to c85cbbf Compare January 13, 2016 13:18

config.workers.times { @workers.add(spawn_worker) }
@workers.enclose
spawn_workers

Choose a reason for hiding this comment

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

Remove this? It is kinda nice that we don't spawn any workers if async notifier is not used.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed.

@vmihailenco
Copy link

Can you instead check that thread was forked and respawn workers?

@kyrylo kyrylo force-pushed the respawn-workers branch 2 times, most recently from 116f9cb to fefd305 Compare January 13, 2016 19:29
@kyrylo
Copy link
Contributor Author

kyrylo commented Jan 13, 2016

PTAL

@@ -42,6 +44,12 @@ def initialize(user_config)
##
# @macro see_public_api_method
def notify(exception, params = {})
if !@workers_spawned || @pid != Process.pid

Choose a reason for hiding this comment

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

Do you really need !@workers_spawned check? I think @pid != Process.pid should be enough...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, with the current refactoring we don't need it.

@kyrylo kyrylo force-pushed the respawn-workers branch 2 times, most recently from 992a0b3 to 6f80830 Compare January 14, 2016 11:27
@kyrylo
Copy link
Contributor Author

kyrylo commented Jan 14, 2016

PTAL

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

Choose a reason for hiding this comment

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

I think you should not spawn any workers if notifier is closed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should this be enough, then?

diff --git a/lib/airbrake-ruby/async_sender.rb b/lib/airbrake-ruby/async_sender.rb
index 35b1aa4..dc3a71d 100644
--- a/lib/airbrake-ruby/async_sender.rb
+++ b/lib/airbrake-ruby/async_sender.rb
@@ -74,7 +74,7 @@ module Airbrake
     def has_workers?
       if @pid != Process.pid && @workers.list.empty?
         @pid = Process.pid
-        spawn_workers
+        spawn_workers unless closed?
       end

       !@closed && @workers.list.any?

Choose a reason for hiding this comment

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

Why not

return false if @closed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also works. My thinking was that in this case @pid won't be updated, but since the sender is closed it doesn't matter. Updated according to your suggestion.

Potentially fixes airbrake/airbrake#463
(falling back to sync delivery because there are no running async
workers)

I noticed I can reliably reproduce this message when I invoke the Rails
console and manually send a notice via `Airbrake.notify`. It happens
because by default Rails launches [Spring][1], which preloads the app
by using the `fork()` system call. And when that happens, as we know,
our worker threads die.

The fix is simply to respawn workers. It works reliably with the Rails
console and I assume it will fix the above mentioned issue.

[1]: https://github.com/rails/spring/
@kyrylo
Copy link
Contributor Author

kyrylo commented Jan 14, 2016

PTAL

@vmihailenco
Copy link

LGTM

kyrylo added a commit that referenced this pull request Jan 14, 2016
notifier: respawn workers if they're all dead
@kyrylo kyrylo merged commit e1d70b3 into master Jan 14, 2016
@kyrylo kyrylo deleted the respawn-workers branch January 14, 2016 12:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

falling back to sync delivery because there are no running async workers
2 participants