mirror of
https://github.com/scsibug/nostr-rs-relay.git
synced 2024-11-22 09:09:07 -05:00
fix: cleanup database connections with same name
When a large number of subscriptions is created with identical names, we do not send a signal over the abandon-read channel. This eventually leads to resource exhaustion.
This commit is contained in:
parent
6502f7dcd7
commit
4cc313fa2d
|
@ -280,7 +280,6 @@ async fn nostr_server(
|
|||
// maintain a hashmap of a oneshot channel for active subscriptions.
|
||||
// when these subscriptions are cancelled, make a message
|
||||
// available to the executing query so it knows to stop.
|
||||
//let (abandon_query_tx, _) = oneshot::channel::<()>();
|
||||
let mut running_queries: HashMap<String, oneshot::Sender<()>> = HashMap::new();
|
||||
// for stats, keep track of how many events the client published,
|
||||
// and how many it received from queries.
|
||||
|
@ -348,7 +347,10 @@ async fn nostr_server(
|
|||
let (abandon_query_tx, abandon_query_rx) = oneshot::channel::<()>();
|
||||
match conn.subscribe(s.clone()) {
|
||||
Ok(()) => {
|
||||
running_queries.insert(s.id.to_owned(), abandon_query_tx);
|
||||
// when we insert, if there was a previous query running with the same name, cancel it.
|
||||
if let Some(previous_query) = running_queries.insert(s.id.to_owned(), abandon_query_tx) {
|
||||
previous_query.send(()).ok();
|
||||
}
|
||||
// start a database query
|
||||
// show pool stats
|
||||
debug!("DB pool stats: {:?}", pool.state());
|
||||
|
|
Loading…
Reference in New Issue
Block a user