Skip to content

Instantly share code, notes, and snippets.

@jsonperl
Last active December 7, 2015 03:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jsonperl/82cdfa31490b52315b47 to your computer and use it in GitHub Desktop.
Save jsonperl/82cdfa31490b52315b47 to your computer and use it in GitHub Desktop.
source "https://rubygems.org"
ruby "1.9.3", engine: "jruby", engine_version: "1.7.23"
gem "celluloid-io"
require "celluloid/io"
class Issue
include Celluloid::IO
def initialize
every(0.1) { puts "WORKING #{Time.now.to_i}" }
end
end
client = Issue.new
sleep
require "celluloid/current"
require "celluloid/io"
class IssueWithIO
include Celluloid::IO
def initialize(host, port)
puts "Connecting server on #{host}:#{port}"
@socket = TCPSocket.new(host, port)
async.run
end
def send_data(data)
@socket.write([999, data.bytesize].pack("CL"))
@socket.write(data)
end
def listen
loop do
@socket.readpartial(4096)
puts "GOT A MESSAGE! #{Time.now.to_i}"
end
end
def run
async.listen
every(1) do
send_data "HELLO CELLULOID #{Time.now.to_i}"
end
end
end
supervisor = IssueWithIO.new("0.0.0.0", 5000)
sleep
require "celluloid"
class Issue
include Celluloid
def initialize
every(0.1) { puts "WORKING #{Time.now.to_i}" }
end
end
client = Issue.new
sleep
@jsonperl
Copy link
Author

jsonperl commented Dec 6, 2015

Works on MRI 2.2.3
Does not work on JRuby 1.7.23

~ bundle exec ruby issue.rb 
I, [2015-12-06T13:43:28.321000 #28450]  INFO -- : Celluloid 0.17.2 is running in BACKPORTED mode. [ http://git.io/vJf3J ]
WORKING 1449431009
WORKING 1449431009
WORKING 1449431009
WORKING 1449431009
WORKING 1449431009
WORKING 1449431009
WORKING 1449431009
WORKING 1449431009
WORKING 1449431009
WORKING 1449431010
WORKING 1449431010
WORKING 1449431010
WORKING 1449431010
WORKING 1449431010
WORKING 1449431010
WORKING 1449431010
WORKING 1449431010
WORKING 1449431010
WORKING 1449431010
WORKING 1449431011
WORKING 1449431011

Then hangs indefinitely

@jsonperl
Copy link
Author

jsonperl commented Dec 6, 2015

Interestingly, including Celluloid and not Celluloid::IO, this example runs fine.

@digitalextremist
Copy link

@jsonperl when you use Celluloid::IO there is expected to be I/O involved, especially some kind of network traffic that would normally be "blocking" and is instead "evented" ... which creates back-pressure. I'd imagine you're having issues because the example code is intended to work with Celluloid and not need Celluloid::IO at all, because it has no I/O. Granted, your example should at least show an error if it doesn't work, or just work -- but it'd make sense that the jRuby I/O selector has no activity going on.

@jsonperl
Copy link
Author

jsonperl commented Dec 7, 2015

@digitalextremist first off, thanks so much for responding quickly, and for the help. I really appreciate it.

The example provided was as minimal as I could make to demonstrate the issue. I've added another minimal(ish) example exhibiting the exact same behavior, but with IO involved: issue_with_io.rb. Again, works fine in MRI, and sends data successfully to the server, but hangs very quickly with JRuby.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment