Skip to content

Commit 00de628

Browse files
committed
Fix:lock unwrap cause panic
If streams cannot be locked, it will cause a panic Signed-off-by: jokemanfire <hu.dingyang@zte.com.cn>
1 parent 152ac12 commit 00de628

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/asynchronous/client.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,10 @@ impl Client {
7474

7575
let (tx, mut rx): (ResultSender, ResultReceiver) = mpsc::channel(100);
7676

77-
// TODO: check return.
78-
self.streams.lock().unwrap().insert(stream_id, tx);
77+
self.streams
78+
.lock()
79+
.map_err(|_| Error::Others("Failed to acquire lock on streams".to_string()))?
80+
.insert(stream_id, tx);
7981

8082
self.req_tx
8183
.send(msg)
@@ -136,8 +138,11 @@ impl Client {
136138
}
137139

138140
let (tx, rx): (ResultSender, ResultReceiver) = mpsc::channel(100);
139-
// TODO: check return
140-
self.streams.lock().unwrap().insert(stream_id, tx);
141+
self.streams
142+
.lock()
143+
.map_err(|_| Error::Others("Failed to acquire lock on streams".to_string()))?
144+
.insert(stream_id, tx);
145+
141146
self.req_tx
142147
.send(msg)
143148
.await

0 commit comments

Comments
 (0)