Skip to content

Commit 9945be2

Browse files
authored
fix: add warning logs for silent failures in RPC message handling (#92)
1 parent 116f378 commit 9945be2

File tree

1 file changed

+12
-4
lines changed
  • src/agent-client-protocol/src

1 file changed

+12
-4
lines changed

src/agent-client-protocol/src/rpc.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,9 @@ where
174174
serde_json::to_writer(&mut outgoing_line, &JsonRpcMessage::wrap(&message)).map_err(Error::into_internal_error)?;
175175
log::trace!("send: {}", String::from_utf8_lossy(&outgoing_line));
176176
outgoing_line.push(b'\n');
177-
outgoing_bytes.write_all(&outgoing_line).await.ok();
177+
if let Err(e) = outgoing_bytes.write_all(&outgoing_line).await {
178+
log::warn!("failed to send message to peer: {e}");
179+
}
178180
broadcast.outgoing(&message);
179181
} else {
180182
break;
@@ -194,7 +196,9 @@ where
194196
match Local::decode_request(&method, message.params) {
195197
Ok(request) => {
196198
broadcast.incoming_request(id.clone(), &*method, &request);
197-
incoming_tx.unbounded_send(IncomingMessage::Request { id, request }).ok();
199+
if let Err(e) = incoming_tx.unbounded_send(IncomingMessage::Request { id, request }) {
200+
log::warn!("failed to send request to handler, channel full: {e:?}");
201+
}
198202
}
199203
Err(error) => {
200204
outgoing_line.clear();
@@ -206,7 +210,9 @@ where
206210
serde_json::to_writer(&mut outgoing_line, &JsonRpcMessage::wrap(&error_response))?;
207211
log::trace!("send: {}", String::from_utf8_lossy(&outgoing_line));
208212
outgoing_line.push(b'\n');
209-
outgoing_bytes.write_all(&outgoing_line).await.ok();
213+
if let Err(e) = outgoing_bytes.write_all(&outgoing_line).await {
214+
log::warn!("failed to send error response to peer: {e}");
215+
}
210216
broadcast.outgoing(&error_response);
211217
}
212218
}
@@ -235,7 +241,9 @@ where
235241
match Local::decode_notification(&method, message.params) {
236242
Ok(notification) => {
237243
broadcast.incoming_notification(&*method, &notification);
238-
incoming_tx.unbounded_send(IncomingMessage::Notification { notification }).ok();
244+
if let Err(e) = incoming_tx.unbounded_send(IncomingMessage::Notification { notification }) {
245+
log::warn!("failed to send notification to handler, channel full: {e:?}");
246+
}
239247
}
240248
Err(err) => {
241249
log::error!("failed to decode {:?}: {err}", message.params);

0 commit comments

Comments
 (0)