digital-fabric / polyphony

Fine-grained concurrency for Ruby
https://www.rubydoc.info/gems/polyphony
MIT License
661 stars 17 forks source link

Can not bind to port when there are connections in TIME_WAIT state #97

Closed jsaak closed 1 year ago

jsaak commented 1 year ago

How to reproduce the error:

$ git clone https://github.com/jsaak/ruby3-tcp-server-mini-benchmark.git
$ cd ruby3-tcp-server-mini-benchmark
$ ruby loop.rb polyphony.rb
spawn
/usr/bin/wrk -t1 -c1 -d1s http://localhost:9090
waiting for process to die
spawn
polyphony.rb:3:in `new': Address already in use - bind(2) for 127.0.0.1:9090 (Errno::EADDRINUSE)
    from polyphony.rb:3:in `<main>'

If you put a sleep 70 in the loop, then all is good on Linux, since connections will stay in TIME_WAIT for 60 sec. (ruby 3.2.1, polyphony 0.99, Linux 5.10.0-19-amd64 #1 SMP Debian 5.10.149-2 (2022-10-21) x86_64 GNU/Linux)