-
-
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 |
Interestingly, including Celluloid and not Celluloid::IO, this example runs fine.
@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.
@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.
Works on MRI 2.2.3
Does not work on JRuby 1.7.23
Then hangs indefinitely