Skip to content

Commit

Permalink
feat: retry dynamodb HttpDispatch errors (#605)
Browse files Browse the repository at this point in the history
and add back retry logic to fetch message calls (legacy autopush and the
python version previously did this)

Note: the majority of HttpDispatch errors are likely due to a
misconfigured pool (so retrying is a lazy fix, but sufficient):

Closes: SYNC-4126
  • Loading branch information
pjenvey authored Feb 9, 2024
1 parent 7d29c16 commit cb1482d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
18 changes: 15 additions & 3 deletions autopush-common/src/db/dynamodb/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::db::client::DbClient;
use crate::db::dynamodb::retry::{
retry_policy, retryable_batchwriteitem_error, retryable_delete_error,
retryable_describe_table_error, retryable_getitem_error, retryable_putitem_error,
retryable_updateitem_error,
retryable_query_error, retryable_updateitem_error,
};
use crate::db::error::{DbError, DbResult};
use crate::db::{
Expand Down Expand Up @@ -399,7 +399,13 @@ impl DbClient for DdbClientImpl {
..Default::default()
};

let output = self.db_client.query(input.clone()).await?;
let output = retry_policy()
.retry_if(
|| self.db_client.query(input.clone()),
retryable_query_error(self.metrics.clone()),
)
.await?;

let mut notifs: Vec<NotificationRecord> = output.items.map_or_else(Vec::new, |items| {
debug!("Got response of: {:?}", items);
items
Expand Down Expand Up @@ -462,7 +468,13 @@ impl DbClient for DdbClientImpl {
..Default::default()
};

let output = self.db_client.query(input.clone()).await?;
let output = retry_policy()
.retry_if(
|| self.db_client.query(input.clone()),
retryable_query_error(self.metrics.clone()),
)
.await?;

let messages = output.items.map_or_else(Vec::new, |items| {
debug!("Got response of: {:?}", items);
items
Expand Down
6 changes: 4 additions & 2 deletions autopush-common/src/db/dynamodb/retry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use cadence::{CountedExt, StatsdClient};
use rusoto_core::RusotoError;
use rusoto_dynamodb::{
BatchWriteItemError, DeleteItemError, DescribeTableError, GetItemError, PutItemError,
UpdateItemError,
QueryError, UpdateItemError,
};
use std::sync::Arc;

Expand All @@ -12,7 +12,8 @@ macro_rules! retryable_error {
($name:ident, $error:tt, $error_tag:expr) => {
pub fn $name(metrics: Arc<StatsdClient>) -> impl Fn(&RusotoError<$error>) -> bool {
move |err| match err {
RusotoError::Service($error::InternalServerError(_))
RusotoError::HttpDispatch(_)
| RusotoError::Service($error::InternalServerError(_))
| RusotoError::Service($error::ProvisionedThroughputExceeded(_)) => {
debug!("retryable {} {:?}", $error_tag, &err);
metrics
Expand All @@ -27,6 +28,7 @@ macro_rules! retryable_error {
};
}

retryable_error!(retryable_query_error, QueryError, "query");
retryable_error!(retryable_getitem_error, GetItemError, "get_item");
retryable_error!(retryable_updateitem_error, UpdateItemError, "update_item");
retryable_error!(retryable_putitem_error, PutItemError, "put_item");
Expand Down

0 comments on commit cb1482d

Please sign in to comment.