Skip to content

Commit

Permalink
force-close clients on IO error
Browse files Browse the repository at this point in the history
  • Loading branch information
UkoeHB committed Sep 4, 2024
1 parent fde643a commit 7cb31bf
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
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.


## v0.6.2
Expand Down
13 changes: 7 additions & 6 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -526,17 +526,18 @@ 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.
tracing::warn!("force-closing client socket due to IO sink close error; connection might be hanging");
return Ok(None);
}
Err(_) if !closed_self => {
return Err(Error::from("unexpected sink error, aborting client actor"))
Expand Down

0 comments on commit 7cb31bf

Please sign in to comment.