Skip to content

Commit 57d1584

Browse files
author
Hui Zhu
authored
Merge pull request #56 from lifupan/fix
client: fix the issue of panic when client request timeout
2 parents 42e8618 + 3d161c1 commit 57d1584

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

src/asynchronous/client.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,10 @@ impl Client {
7373
}
7474

7575
let e = Error::Socket(format!("{:?}", e));
76-
resp_tx.send(Err(e)).await.unwrap();
76+
resp_tx
77+
.send(Err(e))
78+
.await
79+
.unwrap_or_else(|_e| error!("The request has returned"));
7780

7881
break; // The stream is dead, exit the loop.
7982
}
@@ -121,11 +124,11 @@ impl Client {
121124
header, body
122125
))))
123126
.await
124-
.unwrap();
127+
.unwrap_or_else(|_e| error!("The request has returned"));
125128
return;
126129
}
127130

128-
resp_tx2.send(Ok(body)).await.unwrap();
131+
resp_tx2.send(Ok(body)).await.unwrap_or_else(|_e| error!("The request has returned"));
129132
});
130133
}
131134
Err(e) => {
@@ -167,7 +170,7 @@ impl Client {
167170
result.ok_or_else(|| Error::Others("Recive packet from recver error".to_string()))?
168171
}
169172
_ = timeout => {
170-
return Err(Error::Others("Recive packet from recver error".to_string()));
173+
return Err(Error::Others("Recive packet from recver error: timeout".to_string()));
171174
}
172175
}
173176
};

src/sync/client.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@ impl Client {
8282
let mut map = recver_map.lock().unwrap();
8383
map.remove(&current_stream_id);
8484
}
85-
recver_tx.send(Err(e)).unwrap();
85+
recver_tx
86+
.send(Err(e))
87+
.unwrap_or_else(|_e| error!("The request has returned"));
8688
}
8789
}
8890
trace!("Sender quit");
@@ -149,11 +151,13 @@ impl Client {
149151
"Recver got malformed packet {:?} {:?}",
150152
mh, buf
151153
))))
152-
.unwrap();
154+
.unwrap_or_else(|_e| error!("The request has returned"));
153155
continue;
154156
}
155157

156-
recver_tx.send(Ok(buf)).unwrap();
158+
recver_tx
159+
.send(Ok(buf))
160+
.unwrap_or_else(|_e| error!("The request has returned"));
157161

158162
map.remove(&mh.stream_id);
159163
}

0 commit comments

Comments
 (0)