Skip to content

Commit 64cfcaf

Browse files
committed
fix: disconnect for subscription send errors
1 parent 1d2bd26 commit 64cfcaf

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

src/server.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1226,6 +1226,7 @@ async fn nostr_server(
12261226
},
12271227
// TODO: consider logging the LaggedRecv error
12281228
Ok(global_event) = bcast_rx.recv() => {
1229+
let mut should_disconnect = false;
12291230
// an event has been broadcast to all clients
12301231
// first check if there is a subscription for this event.
12311232
for (s, sub) in conn.subscriptions() {
@@ -1245,13 +1246,17 @@ async fn nostr_server(
12451246
if ws_stream.send(Message::Text(format!("[\"EVENT\",\"{subesc}\",{event_str}]"))).await.is_err() {
12461247
debug!("failed to send message, closing connection (cid: {})", cid);
12471248
metrics.disconnects.with_label_values(&["send_error"]).inc();
1249+
should_disconnect = true;
12481250
break;
12491251
}
12501252
}
12511253
} else {
12521254
warn!("could not serialize event: {:?}", global_event.get_event_id_prefix());
12531255
}
12541256
}
1257+
if should_disconnect {
1258+
break;
1259+
}
12551260
},
12561261
ws_next = ws_stream.next() => {
12571262
// update most recent message time for client

0 commit comments

Comments
 (0)