Giter Site home page Giter Site logo

Comments (3)

repeatedly avatar repeatedly commented on August 14, 2024

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

from cool.io.

ganmacs avatar ganmacs commented on August 14, 2024

I think this is expected behavior.
What Cool.io::TCPServer#close does is just closing a socket listening*, not closing the accepted socket. the method is similar to TcpServer#close.

So here is the correct code to shutdown coolio.

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
conns = []
server = Cool.io::TCPServer.new(HOST, PORT, ServerConnection) do |conn|
  conns << conn
end
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
conns.each do |c|
  c.close
end
puts 'server stopped'
sleep 1

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

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

We can find another problem here.
Calling second sock.send "message", 0 succeeded even if the accepted socket was already closed on the server-side.
it seems to be related to fluent/fluentd#1985 (also I don't think this is coolio's issue, it's a TCP stack issue).

from cool.io.

ioquatix avatar ioquatix commented on August 14, 2024

It sounds wrong to me, but please consider making a PR, as I don't think anyone is invested in maintaining this code base.

from cool.io.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.