housleyjk / ws-rs

Lightweight, event-driven WebSockets for Rust.
MIT License
1.46k stars 219 forks source link

Don't panic when trying to close a connection in "Connecting" state #329

Open zazabe opened 3 years ago

zazabe commented 3 years ago

It's almost impossible to control the state of a WebSocket if there's a panic here (e.g. being able to start/stop a ws client or server).

We must control each connection state to decide how to close a connection to avoid this panic, and most important point, to shutdown the WebSocket.
ws::Sender::shutdown should never panic, because it's the only way to stop a running WebSocket, and we should not have to care about the state of connections.

It's not happening in release mode, but using this crate in tests seems to be a valid use-case.

Why not using an error log instead?