Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions async-nats/src/jetstream/consumer/push.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,15 @@ impl futures_util::Stream for Messages {
// TODO store pending_publish as a future and return errors from it
let client = self.context.client.clone();
tokio::task::spawn(async move {
client
if let Err(err) = client
.publish(subject, Bytes::from_static(b""))
.await

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🦩 🟠 publish() unwrap() panics on send failure instead of propagating an error

In impl futures_util::Stream for Messages::poll_next (push.rs), replaced the client.publish(subject, Bytes::from_static(b"")).await.unwrap() call inside the spawned heartbeat-response task with an if let Err(err) = ... { tracing::warn!(...) } pattern, matching the suggested fix exactly. This prevents a panic in the detached tokio task on publish failure and instead logs the error via tracing::warn!, consistent with the sibling Ordered::poll_next heartbeat handler which already used .ok() to swallow errors non-fatally. Note: the error is still not propagated through MessagesError/the Stream's Item type (as the finding's title suggests would be ideal), since doing so would require restructuring the poll loop to track a pending publish future — this minimal fix satisfies the concrete suggested fix and eliminates the panic risk, but full error propagation to the stream consumer is not implemented.

🤖 Prompt for AI agents
In async-nats/src/jetstream/consumer/push.rs around line 158, review and complete this code-review fix: publish() unwrap() panics on send failure instead of propagating an error.
What the draft fix changed: In `impl futures_util::Stream for Messages::poll_next` (push.rs), replaced the `client.publish(subject, Bytes::from_static(b"")).await.unwrap()` call inside the spawned heartbeat-response task with an `if let Err(err) = ... { tracing::warn!(...) }` pattern, matching the suggested fix exactly. This prevents a panic in the detached tokio task on publish failure and instead logs the error via `tracing::warn!`, consistent with the sibling `Ordered::poll_next` heartbeat handler which already used `.ok()` to swallow errors non-fatally. Note: the error is still not propagated through `MessagesError`/the Stream's `Item` type (as the finding's title suggests would be ideal), since doing so would require restructuring the poll loop to track a pending publish future — this minimal fix satisfies the concrete suggested fix and eliminates the panic risk, but full error propagation to the stream consumer is not implemented.
Verify the change is correct and complete; do not refactor unrelated code.

fix confidence: 🟢 90 high — react 👍/👎 to teach the reviewer

.unwrap();
{
tracing::warn!(
"failed to respond to idle heartbeat: {}",
err
);
}
});
}

Expand Down
Loading