fix(#3453): resolve concurrency, leak, and panic issues from code audit#3461
Open
HarshMehta112 wants to merge 2 commits into
Open
fix(#3453): resolve concurrency, leak, and panic issues from code audit#3461HarshMehta112 wants to merge 2 commits into
HarshMehta112 wants to merge 2 commits into
Conversation
…erformance issues Signed-off-by: Harsh Mehta <harshmehta010102@gmail.com>
…uster tests Signed-off-by: Harsh Mehta <harshmehta010102@gmail.com>
|
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## develop #3461 +/- ##
===========================================
+ Coverage 53.57% 54.09% +0.52%
===========================================
Files 460 461 +1
Lines 35182 35530 +348
===========================================
+ Hits 18847 19220 +373
+ Misses 14857 14791 -66
- Partials 1478 1519 +41 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Member
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Fixes #3453
Addresses six source-grounded findings around concurrency correctness, memory/goroutine
leaks, and panic-based failure handling. Each fix is narrowly scoped with focused tests.
1. RoundRobin selection now atomic under concurrency
cluster/loadbalance/roundrobin/loadbalance.goThe weighted-round-robin select+update sequence was only per-field atomic, so concurrent
callers could observe each other's intermediate
currentWeightand skew distribution.Added a per-key
sync.MutexoncachedInvokersso the full select+update transaction isserialized per service+method (contention bounded to the same key).
2. Getty server no longer panics on config errors
remoting/getty/getty_server.goReplaced
panic(err)in config marshal/unmarshal,CheckValidity(), andnewSession()with structured error logging / error returns. Added
safeYAMLMarshalto recover thepanic
yaml.v3raises on unmarshalable types (channels, funcs) and surface it as an error.Malformed protocol config no longer escalates to process-level failure.
3. Graceful shutdown result publication hardened
graceful_shutdown/shutdown.goAdded
shutdownResultMuguarding all reads/writes of the package-levelshutdownResult,removing reliance on subtle ordering assumptions between the background shutdown goroutine
and concurrent
Shutdown()readers.4. TPS limiter cache is now bounded
filter/tps/limiter/method_service.goThe limiter map grew for process lifetime as distinct service+method combos accumulated.
Wrapped each strategy in a
tpsLimitEntrytracking last-access time, switched tosync.Map,and added a singleton background
runCleanupgoroutine that evicts entries idle past a TTL.5. Script-router JS runtime no longer leaks cross-request state
cluster/router/script/instance/js_instance.goPooled
goja.Runtimeinstances were never returned to the pool, and request/script globalssurvived reuse. Added
defer reset()+Put()inRun().reset()snapshots the built-inglobal keys at construction and deletes every global outside that set — clearing both request
bindings and user-script-defined globals while preserving built-ins.
6. Forking cluster cancels losing parallel branches
cluster/cluster/forking/cluster_invoker.goLosing parallel invocations ran to completion after the winner returned, wasting downstream
work. Derived a cancelable
forkCtx;defer cancel()stops sibling requests as soon as thefirst accepted result wins.
Tests
TestRoundRobinByWeightConcurrent— 50 goroutines × 30 selections, race-cleanTestInitServerDoesNotPanicOnUnmarshalableParams— channel in Params no longer panicsTestShutdownResultConsistentUnderConcurrentReaders,TestShutdownPanicSetsResultErrorTestTpsLimitEntryUpdatesLastAccess,TestTpsLimiterStaleEntryEvictionTestJsInstanceResetClearsBindings(incl. user-defined global),TestJsInstanceRunReturnsRuntimeToPoolTestForkingInvokeCancelsLosingBranches— loser branch ctx canceled after winner succeedsAll 74 tests across the 6 packages pass;
go vetandgofmtclean.Scope
Covers audit items 1–6 only. Item 7 (broader panic/fatal policy audit) is left for follow-up
PRs per the issue's suggested slicing. Items A/B/C are already fixed upstream.
Checklist
develop