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

fix: surface fatal error to caller #321

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
24 changes: 10 additions & 14 deletions src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -869,26 +869,22 @@ impl<Exe: Executor> Connection<Exe> {
return Ok(Connection { id, url, sender });
}

let mut fatal_errors = vec![];
let mut retryable_errors = vec![];
// Prefer returning a retryable error if possible, so that the caller can
// retry the connection attempt. If all errors are fatal, return the first
// fatal error found.
let mut fatal_error = None;

for e in errors.into_iter() {
if e.establish_retryable() {
retryable_errors.push(e);
return Err(e);
} else {
fatal_errors.push(e);
if fatal_error.is_none() {
fatal_error = Some(e);
}
}
}

if retryable_errors.is_empty() {
error!("connection error, not retryable: {:?}", fatal_errors);
Err(ConnectionError::Io(std::io::Error::new(
std::io::ErrorKind::Other,
"fatal error when connecting to the Pulsar server",
)))
} else {
warn!("retry establish connection on: {:?}", retryable_errors);
Err(retryable_errors.into_iter().next().unwrap())
}
Err(fatal_error.expect("expected fatal error"))
}

#[cfg_attr(feature = "telemetry", tracing::instrument(skip_all))]
Expand Down
1 change: 1 addition & 0 deletions src/connection_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ impl<Exe: Executor> ConnectionManager<Exe> {
self.executor.delay(current_backoff).await;
}
Err(e) => {
error!("connection error, not retryable: {}", e);
return Err(e);
}
}
Expand Down
Loading