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

[Merged by Bors] - feat: fail fast if socket is stale #3054

Closed
wants to merge 6 commits into from
Closed
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
3 changes: 2 additions & 1 deletion crates/fluvio-auth/src/x509/authenticator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ impl X509Authenticator {
.await
.map_err(|err| match err {
fluvio_socket::SocketError::Io { source, .. } => source,
fluvio_socket::SocketError::SocketClosed => {
fluvio_socket::SocketError::SocketClosed
| fluvio_socket::SocketError::SocketStale => {
IoError::new(IoErrorKind::BrokenPipe, "connection closed")
}
})?;
Expand Down
2 changes: 2 additions & 0 deletions crates/fluvio-socket/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ pub enum SocketError {
Io { source: IoError, msg: String },
#[error("Socket closed")]
SocketClosed,
#[error("Socket is stale")]
SocketStale,
}

impl From<IoError> for SocketError {
Expand Down
19 changes: 19 additions & 0 deletions crates/fluvio-socket/src/versioned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,12 +248,27 @@ impl VersionedSerialSocket {
self.socket.clone()
}

/// Check if inner socket is stale
pub fn is_stale(&self) -> bool {
self.socket.is_stale()
}

fn check_liveness(&self) -> Result<(), SocketError> {
if self.is_stale() {
Err(SocketError::SocketStale)
} else {
Ok(())
}
}

/// send and wait for reply serially
#[instrument(level = "trace", skip(self, request))]
pub async fn send_receive<R>(&self, request: R) -> Result<R::Response, SocketError>
where
R: Request + Send + Sync,
{
self.check_liveness()?;

let req_msg = self.new_request(request, self.versions.lookup_version::<R>());

// send request & save response
Expand All @@ -266,6 +281,8 @@ impl VersionedSerialSocket {
where
R: Request + Send + Sync,
{
self.check_liveness()?;

let req_msg = self.new_request(request, self.versions.lookup_version::<R>());

// send request & get a Future that resolves to response
Expand All @@ -283,6 +300,8 @@ impl VersionedSerialSocket {
R: Request + Send + Sync + Clone,
I: IntoIterator<Item = Duration> + Debug + Send,
{
self.check_liveness()?;

let req_msg = self.new_request(request, self.versions.lookup_version::<R>());

// send request & retry it if result is Err
Expand Down