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

feat: further detect common io errors in megaphone's updater #492

Merged
merged 1 commit into from
Oct 31, 2023
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 Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions autoconnect/autoconnect-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ actix-web.workspace = true
cadence.workspace = true
futures.workspace = true
futures-locks.workspace = true
hyper.workspace = true
reqwest.workspace = true
tokio.workspace = true
sentry.workspace = true
Expand Down
30 changes: 29 additions & 1 deletion autoconnect/autoconnect-common/src/megaphone.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{collections::HashMap, sync::Arc, time::Duration};
use std::{collections::HashMap, error::Error, io, sync::Arc, time::Duration};

use actix_web::rt;
use cadence::{CountedExt, StatsdClient};
Expand Down Expand Up @@ -53,6 +53,8 @@ fn report_updater_error(metrics: &Arc<StatsdClient>, err: reqwest::Error) {
"timeout"
} else if err.is_connect() {
"connect"
} else if is_io(&err) {
"io"
} else {
"unknown"
};
Expand Down Expand Up @@ -91,3 +93,29 @@ async fn updater(
}
Ok(())
}

/// Determine if a source of [reqwest::Error] was a [hyper::Error] Io Error
fn is_io(err: &reqwest::Error) -> bool {
let mut source = err.source();
while let Some(err) = source {
if let Some(hyper_err) = err.downcast_ref::<hyper::Error>() {
if is_hyper_io(hyper_err) {
return true;
}
}
source = err.source();
}
false
}

/// Determine if a source of [hyper::Error] was an [io::Error]
fn is_hyper_io(err: &hyper::Error) -> bool {
let mut source = err.source();
while let Some(err) = source {
if err.downcast_ref::<io::Error>().is_some() {
return true;
}
source = err.source();
}
false
}
7 changes: 6 additions & 1 deletion autoconnect/autoconnect-ws/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,12 @@ impl WSError {

impl ReportableError for WSError {
fn backtrace(&self) -> Option<&Backtrace> {
self.backtrace.as_ref()
// XXX: dumb hack: return SMError's backtrace for now as our
// sentry::event_from_error doesn't capture it
match &self.kind {
WSErrorKind::SM(e) => e.backtrace(),
_ => self.backtrace.as_ref(),
}
}

fn is_sentry_event(&self) -> bool {
Expand Down