{"action":"created","issue":{"url":"https://api.github.com/repos/celluloid/timers/issues/58","labels_url":"https://api.github.com/repos/celluloid/timers/issues/58/labels{/name}","comments_url":"https://api.github.com/repos/celluloid/timers/issues/58/comments","events_url":"https://api.github.com/repos/celluloid/timers/issues/58/events","html_url":"https://github.com/celluloid/timers/issues/58","id":129220756,"number":58,"title":"timeout is buggy in JRuby","user":{"login":"TiagoCardoso1983","id":215707,"avatar_url":"https://avatars.githubusercontent.com/u/215707?v=3","gravatar_id":"","url":"https://api.github.com/users/TiagoCardoso1983","html_url":"https://github.com/TiagoCardoso1983","followers_url":"https://api.github.com/users/TiagoCardoso1983/followers","following_url":"https://api.github.com/users/TiagoCardoso1983/following{/other_user}","gists_url":"https://api.github.com/users/TiagoCardoso1983/gists{/gist_id}","starred_url":"https://api.github.com/users/TiagoCardoso1983/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TiagoCardoso1983/subscriptions","organizations_url":"https://api.github.com/users/TiagoCardoso1983/orgs","repos_url":"https://api.github.com/users/TiagoCardoso1983/repos","events_url":"https://api.github.com/users/TiagoCardoso1983/events{/privacy}","received_events_url":"https://api.github.com/users/TiagoCardoso1983/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":40,"created_at":"2016-01-27T17:55:19Z","updated_at":"2016-01-29T14:54:04Z","closed_at":null,"body":"First I thought it was celluloid-io sockets, but then I realized that in Jruby, timeouts will not always be triggered. Here is a simple script:\r\n\r\n```ruby\r\nrequire 'time'\r\nrequire 'celluloid/io'\r\n\r\n\r\nclass Tester\r\n  include Celluloid::IO\r\n  def initialize\r\n    @sock = TCPSocket.new(\"localhost\", 80)\r\n  end\r\n\r\n  def test_timeout\r\n    begin\r\n      timeout(2) do\r\n         # option 1\r\n         # @sock.wait_readable\r\n         # option 2\r\n         # sleep 3\r\n         # option 3 \r\n         loop do\r\n            sleep 1\r\n         end\r\n      end\r\n    rescue Celluloid::Task::TimeoutError\r\n      puts \"successfull timeout fetch: #{Time.now}\"\r\n      retry\r\n    ensure\r\n      puts \"#{$!.class} #{$!.message}\" if $!\r\n    end\r\n  end\r\n\r\nend\r\n\r\n\r\nputs \"starting the actor...\"\r\nt = Tester.new\r\nt.async(:test_timeout)\r\nsleep\r\n\r\n# Option 1\r\n# Both MRI 2.1 and jruby 9.0.5.0\r\n....\r\nsuccessfull timeout fetch: 2016-01-27 18:50:47 +0100\r\nsuccessfull timeout fetch: 2016-01-27 18:50:49 +0100\r\nsuccessfull timeout fetch: 2016-01-27 18:50:51 +0100\r\nsuccessfull timeout fetch: 2016-01-27 18:50:53 +0100\r\nsuccessfull timeout fetch: 2016-01-27 18:50:55 +0100\r\nsuccessfull timeout fetch: 2016-01-27 18:50:57 +0100\r\nsuccessfull timeout fetch: 2016-01-27 18:50:59 +0100\r\nsuccessfull timeout fetch: 2016-01-27 18:51:01 +0100\r\n\r\n\r\n(hangs at some point...)\r\n\r\n\r\n# Option 2\r\n# MRI 2.1 and JRUBY-9.0.5.0\r\nstarting the actor...\r\nsuccessfull timeout fetch: 2016-01-27 18:49:12 +0100\r\nW, [2016-01-27T18:49:15.799990 #328595]  WARN -- : Attempted to resume a dead task: type=:call, meta={:dangerous_suspend=>false, :method_name=>:test_timeout}, status=:dead\r\n```\r\n\r\nOption 3 works in MRI (apparently), but also hangs at some point. \r\n\r\nThis can seriously hinder https://github.com/celluloid/celluloid-io/pull/170. \r\n"},"comment":{"url":"https://api.github.com/repos/celluloid/timers/issues/comments/176794243","html_url":"https://github.com/celluloid/timers/issues/58#issuecomment-176794243","issue_url":"https://api.github.com/repos/celluloid/timers/issues/58","id":176794243,"user":{"login":"TiagoCardoso1983","id":215707,"avatar_url":"https://avatars.githubusercontent.com/u/215707?v=3","gravatar_id":"","url":"https://api.github.com/users/TiagoCardoso1983","html_url":"https://github.com/TiagoCardoso1983","followers_url":"https://api.github.com/users/TiagoCardoso1983/followers","following_url":"https://api.github.com/users/TiagoCardoso1983/following{/other_user}","gists_url":"https://api.github.com/users/TiagoCardoso1983/gists{/gist_id}","starred_url":"https://api.github.com/users/TiagoCardoso1983/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TiagoCardoso1983/subscriptions","organizations_url":"https://api.github.com/users/TiagoCardoso1983/orgs","repos_url":"https://api.github.com/users/TiagoCardoso1983/repos","events_url":"https://api.github.com/users/TiagoCardoso1983/events{/privacy}","received_events_url":"https://api.github.com/users/TiagoCardoso1983/received_events","type":"User","site_admin":false},"created_at":"2016-01-29T14:54:04Z","updated_at":"2016-01-29T14:54:04Z","body":"@ioquatix problem is here: https://github.com/celluloid/timers/blob/master/lib/timers/group.rb#L66-L70. I've been following this and, in the normal case, you yield two intervals, fire the events in the end, and the timer get's cancelled after. You can see an example below:\r\n\r\n```\r\nsuccessfull timeout fetch: 2016-01-29 15:42:59 +0100   \r\nGroup has 1 events        \r\nHandle: #<Timers::Events::Handle:0x007fe97ad1cf70>     \r\nactor#run: interval 1.9999147540000024                     \r\nGroup has 1 events        \r\nHandle: #<Timers::Events::Handle:0x007fe97ad1cf70>     \r\nkaboom!!!!!!!! (timer.cancel from Celluloid::Actor)\r\nsuccessfull timeout fetch: 2016-01-29 15:43:01 +0100\r\n...\r\n```\r\n\r\nMain feature is that the handle must be a valid (not yet cancelled one), which means the timer hasn't been triggered yet. In fact, the problem arrive as soon as the timer cancels in between the two calls on wait_interval there in the link:\r\n\r\n```\r\nsuccessfull timeout fetch: 2016-01-29 15:43:03 +0100     \r\nGroup has 1 events          \r\nHandle: #<Timers::Events::Handle:0x007fe97ad146b8>       \r\nactor: interval 1.999946142000006                        \r\n(timer gets cancelled here, but the task is not resumable at this point)\r\nGroup has 1 events    \r\nHandle: #<Timers::Events::Handle:0x007fe97ad146b8> but it is cancelled!!!\r\nGroup has 0 events    \r\nactor: interval (nil)\r\n# our problems start here\r\n....\r\n```                               \r\n\r\nI can't investigate this further, at least for today and the weekend, but my the main issue is right there: you can't fire cancelled handles."}}