fix(web): close unary Zoekt gRPC clients - #1591
Conversation
This comment has been minimized.
This comment has been minimized.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
Included review availability: Your plan provides up to 8 included reviews per hour; 6 remain after this review. Walkthrough
ChangesZoekt search cleanup
Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: ⚪ Minimal · up to This localized change closes unary search clients across success and failure paths with regression coverage; no actionable merge-blocking risk remains beyond normal checks and review. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Summary
Finding
zoektSearch created a new grpc-js WebserverService client for every unary request but never closed it. grpc-js registers each InternalChannel in its process-global channelz registry and only unregisters it when Client.close() runs, so dropping JavaScript references does not make those channels collectible.
With the repository pinned grpc-js 1.14.4, a forced-GC reproduction created and dropped 20,000 clients. Channelz still reported all 20,000 channels afterward; retained V8 heap grew by 36,170,288 bytes (about 1.81 KiB per call) and RSS grew by 318 MiB. This path is used by unary search, code navigation, and search-backed tools. Live counters show it is not the dominant source of the current browse-crawler incident, but it is a concrete traffic-proportional leak.
Remediation
The unary call and response transformation now run inside try/finally, and the client is closed in finally. This guarantees channelz cleanup after a successful response, an RPC error, a synchronous call failure, or a later database/response transformation error.
Test plan
Note
Medium Risk
Touches the unary Zoekt search path used by search, code nav, and tools. The change is small and covered by tests, but incorrect client teardown could leak or fail searches.
Overview
Stops unary Zoekt searches from leaking a grpc-js channel on every request.
zoektSearchnow awaits the RPC and response transform intry/finallyand always callsclient.close().Streaming search already closed clients; this only fixes the unary path. Tests cover success, RPC failure, and post-response transform failure. Changelog notes the leak fix.
Reviewed by Cursor Bugbot for commit b7868ec. Bugbot is set up for automated code reviews on this repo. Configure here.
Summary by CodeRabbit
Bug Fixes
Documentation
Tests