Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Force-close clients on IO error #110

Merged
merged 4 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
## v0.6.3

- Allow users to use tokio v2.4.0 in their projects. See [#106](https://github.com/gbaranski/ezsockets/pull/106).
- Force-close clients if they encounter an IO error, since an IO error might mean the client is hanging (e.g. after an IP address change) and should be reconstructed.
- Return `CloseCode::Abnormal` from keepalive timeouts instead of `CloseCode::Normal`.
- Fix DDOS by honest clients when servers check capacity *after* clients connect.

Expand Down
18 changes: 11 additions & 7 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -526,20 +526,24 @@ impl<E: ClientExt, C: ClientConnector> ClientActor<E, C> {
);
}
match result {
Err(WSError::ConnectionClosed)
| Err(WSError::AlreadyClosed)
| Err(WSError::Io(_))
| Err(WSError::Tls(_)) => {
Err(WSError::ConnectionClosed) | Err(WSError::AlreadyClosed) => {
// either:
// A) The connection was closed via the close protocol, so we will allow the stream to
// handle it.
// B) We already tried and failed to submit another message, so now we are
// waiting for other parts of the select! to shut us down.
// C) An IO error means the connection closed unexpectedly, so we can try to reconnect when
// the stream fails.
}
Err(WSError::Io(_)) | Err(WSError::Tls(_)) => {
// An IO error means the connection closed unexpectedly. We don't know if the stream is
// hanging or if it will shut down, so we force-close the socket.
//
// There are edge cases where this erroneously closes the connection even though we'd rather
// use auto-reconnect. TODO: isolate the error cases where force-closing is appropriate.
return Err(Error::from("encountered IO sink close error, force-closing client actor since connection \
might be hanging"));
}
Err(_) if !closed_self => {
return Err(Error::from("unexpected sink error, aborting client actor"))
return Err(Error::from("unexpected sink error, aborting client actor"));
}
_ => (),
}
Expand Down
Loading