mirror of
https://github.com/LemmyNet/lemmy
synced 2024-11-10 06:54:12 +00:00
Add timeout for processing incoming activities
This commit is contained in:
parent
522f974e30
commit
e34e6a837a
3 changed files with 1641 additions and 2022 deletions
File diff suppressed because it is too large
Load diff
|
@ -20,7 +20,8 @@ use lemmy_db_schema::{
|
||||||
};
|
};
|
||||||
use lemmy_utils::error::{LemmyErrorType, LemmyResult};
|
use lemmy_utils::error::{LemmyErrorType, LemmyResult};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::ops::Deref;
|
use std::{ops::Deref, time::Duration};
|
||||||
|
use tokio::time::timeout;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
mod comment;
|
mod comment;
|
||||||
|
@ -35,8 +36,15 @@ pub async fn shared_inbox(
|
||||||
body: Bytes,
|
body: Bytes,
|
||||||
data: Data<LemmyContext>,
|
data: Data<LemmyContext>,
|
||||||
) -> LemmyResult<HttpResponse> {
|
) -> LemmyResult<HttpResponse> {
|
||||||
receive_activity::<SharedInboxActivities, UserOrCommunity, LemmyContext>(request, body, &data)
|
let receive_fut =
|
||||||
|
receive_activity::<SharedInboxActivities, UserOrCommunity, LemmyContext>(request, body, &data);
|
||||||
|
// Set a timeout shorter than `REQWEST_TIMEOUT` for processing incoming activities. This is to
|
||||||
|
// avoid taking a long time to process an incoming activity when a required data fetch times out.
|
||||||
|
// In this case our own instance would timeout and be marked as dead by the sender. Better to
|
||||||
|
// consider the activity broken and move on.
|
||||||
|
timeout(Duration::from_secs(9), receive_fut)
|
||||||
.await
|
.await
|
||||||
|
.map_err(|_| LemmyErrorType::InboxTimeout)?
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convert the data to json and turn it into an HTTP Response with the correct ActivityPub
|
/// Convert the data to json and turn it into an HTTP Response with the correct ActivityPub
|
||||||
|
|
|
@ -177,6 +177,7 @@ pub enum LemmyErrorType {
|
||||||
InvalidBotAction,
|
InvalidBotAction,
|
||||||
CantBlockLocalInstance,
|
CantBlockLocalInstance,
|
||||||
UrlWithoutDomain,
|
UrlWithoutDomain,
|
||||||
|
InboxTimeout,
|
||||||
Unknown(String),
|
Unknown(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue