mirror of
https://github.com/nostrlabs-io/notepush.git
synced 2025-06-15 03:26:34 +00:00
Add timeout to mute list fetching
If a relay does not have a user's mutelist, a function in our pipeline would wait indefinitely, causing all other requests to be locked as well. This commit adds a timeout to avoid this issue Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
This commit is contained in:
@ -1,5 +1,6 @@
|
|||||||
use super::ExtendedEvent;
|
use super::ExtendedEvent;
|
||||||
use nostr_sdk::prelude::*;
|
use nostr_sdk::prelude::*;
|
||||||
|
use tokio::time::{timeout, Duration};
|
||||||
|
|
||||||
pub struct MuteManager {
|
pub struct MuteManager {
|
||||||
client: Client,
|
client: Client,
|
||||||
@ -99,19 +100,27 @@ impl MuteManager {
|
|||||||
|
|
||||||
let mut mute_list: Option<Event> = None;
|
let mut mute_list: Option<Event> = None;
|
||||||
let mut notifications = self.client.notifications();
|
let mut notifications = self.client.notifications();
|
||||||
while let Ok(notification) = notifications.recv().await {
|
|
||||||
if let RelayPoolNotification::Event {
|
let timeout_duration = Duration::from_secs(10);
|
||||||
subscription_id,
|
while let Ok(result) = timeout(timeout_duration, notifications.recv()).await {
|
||||||
event,
|
if let Ok(notification) = result {
|
||||||
..
|
if let RelayPoolNotification::Event {
|
||||||
} = notification
|
subscription_id,
|
||||||
{
|
event,
|
||||||
if this_subscription_id == subscription_id && event.kind == Kind::MuteList {
|
..
|
||||||
mute_list = Some((*event).clone());
|
} = notification
|
||||||
break;
|
{
|
||||||
|
if this_subscription_id == subscription_id && event.kind == Kind::MuteList {
|
||||||
|
mute_list = Some((*event).clone());
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if mute_list.is_none() {
|
||||||
|
log::debug!("Mute list not found for pubkey {:?}", pubkey);
|
||||||
|
}
|
||||||
|
|
||||||
self.client.unsubscribe(this_subscription_id).await;
|
self.client.unsubscribe(this_subscription_id).await;
|
||||||
mute_list
|
mute_list
|
||||||
|
Reference in New Issue
Block a user