Skip to content

Commit

Permalink
feat: further detect common io errors in megaphone's updater (#492)
Browse files Browse the repository at this point in the history
return SMError's backtrace for WSError (for now)

SYNC-3978
  • Loading branch information
pjenvey authored Oct 31, 2023
1 parent bbde582 commit 5421f58
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 2 deletions.
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

0 comments on commit 5421f58

Please sign in to comment.