nostr-rs-relay

My dev fork of nostr-rs-relay
git clone git://jb55.com/nostr-rs-relay
Log | Files | Refs | README | LICENSE

commit 4cc313fa2d8006f21a4219551a2a354145cfaadd
parent 6502f7dcd7218de0171795aa1e853471177640aa
Author: Greg Heartsfield <scsibug@imap.cc>
Date:   Sun, 30 Jan 2022 15:14:02 -0600

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.

Diffstat:
Msrc/main.rs | 6++++--
1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/main.rs b/src/main.rs @@ -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());