From bf021aa481338c758c4db4e5af6161911711d3cc Mon Sep 17 00:00:00 2001 From: jokemanfire Date: Thu, 8 Aug 2024 15:37:36 +0800 Subject: [PATCH] Fix:lock unwrap cause panic If streams cannot be locked, it will cause a panic Signed-off-by: jokemanfire --- src/asynchronous/client.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/asynchronous/client.rs b/src/asynchronous/client.rs index ed2ee3a8..2eb36e58 100644 --- a/src/asynchronous/client.rs +++ b/src/asynchronous/client.rs @@ -74,8 +74,9 @@ impl Client { let (tx, mut rx): (ResultSender, ResultReceiver) = mpsc::channel(100); - // TODO: check return. - self.streams.lock().unwrap().insert(stream_id, tx); + self.streams.lock().map(|mut x| { + x.insert(stream_id, tx); + }).map_err(|_| Error::Others("Failed to acquire lock on streams".to_string()))?; self.req_tx .send(msg) @@ -136,8 +137,10 @@ impl Client { } let (tx, rx): (ResultSender, ResultReceiver) = mpsc::channel(100); - // TODO: check return - self.streams.lock().unwrap().insert(stream_id, tx); + self.streams.lock().map(|mut x| { + x.insert(stream_id, tx); + }).map_err(|_| Error::Others("Failed to acquire lock on streams".to_string()))?; + self.req_tx .send(msg) .await