Skip to content

Commit

Permalink
Fix:lock unwrap cause panic
Browse files Browse the repository at this point in the history
If streams cannot be locked, it will cause a panic

Signed-off-by: jokemanfire <[email protected]>
  • Loading branch information
jokemanfire committed Sep 25, 2024
1 parent 152ac12 commit bf021aa
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/asynchronous/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit bf021aa

Please sign in to comment.