From 9aa972dd83a85cec5da71e8e893eb6e07d5db8ca Mon Sep 17 00:00:00 2001 From: hozan23 Date: Fri, 21 Jun 2024 22:45:17 +0200 Subject: jsonrpc/client: fix subscription error when the subscriber cannot keep up Add a limit for receiving notifications for the subscription. If this limit is exceeded, the client will stop and raise an error. The limit is configurable when building a new client. --- jsonrpc/src/client/message_dispatcher.rs | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'jsonrpc/src/client/message_dispatcher.rs') diff --git a/jsonrpc/src/client/message_dispatcher.rs b/jsonrpc/src/client/message_dispatcher.rs index 14dcc71..f370985 100644 --- a/jsonrpc/src/client/message_dispatcher.rs +++ b/jsonrpc/src/client/message_dispatcher.rs @@ -34,6 +34,15 @@ impl MessageDispatcher { self.chans.lock().await.remove(id); } + /// Clear the registered channels. + pub(super) async fn clear(&self) { + let mut chans = self.chans.lock().await; + for (_, tx) in chans.iter() { + tx.close(); + } + chans.clear(); + } + /// Dispatches a response to the channel associated with the response's ID. /// /// If a channel is registered for the response's ID, the response is sent -- cgit v1.2.3