http-rs / tide

Fast and friendly HTTP server framework for async Rust
https://docs.rs/tide
Apache License 2.0
5.03k stars 323 forks source link

Remove Unix Socket on close #669

Open yoshuawuyts opened 4 years ago

yoshuawuyts commented 4 years ago

@timsuchanek reported an issue with Tide's unix:// handler where on close the socket is kept open on disk. This caused issues when closing and then restarting a server over UDS.

We should ensure that when a Tide server is closed we close the UDS socket too. If need be we can do this synchronously on Drop.

Open question: graceful termination

Something I do wonder though is what happens to any open clients on the other side of the socket when we remove it from the filesystem. I would imagine they just get an error on the next system call since the fd no longer exists? The alternative is that they time out since the server is no longer active and responding.

Probably the right solution in the future is to enable graceful termination of connections so that we can send a signal to the application, and then stop accepting new connections before the application exits. We should also enable this on async drop when it lands; but that may be further out.

Fishrock123 commented 4 years ago

Related to https://github.com/http-rs/tide/issues/528 "Graceful shutdown"

rtyler commented 3 years ago

My workaround for this has been to simply run std::fs::remove_file("my.sock"); before starting the listener.

IMHO that may be something worth incorporating into the listener itself :woman_shrugging:

jcbritobr commented 3 years ago

My workaround for this has been to simply run std::fs::remove_file("my.sock"); before starting the listener.

IMHO that may be something worth incorporating into the listener itself 🤷‍♀️

Or at least trigger an error saying that file already exists.