Skip to content
This repository has been archived by the owner on Dec 7, 2018. It is now read-only.

Celluloid::TaskThread seems to be broken for UDP sockets. #111

Open
ioquatix opened this issue May 21, 2014 · 2 comments
Open

Celluloid::TaskThread seems to be broken for UDP sockets. #111

ioquatix opened this issue May 21, 2014 · 2 comments

Comments

@ioquatix
Copy link
Contributor

The following example fails unless line 8 is commented out:

#!/usr/bin/env ruby
#
# Run this as: bundle exec examples/echo_server.rb

require 'bundler/setup'
require 'celluloid/io'

Celluloid.task_class = Celluloid::TaskThread

class Server
    include Celluloid::IO
    finalizer :finalize

    def initialize
        async.run
    end

    def run
        @handler = UDPHandler.new("0.0.0.0", 8000)

        loop do
            puts @handler.inspect
            sleep 10
        end
    end
end

class UDPHandler
    include Celluloid::IO
    finalizer :finalize

    def initialize(host, port)
        puts "*** Starting echo server on #{host}:#{port}"

        # Since we included Celluloid::IO, we're actually making a
        # Celluloid::IO::TCPServer here
        @server = UDPSocket.new
        @server.bind(host, port)

        async.run
    end

    def finalize
        @server.close if @server
    end

    def run
        loop { handle_connection }
    end

    def handle_connection
        data, (_, port, host) = @server.recvfrom(1024)
        puts "*** Received connection from #{host}:#{port}"

        @server.send(data, 0, host, port)
    rescue => error
        puts "*** #{error.inspect}"
    end
end

supervisor = Server.supervise
trap("INT") { supervisor.terminate; exit }
sleep

You can test the server by running:

dig @localhost -p 8000 dev.mydomain.org A

It works fine once, then the 2nd time, it gets stuck inside recvfrom. Is this correct behaviour?

@ioquatix
Copy link
Contributor Author

I believe this issue is related to celluloid/celluloid#432 as this has been merged this should now be working - could form the basis of a spec for that bug/issue.

@digitalextremist
Copy link
Member

Still an issue @ioquatix?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants