hhvm / hsl-experimental

Experimental features for the Hack Standard Library
MIT License
23 stars 10 forks source link

[Network] no way to set SO_REUSEADDR #101

Closed azjezz closed 4 years ago

azjezz commented 4 years ago

example :

$tcp = TCP\Server::createAsync($ipv4, '127.0.0.1', 8080);
// results in ADDRINUSE, how to stop the first one ?
// $tcp = TCP\Server::createAsync($ipv4, '127.0.0.1', 8080);
fredemmott commented 4 years ago

It's not necessarily that it's actually in-use, or that it's still listening: the usual cause is the server has stopped, but the socket remains in TIME_WAIT state for several minutes. This is standard, defined behavior of TCP. Most operating systems let you ignore TIME_WAIT with SO_REUSEADDR, but this does potentially cause problems if there were any packets sent to the old server but not yet received.

It should be added to the HSL

azjezz commented 4 years ago

no way to set SO_REUSEADDR

Note: this is not just about reusing already in use addresses, but also stopping servers to free up the port.

fredemmott commented 4 years ago

Ah, you're trying to reuse the same port in the same process, just not at the same time? If so, shoudl have a separate issue for each

azjezz commented 4 years ago

Ah, you're trying to reuse the same port in the same process, just not at the same time

yes, or in a different process :)

i just want to make sure i can free up the port when the process is killed via pcntl_signal :)

fredemmott commented 4 years ago

when the process is killed via pcntl_signal

AIUI this is entirely the SO_REUSEADDR/TIME_WAIT case

We definitely should have the ability to stop the server, but it's not needed/doesn't help for "I want the port when the process exits" case