{"action":"created","issue":{"url":"https://api.github.com/repos/airbrake/airbrake-ruby/issues/312","repository_url":"https://api.github.com/repos/airbrake/airbrake-ruby","labels_url":"https://api.github.com/repos/airbrake/airbrake-ruby/issues/312/labels{/name}","comments_url":"https://api.github.com/repos/airbrake/airbrake-ruby/issues/312/comments","events_url":"https://api.github.com/repos/airbrake/airbrake-ruby/issues/312/events","html_url":"https://github.com/airbrake/airbrake-ruby/issues/312","id":307197068,"number":312,"title":"TypeError: can't move to the enclosed thread group","user":{"login":"meetme2meat","id":63040,"avatar_url":"https://avatars1.githubusercontent.com/u/63040?v=4","gravatar_id":"","url":"https://api.github.com/users/meetme2meat","html_url":"https://github.com/meetme2meat","followers_url":"https://api.github.com/users/meetme2meat/followers","following_url":"https://api.github.com/users/meetme2meat/following{/other_user}","gists_url":"https://api.github.com/users/meetme2meat/gists{/gist_id}","starred_url":"https://api.github.com/users/meetme2meat/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/meetme2meat/subscriptions","organizations_url":"https://api.github.com/users/meetme2meat/orgs","repos_url":"https://api.github.com/users/meetme2meat/repos","events_url":"https://api.github.com/users/meetme2meat/events{/privacy}","received_events_url":"https://api.github.com/users/meetme2meat/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2018-03-21T10:55:01Z","updated_at":"2018-04-19T00:05:56Z","closed_at":null,"author_association":"NONE","body":"Calling `Airbrake.notify` on Thread applications can result in a Thread been assign to an already enclosed ThreadGroup\r\n\r\nThe issue is very hard to replicate(but still we have 5-6 report of the above error in past 2 months) since it depends on the OS ability to context switch at wrong place resulting in a deadlock/race conditions on a shared object. \r\n\r\nThe relevant code that been referred over here is `spawn_workers` inside the [async_sender.rb](https://github.com/airbrake/airbrake-ruby/blob/master/lib/airbrake-ruby/async_sender.rb#L95-L99)\r\n\r\nFollowing is the backtrace reported by Airbrake.\r\n\r\n```\r\nTypeError: can't move to the enclosed thread group\r\n\r\norg/jruby/RubyThreadGroup.java:87 in add\r\n/gems/airbrake-ruby-1.1.0/lib/airbrake-ruby/async_sender.rb:93 in block in spawn_workers\r\norg/jruby/RubyFixnum.java:296 in times\r\n/gems/airbrake-ruby-1.1.0/lib/airbrake-ruby/async_sender.rb:93 in spawn_workers\r\n/gems/airbrake-ruby-1.1.0/lib/airbrake-ruby/async_sender.rb:83 in has_workers?\r\n/gems/airbrake-ruby-1.1.0/lib/airbrake-ruby/notifier.rb:130 in default_sender\r\n/gems/airbrake-ruby-1.1.0/lib/airbrake-ruby/notifier.rb:45 in send_notice\r\n/gems/airbrake-ruby-1.1.0/lib/airbrake-ruby/notifier.rb:45 in notify\r\n/gems/airbrake-ruby-1.1.0/lib/airbrake-ruby.rb:282 in call_notifier\r\n/gems/airbrake-ruby-1.1.0/lib/airbrake-ruby.rb:136 in notify\r\n/srv/apps/policy_router/releases/20180212084654/lib/policy_router/response_handler.rb:52 in start\r\n/srv/apps/policy_router/releases/20180212084654/lib/policy_router/request_handler.rb:7 in start\r\norg/jruby/RubyKernel.java:1823 in public_send\r\n/gems/celluloid-0.17.1.1/lib/celluloid/calls.rb:28 in dispatch\r\n/gems/celluloid-0.17.1.1/lib/celluloid/call/sync.rb:16 in dispatch\r\n/gems/celluloid-0.17.1.1/lib/celluloid/cell.rb:50 in block in dispatch\r\n/gems/celluloid-0.17.1.1/lib/celluloid/cell.rb:76 in block in task\r\n/gems/celluloid-0.17.1.1/lib/celluloid/actor.rb:338 in block in task\r\n/gems/celluloid-0.17.1.1/lib/celluloid/task.rb:44 in block in initialize\r\n/gems/celluloid-0.17.1.1/lib/celluloid/task/fibered.rb:14 in block in create\r\n```\r\n\r\nIf need be I can share a sample script which I wrote to confirm the above issue.\r\n\r\nEnvironment: \r\n* Airbrake version: 1.1.0\r\n* Ruby version: JRuby-9.0.5.0 (openJDK 1.8)\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/airbrake/airbrake-ruby/issues/comments/382567102","html_url":"https://github.com/airbrake/airbrake-ruby/issues/312#issuecomment-382567102","issue_url":"https://api.github.com/repos/airbrake/airbrake-ruby/issues/312","id":382567102,"user":{"login":"kyrylo","id":1079123,"avatar_url":"https://avatars2.githubusercontent.com/u/1079123?v=4","gravatar_id":"","url":"https://api.github.com/users/kyrylo","html_url":"https://github.com/kyrylo","followers_url":"https://api.github.com/users/kyrylo/followers","following_url":"https://api.github.com/users/kyrylo/following{/other_user}","gists_url":"https://api.github.com/users/kyrylo/gists{/gist_id}","starred_url":"https://api.github.com/users/kyrylo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kyrylo/subscriptions","organizations_url":"https://api.github.com/users/kyrylo/orgs","repos_url":"https://api.github.com/users/kyrylo/repos","events_url":"https://api.github.com/users/kyrylo/events{/privacy}","received_events_url":"https://api.github.com/users/kyrylo/received_events","type":"User","site_admin":false},"created_at":"2018-04-19T00:05:56Z","updated_at":"2018-04-19T00:05:56Z","author_association":"OWNER","body":"Apologies for the delay. I have been very busy with some other urgent work.\r\nI managed to reproduce this error with the following simplified script:\r\n\r\n```rb\r\nrequire 'airbrake-ruby'\r\n\r\nAirbrake.configure do |c|\r\n  c.project_id = <id>\r\n  c.project_key = <key>\r\nend\r\n\r\nt1 = Thread.new { Airbrake.notify(1) }\r\nt2 = Thread.new { Airbrake.notify(2) }\r\nt1.join\r\nt2.join\r\n```\r\n\r\nI believe all it takes to fix the error is to wrap the body of the `AsyncSender#has_worker?` method into a mutex. I tested it locally and it seems to fix the error.\r\n\r\nI submitted https://github.com/airbrake/airbrake-ruby/pull/316. Could you, please, test it?"}}
{"actor":{"display_login":"kyrylo"}}