adds missing cancel() to integration router - #3541
Conversation
|
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughSummary by CodeRabbit
WalkthroughThis change consolidates cancellation lifetime management in ChangesCentralized cancellation cleanup in request handler
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 golangci-lint (2.12.2)level=error msg="[linters_context] typechecking error: pattern ./...: directory prefix . does not contain main module or its selected dependencies" Comment |
Confidence Score: 4/5Safe to merge; the consolidation is correct and fixes real resource leaks. The one remaining gap (no cancel on normal stream completion) is a pre-existing design choice and not introduced here. The centralized defer correctly covers all non-streaming return paths, including the previously unguarded PreCallback error return. The streamingOwnsCancel ownership transfer is clean and matches how handleStreamingRequest already manages cancel() internally. The only open question is whether cancel() should also be called at the end of a fully-successful stream — the current code intentionally omits it, relying on Bifrost's internal cleanup, but the CancelFunc is still technically leaked for the lifetime of the parent context. transports/bifrost-http/integrations/router.go — specifically the producer goroutine in handleStreaming which never calls cancel() on the happy path. Important Files Changed
|
Merge activity
|
## Summary Consolidates context cancellation in `createHandler` into a single `defer` at the top of the handler lambda, eliminating scattered and inconsistent `cancel()` / `defer cancel()` calls throughout the function. A `streamingOwnsCancel` flag is introduced to transfer cancel ownership to the streaming path, whose producer goroutine outlives the handler lambda and is responsible for calling `cancel` itself. ## Changes - Replaced all individual `cancel()` and `defer cancel()` calls across every early-return branch with a single `defer` guarded by a `streamingOwnsCancel` boolean. - When the request is determined to be streaming, `streamingOwnsCancel` is set to `true` before calling `handleStreamingRequest`, so the deferred cleanup is skipped and ownership is passed to the streaming goroutine. - All non-streaming and error paths continue to have `cancel` called correctly via the centralized defer without any change in behavior. ## Type of change - [ ] Bug fix - [ ] Feature - [x] Refactor - [ ] Documentation - [ ] Chore/CI ## Affected areas - [ ] Core (Go) - [x] Transports (HTTP) - [ ] Providers/Integrations - [ ] Plugins - [ ] UI (React) - [ ] Docs ## How to test ```sh go test ./transports/bifrost-http/... ``` Verify that streaming responses complete without context cancellation errors, and that non-streaming and error paths do not leak contexts. ## Screenshots/Recordings N/A ## Breaking changes - [ ] Yes - [x] No ## Related issues N/A ## Security considerations No security implications. This change only affects context lifecycle management within the HTTP handler. ## Checklist - [ ] I read `docs/contributing/README.md` and followed the guidelines - [ ] I added/updated tests where appropriate - [ ] I updated documentation where needed - [ ] I verified builds succeed (Go and UI) - [ ] I verified the CI pipeline passes locally if applicable

Summary
Consolidates context cancellation in
createHandlerinto a singledeferat the top of the handler lambda, eliminating scattered and inconsistentcancel()/defer cancel()calls throughout the function. AstreamingOwnsCancelflag is introduced to transfer cancel ownership to the streaming path, whose producer goroutine outlives the handler lambda and is responsible for callingcancelitself.Changes
cancel()anddefer cancel()calls across every early-return branch with a singledeferguarded by astreamingOwnsCancelboolean.streamingOwnsCancelis set totruebefore callinghandleStreamingRequest, so the deferred cleanup is skipped and ownership is passed to the streaming goroutine.cancelcalled correctly via the centralized defer without any change in behavior.Type of change
Affected areas
How to test
go test ./transports/bifrost-http/...Verify that streaming responses complete without context cancellation errors, and that non-streaming and error paths do not leak contexts.
Screenshots/Recordings
N/A
Breaking changes
Related issues
N/A
Security considerations
No security implications. This change only affects context lifecycle management within the HTTP handler.
Checklist
docs/contributing/README.mdand followed the guidelines