{"action":"created","issue":{"url":"https://api.github.com/repos/deivid-rodriguez/byebug/issues/115","labels_url":"https://api.github.com/repos/deivid-rodriguez/byebug/issues/115/labels{/name}","comments_url":"https://api.github.com/repos/deivid-rodriguez/byebug/issues/115/comments","events_url":"https://api.github.com/repos/deivid-rodriguez/byebug/issues/115/events","html_url":"https://github.com/deivid-rodriguez/byebug/issues/115","id":56328898,"number":115,"title":"Unexpected thread behavior inside debugger context","user":{"login":"mhoran","id":5330,"avatar_url":"https://avatars.githubusercontent.com/u/5330?v=3","gravatar_id":"","url":"https://api.github.com/users/mhoran","html_url":"https://github.com/mhoran","followers_url":"https://api.github.com/users/mhoran/followers","following_url":"https://api.github.com/users/mhoran/following{/other_user}","gists_url":"https://api.github.com/users/mhoran/gists{/gist_id}","starred_url":"https://api.github.com/users/mhoran/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mhoran/subscriptions","organizations_url":"https://api.github.com/users/mhoran/orgs","repos_url":"https://api.github.com/users/mhoran/repos","events_url":"https://api.github.com/users/mhoran/events{/privacy}","received_events_url":"https://api.github.com/users/mhoran/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-02-03T03:26:13Z","updated_at":"2015-02-18T17:55:39Z","closed_at":null,"body":"In capybara-webkit, we use threads to work around a JRuby bug in `IO.select`. This causes an issue when commands are sent to the `webkit_server` process from within a debugger context. The issue persists on master, so I'm opening this issue to document my findings.\r\n\r\nA simple test case does not behave as expected:\r\n\r\n```ruby\r\nrequire 'byebug'\r\n\r\ndef read\r\n  Thread.abort_on_exception = true\r\n  Thread.new {}.join\r\nend\r\n\r\ndef main\r\n  byebug\r\nend\r\n\r\nmain\r\n```\r\n\r\nCalling `read` from `main` results in ``test.rb:5:in `join': No live threads left. Deadlock? (fatal)``. While seemingly related to #54, this issue persists on master.\r\n\r\nHere's a test case that's more similar to what we do in capybara-webkit:\r\n\r\n```ruby\r\nrequire 'socket'\r\nfork do\r\n  server = TCPServer.new 3001\r\n  client = server.accept\r\n  client.gets\r\nend\r\n\r\nrequire 'byebug'\r\n\r\ndef connect\r\n  Timeout.timeout(5) do\r\n    while @socket.nil?\r\n      attempt_connect\r\n    end\r\n  end\r\nend\r\n\r\ndef attempt_connect\r\n  @socket = TCPSocket.open(\"127.0.0.1\", 3001)\r\nrescue Errno::ECONNREFUSED\r\nend\r\n\r\ndef read\r\n  response = ''\r\n  begin\r\n    while response.length < 1 do\r\n      response += @socket.read_nonblock(1)\r\n    end\r\n  rescue IO::WaitReadable\r\n    Thread.abort_on_exception = true\r\n    Thread.new { IO.select([@socket]) }.join\r\n    retry\r\n  end\r\nend\r\n\r\ndef main\r\n  connect\r\n  byebug\r\nend\r\n\r\nmain\r\n```\r\n\r\nThis results, again, in ``test.rb:31:in `join': No live threads left. Deadlock? (fatal)``.\r\n\r\nOddly, when capybara-webkit is utilized by a project and the `#read` method is invoked, one does not see this error but instead, the debugger hangs. This has been documented in https://github.com/deivid-rodriguez/pry-byebug/issues/51. Unfortunately, I've been unable to isolate this behavior, but it is reproducible with the latest version of capybara-webkit."},"comment":{"url":"https://api.github.com/repos/deivid-rodriguez/byebug/issues/comments/74912617","html_url":"https://github.com/deivid-rodriguez/byebug/issues/115#issuecomment-74912617","issue_url":"https://api.github.com/repos/deivid-rodriguez/byebug/issues/115","id":74912617,"user":{"login":"deivid-rodriguez","id":2887858,"avatar_url":"https://avatars.githubusercontent.com/u/2887858?v=3","gravatar_id":"","url":"https://api.github.com/users/deivid-rodriguez","html_url":"https://github.com/deivid-rodriguez","followers_url":"https://api.github.com/users/deivid-rodriguez/followers","following_url":"https://api.github.com/users/deivid-rodriguez/following{/other_user}","gists_url":"https://api.github.com/users/deivid-rodriguez/gists{/gist_id}","starred_url":"https://api.github.com/users/deivid-rodriguez/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/deivid-rodriguez/subscriptions","organizations_url":"https://api.github.com/users/deivid-rodriguez/orgs","repos_url":"https://api.github.com/users/deivid-rodriguez/repos","events_url":"https://api.github.com/users/deivid-rodriguez/events{/privacy}","received_events_url":"https://api.github.com/users/deivid-rodriguez/received_events","type":"User","site_admin":false},"created_at":"2015-02-18T17:55:39Z","updated_at":"2015-02-18T17:55:39Z","body":"So I've fixed the issue you reported but I'm pretty sure the other issue will still happen. So what would be the steps to reproduce it?\r\n\r\nThe issue you linked to seems to the same as the one I've fixed (because they both happen when evaluating stuff from byebug/pry-byebug's prompt) although it is true that the errors are different."}}