HarshMehta112 opened a new pull request, #3461:
URL: https://github.com/apache/dubbo-go/pull/3461
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.go`
The weighted-round-robin select+update sequence was only per-field atomic,
so concurrent
callers could observe each other's intermediate `currentWeight` and skew
distribution.
Added a per-key `sync.Mutex` on `cachedInvokers` so the full select+update
transaction is
serialized per service+method (contention bounded to the same key).
#### 2. Getty server no longer panics on config errors
`remoting/getty/getty_server.go`
Replaced `panic(err)` in config marshal/unmarshal, `CheckValidity()`, and
`newSession()`
with structured error logging / error returns. Added `safeYAMLMarshal` to
recover the
panic `yaml.v3` raises 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.go`
Added `shutdownResultMu` guarding all reads/writes of the package-level
`shutdownResult`,
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.go`
The limiter map grew for process lifetime as distinct service+method
combos accumulated.
Wrapped each strategy in a `tpsLimitEntry` tracking last-access time,
switched to `sync.Map`,
and added a singleton background `runCleanup` goroutine that evicts
entries idle past a TTL.
#### 5. Script-router JS runtime no longer leaks cross-request state
`cluster/router/script/instance/js_instance.go`
Pooled `goja.Runtime` instances were never returned to the pool, and
request/script globals
survived reuse. Added `defer reset()+Put()` in `Run()`. `reset()`
snapshots the built-in
global 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.go`
Losing parallel invocations ran to completion after the winner returned,
wasting downstream
work. Derived a cancelable `forkCtx`; `defer cancel()` stops sibling
requests as soon as the
first accepted result wins.
### Tests
- `TestRoundRobinByWeightConcurrent` — 50 goroutines × 30 selections,
race-clean
- `TestInitServerDoesNotPanicOnUnmarshalableParams` — channel in Params no
longer panics
- `TestShutdownResultConsistentUnderConcurrentReaders`,
`TestShutdownPanicSetsResultError`
- `TestTpsLimitEntryUpdatesLastAccess`, `TestTpsLimiterStaleEntryEviction`
- `TestJsInstanceResetClearsBindings` (incl. user-defined global),
`TestJsInstanceRunReturnsRuntimeToPool`
- `TestForkingInvokeCancelsLosingBranches` — loser branch ctx canceled
after winner succeeds
All 74 tests across the 6 packages pass; `go vet` and `gofmt` clean.
### 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
- [x] I confirm the target branch is `develop`
- [x] Code has passed local testing
- [x] I have added tests that prove my fix is effective or that my feature
works
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]