Repository navigation
fix: prevent channel error leaks and iterator panics - #21565
Conversation
|
Important Review skippedReview was skipped as selected files did not have any reviewable changes.
|
| Layer / File(s) | Summary |
|---|---|
HTTP status errors and security tests internal/channels/whatsapp.go, internal/channels/whatsapp_security_test.go |
The request helper returns an error containing the HTTP status for responses of 400 or above before reading the body. Tests check that LastError omits the response body and that a request to an untrusted destination is rejected. |
Async iterator lifecycle
| Layer / File(s) | Summary |
|---|---|
Iterator shutdown and generator sends internal/harness/core/utils.go, internal/harness/core/async_iterator_test.go, internal/harness/core/workflow_stress_test.go |
The iterator and generator use shutdown and completion signals to coordinate closure and in-flight sends. Tests cover buffered-item draining, blocked sends, post-closure sends, and handleIter panic safety. |
Priority:
Estimated code review effort: 3 (Moderate) | ~25 minutes
Change: Bug fix
Sequence Diagram(s)
sequenceDiagram
participant Caller
participant AsyncGenerator
participant AsyncIterator
Caller->>AsyncGenerator: Start a send
Caller->>AsyncIterator: Close iterator
AsyncIterator-->>AsyncGenerator: Signal iterator shutdown
AsyncGenerator-->>Caller: Stop the in-flight send
Caller->>AsyncGenerator: Close generator
AsyncGenerator->>AsyncGenerator: Wait for in-flight sends
AsyncGenerator-->>Caller: Signal completion
Suggested labels: 🐞 bug, go
Suggested reviewers: jay77721, yuzhichang
Merge Risk: 
Minimal · previous review 0a594
-
The gateway error and iterator shutdown fixes appear ready to merge after normal checks.
Pre-merge checks: 
4 · 
1
-
Failed checks: 1 warning Passed checks: 4 passedFull details: Docstring Coverage
-
Explanation
Docstring coverage is 11.11% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 9 functions across 5 files.
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
A rabbit checks the gateway’s note,
And keeps its body out of sight.
It waits for sends to find their stop,
Then drains the buffered bits just right.
“All closed,” it says, and hops from view.
Comment @coderabbitai help to get the list of available commands.
Lynn-Inf
left a comment
There was a problem hiding this comment.
LGTM. Three non-blocking notes:
-
The WhatsApp error now carries only the status code, which loses the gateway's explanation for operators debugging a 401/500, and the error path no longer reads the body to EOF, so the transport will not reuse that connection. Keeping the bounded
io.LimitReaderread and logging the (truncated) body at debug level — rather than putting it into the returned error — would preserve both debuggability and keep-alive without re-introducing the tenant-visible leak. -
AsyncIterator.Close()intentionally stops closingch, usingstop/doneinstead, but that is not stated anywhere the next reader will look. Other code in the package still readsit.chdirectly (e.g.model_chain_test.go:275), so a comment onClose()saying the channel is never closed and termination is signalled throughstop/donewould prevent a future caller from waiting on a close that never happens. -
Dropping a
Sendafter close is the intended behaviour, but it leaves no trace if it happens because of a lifecycle bug elsewhere. A debug log on the discarded path (with the iterator/generator identity) would make those cases visible without changing behaviour.
What problem does this PR solve?
WhatsApp runtime errors could expose a tenant-configured gateway's response body through the tenant-readable last_error field. Closing an iterator could also close the shared channel while the runner was still sending or closing it, causing a panic.
Type of change