watchexec / cargo-watch

Watches over your Cargo project's source.
Creative Commons Zero v1.0 Universal
2.78k stars 81 forks source link

Reloading servers without catflap #98

Closed rushmorem closed 6 years ago

rushmorem commented 6 years ago

Besides using catflap, one can simply kill the process using the pkill command before restarting the server like this

cargo watch --shell "pkill -f '^target/'; cargo run"

This way, you don't have to alter your server.

passcod commented 6 years ago

That should happen anyway without the pkill; if it doesn't it's a (watchexec) bug. Restarting servers has always been possible.

Catflap has a different purpose: it offers a socket that's already open and remains open even if you stop listening on it. That way, you don't drop packets and you avoid port availability errors. It's a lot like reloading nginx or apache, for production examples: restart and you'll have downtime, reload and you won't.

rushmorem commented 6 years ago

That should happen anyway without the pkill; if it doesn't it's a (watchexec) bug. Restarting servers has always been possible.

With certain apps, like actix-web, cargo watch -x run runs into ADDR_IN_USE. Hence using pkill to kill the process before restarting.

That way, you don't drop packets and you avoid port availability errors

Ah, I see. All this looked to me like it was for avoiding port availability errors and only needed in development.

passcod commented 6 years ago

ADDR_IN_USE is because the server restarts too quickly, not because it's not killed. (Or because the server is starting sub-processes some weird way and we can't kill those easily, see the "this could be a bug" thing.) There's a delay in between releasing a socket and the socket actually being reaped. ADDR_IN_USE is exactly what I mean by "port availability" issues.

rushmorem commented 6 years ago

ADDR_IN_USE is exactly what I mean by "port availability" issues.

Yeah, I know. I thought that was the only use for catflap. Since using pkill helps avoid that port availability issue without modifying my apps, I thought catflap wasn't necessary. I was misinformed.

passcod commented 6 years ago

That's alright :) Thank you for asking in anyway! I might clarify the Readme in this regard later