commit 82669a5be9f747e41061f1120ae211ea2d044b6a
parent f1a80c0793176c0a97e2ef760272c223e52c2db6
Author: William Casarin <jb55@jb55.com>
Date: Mon, 30 Dec 2024 09:36:01 -0800
fix subscription exhaustion
Switch SubscriptionStream's to unsubscribe on Drop. This will fix any
issues with missing unsubscribe if we're returning an error somewhere.
Changelog-Fixed: Fix subscription leaks leading to 500s
Diffstat:
3 files changed, 5 insertions(+), 8 deletions(-)
diff --git a/Cargo.lock b/Cargo.lock
@@ -1622,7 +1622,7 @@ dependencies = [
[[package]]
name = "nostrdb"
version = "0.5.1"
-source = "git+https://github.com/damus-io/nostrdb-rs?rev=b4dfb0b29d6537d9f5f852028bd34c5ccff4c839#b4dfb0b29d6537d9f5f852028bd34c5ccff4c839"
+source = "git+https://github.com/damus-io/nostrdb-rs?rev=e8b6e258410ff8acb0f689f8cf2fe287e19c6280#e8b6e258410ff8acb0f689f8cf2fe287e19c6280"
dependencies = [
"bindgen 0.69.5",
"cc",
diff --git a/Cargo.toml b/Cargo.toml
@@ -13,7 +13,7 @@ hyper-util = { version = "0.1.1", features = ["full"] }
http-body-util = "0.1"
log = "0.4.20"
env_logger = "0.10.1"
-nostrdb = { git = "https://github.com/damus-io/nostrdb-rs", rev = "b4dfb0b29d6537d9f5f852028bd34c5ccff4c839" }
+nostrdb = { git = "https://github.com/damus-io/nostrdb-rs", rev = "e8b6e258410ff8acb0f689f8cf2fe287e19c6280" }
#nostrdb = { path = "/home/jb55/src/rust/nostrdb-rs" }
#nostrdb = "0.1.6"
#nostr-sdk = { git = "https://github.com/damus-io/nostr-sdk.git", rev = "fc0dc7b38f5060f171228b976b9700c0135245d3" }
diff --git a/src/render.rs b/src/render.rs
@@ -298,8 +298,8 @@ impl RenderData {
};
}
- pub async fn complete(&mut self, mut ndb: Ndb, keys: Keys, nip19: Nip19) -> Result<()> {
- let (mut stream, sub_id) = {
+ pub async fn complete(&mut self, ndb: Ndb, keys: Keys, nip19: Nip19) -> Result<()> {
+ let mut stream = {
let filter = renderdata_to_filter(self);
if filter.is_empty() {
// should really never happen unless someone broke
@@ -313,7 +313,7 @@ impl RenderData {
let filters = filter.iter().map(convert_filter).collect();
let ndb = ndb.clone();
tokio::spawn(async move { find_note(ndb, keys, filters, &nip19).await });
- (stream, sub_id)
+ stream
};
let wait_for = Duration::from_secs(1);
@@ -361,9 +361,6 @@ impl RenderData {
loops += 1;
}
- if let Err(err) = ndb.unsubscribe(sub_id) {
- error!("error unsubscribing: {err}");
- }
Ok(())
}
}