New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cool.io::TCPServer continues to receive data even if its close method is called #61

Open
abicky opened this Issue Oct 22, 2017 · 1 comment

Comments

Projects
None yet
2 participants
@abicky

abicky commented Oct 22, 2017

I expect Cool.io::TCPServer to stop receiving data after Cool.io::TCPServer#close is called, but it continues to receive data. Is this behavior expected?

Here is a reproducible code:

require 'socket'
require 'cool.io'

HOST = '127.0.0.1'
PORT = 1234

class ServerConnection < Coolio::TCPSocket
  def on_read(data)
    puts "received: #{data}"
  end
end

event_loop = Coolio::Loop.new
server = Cool.io::TCPServer.new(HOST, PORT, ServerConnection)
server.attach(event_loop)

server_thr = Thread.new { event_loop.run }
sock = TCPSocket.new(HOST, PORT)

puts "cool.io version: #{Coolio::VERSION}"

puts 'send a message'
sock.send "message", 0
sleep 1

server.close
puts 'server stopped'
sleep 1

puts 'send a message'
sock.send "message", 0
sleep 1

puts 'done'

Output

% docker run --rm -v $PWD/coolio_example.rb:/coolio_example.rb ruby:2.4.2 bash -c 'gem install cool.io && ruby /coolio_example.rb'
Building native extensions.  This could take a while...
Successfully installed cool.io-1.5.1
1 gem installed
cool.io version: 1.5.1
send a message
received: message
server stopped
send a message
received: message
done
@repeatedly

This comment has been minimized.

Collaborator

repeatedly commented Oct 24, 2017

You need to call Loop#stop before server.close.

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