celluloid / celluloid-io

UNMAINTAINED: See celluloid/celluloid#779 - Evented sockets for Celluloid actors
https://celluloid.io
MIT License
879 stars 93 forks source link

Crashing with limited debugging output. #110

Closed ioquatix closed 10 years ago

ioquatix commented 10 years ago

I have a top level Server which spawns UDPHandler and TCPHandler instances for handling incoming requests.

I get the following error:

I, [2014-05-21T13:00:07.169418 #76622]  INFO -- : Starting RubyDNS server (v0.9.0)...
D, [2014-05-21T13:00:07.169550 #76622] DEBUG -- : Terminating 3 actors...
I, [2014-05-21T13:00:07.169621 #76622]  INFO -- : Listening on udp:0.0.0.0:5300
I, [2014-05-21T13:00:07.169981 #76622]  INFO -- : Creating handler
W, [2014-05-21T13:00:07.170514 #76622]  WARN -- : Terminating task: type=:call, meta={:method_name=>:run}, status=:callwait
    /Users/samuel/.rvm/gems/ruby-2.1.2/gems/celluloid-0.16.0.pre/lib/celluloid/tasks/task_thread.rb:32:in `pop'
    /Users/samuel/.rvm/gems/ruby-2.1.2/gems/celluloid-0.16.0.pre/lib/celluloid/tasks/task_thread.rb:32:in `signal'
    /Users/samuel/.rvm/gems/ruby-2.1.2/gems/celluloid-0.16.0.pre/lib/celluloid/tasks.rb:82:in `suspend'
    /Users/samuel/.rvm/gems/ruby-2.1.2/gems/celluloid-0.16.0.pre/lib/celluloid/tasks.rb:24:in `suspend'
    /Users/samuel/.rvm/gems/ruby-2.1.2/gems/celluloid-0.16.0.pre/lib/celluloid.rb:114:in `suspend'
    /Users/samuel/.rvm/gems/ruby-2.1.2/gems/celluloid-0.16.0.pre/lib/celluloid/calls.rb:88:in `response'
    /Users/samuel/.rvm/gems/ruby-2.1.2/gems/celluloid-0.16.0.pre/lib/celluloid/calls.rb:92:in `value'
    /Users/samuel/.rvm/gems/ruby-2.1.2/gems/celluloid-0.16.0.pre/lib/celluloid/proxies/sync_proxy.rb:33:in `method_missing'
    /Users/samuel/.rvm/gems/ruby-2.1.2/gems/celluloid-0.16.0.pre/lib/celluloid/proxies/cell_proxy.rb:17:in `_send_'
    /Users/samuel/.rvm/gems/ruby-2.1.2/gems/celluloid-0.16.0.pre/lib/celluloid.rb:169:in `new'
    /Users/samuel/Documents/Programming/Internet/rubydns/lib/rubydns/server.rb:158:in `bind_udp_socket'
    /Users/samuel/Documents/Programming/Internet/rubydns/lib/rubydns/server.rb:132:in `block in run'
    /Users/samuel/Documents/Programming/Internet/rubydns/lib/rubydns/server.rb:129:in `each'
    /Users/samuel/Documents/Programming/Internet/rubydns/lib/rubydns/server.rb:129:in `run'
    /Users/samuel/.rvm/gems/ruby-2.1.2/gems/celluloid-0.16.0.pre/lib/celluloid/calls.rb:26:in `public_send'
    /Users/samuel/.rvm/gems/ruby-2.1.2/gems/celluloid-0.16.0.pre/lib/celluloid/calls.rb:26:in `dispatch'
    /Users/samuel/.rvm/gems/ruby-2.1.2/gems/celluloid-0.16.0.pre/lib/celluloid/calls.rb:122:in `dispatch'
    /Users/samuel/.rvm/gems/ruby-2.1.2/gems/celluloid-0.16.0.pre/lib/celluloid/cell.rb:60:in `block in invoke'
    /Users/samuel/.rvm/gems/ruby-2.1.2/gems/celluloid-0.16.0.pre/lib/celluloid/cell.rb:71:in `block in task'
    /Users/samuel/.rvm/gems/ruby-2.1.2/gems/celluloid-0.16.0.pre/lib/celluloid/actor.rb:362:in `block in task'
    /Users/samuel/.rvm/gems/ruby-2.1.2/gems/celluloid-0.16.0.pre/lib/celluloid/tasks.rb:55:in `block in initialize'
    /Users/samuel/.rvm/gems/ruby-2.1.2/gems/celluloid-0.16.0.pre/lib/celluloid/tasks/task_thread.rb:21:in `block in create'
    /Users/samuel/.rvm/gems/ruby-2.1.2/gems/celluloid-0.16.0.pre/lib/celluloid/thread_handle.rb:13:in `block in initialize'
    /Users/samuel/.rvm/gems/ruby-2.1.2/gems/celluloid-0.16.0.pre/lib/celluloid/actor_system.rb:32:in `block in get_thread'
    /Users/samuel/.rvm/gems/ruby-2.1.2/gems/celluloid-0.16.0.pre/lib/celluloid/internal_pool.rb:99:in `call'
    /Users/samuel/.rvm/gems/ruby-2.1.2/gems/celluloid-0.16.0.pre/lib/celluloid/internal_pool.rb:99:in `block in create'
I, [2014-05-21T13:00:07.170575 #76622]  INFO -- : Entering runloop

Here is the abbreviated code:

class Server
    include Celluloid::IO
    def initialize
        # ...
        async.run
    end

    # ...

    def run
        bind_udp_socket(...)
    end

    def bind_udp_socket(host, port)
        socket = UDPSocket.new
        socket.bind(host, port)

        Celluloid.logger.info "Creating handler"
        @handlers << UDPHandler.new(self, socket)
        Celluloid.logger.info "Handler created"
    end
end

class UDPHandler
    include Celluloid::IO
    def initialize(server, socket)
        @server = server
        @socket = socket

        async.run
    end

    def run
        puts "Entering runloop"
        loop {
            @socket.recvfrom(...)
            # ...
        }
    end
end

What am I doing wrong or is this a bug?

ioquatix commented 10 years ago

Okay, my bad, looks like I need to call sleep in the main thread/program.

michaelmior commented 9 years ago

I'm having what looks to be the same issue. Can you clarify what your fix was?

ioquatix commented 9 years ago

Don't let the main thread/process die eg use sleep at the end of your main program.