Repository navigation
Closed
Bug
7 / 77 of 7 issues completed
Copy link
Labels
Description
Summary
This issue tracks potential bugs found through static analysis (code review, go vet, pattern matching, and manual verification) of the production code (non-test files) in the cluster, config_center, protocol, registry, common, remoting, and graceful_shutdown packages.
Findings are grouped by severity:
- P0 (7) — can cause process crash (unrecoverable
fatal error), goroutine leaks, or fd exhaustion under normal operation - P1 (10) — high-risk: swallowed errors, unchecked type assertions, missing cancellation
- P2 (7) — robustness / anti-pattern improvements
All line numbers refer to the current develop tip.
🔴 P0 — Must Fix
1. Concurrent map read/write in ZooKeeper CacheListener → fatal crash
- File:
config_center/zookeeper/listener.go:48-91 - Code:
// AddListener listeners, loaded := l.keyListeners.LoadOrStore(key, map[...]struct{}{listener: {}}) if loaded { listeners.(map[...]struct{})[listener] = struct{}{} // writes inner map l.keyListeners.Store(key, listeners) } // DataChange if listeners, ok := l.keyListeners.Load(event.Path); ok { for listener := range listeners.(map[...]struct{}) { ... } // reads inner map }
- Problem:
keyListenersis async.Map, but the stored value is a plainmap.AddListener/RemoveListenermutate the inner map directly whileDataChangemayrangeover the same map concurrently. This triggers Go's built-in concurrent-map detector →fatal error: concurrent map read and map write, which cannot be recovered and kills the process. - Fix: Protect the inner map with its own
sync.RWMutex, or replace with copy-on-write (build a new map andStoreit atomically).
2. Goroutine leak in ForkingClusterInvoker
- File:
cluster/cluster/forking/cluster_invoker.go:74-99 - Problem: A
queue.New(1)(capacity 1) collects results. N fork goroutines each callresultQ.Put(result). The caller does a singleresultQ.Poll(1, timeout)then returns. The remainingN-1fork goroutines block forever onPut(queue full, never drained, never closed) → leaks N-1 goroutines per invocation. - Fix: Use a buffered channel
chan result.Resultwith cap =len(selected); useselect { case ch <- r: default: }for non-blocking send, andcontext-cancel the goroutines on exit.
3. Type-assertion panic in Apollo makeNestedMap
- File:
config_center/apollo/impl.go:211 - Code:
current = current[part].(map[string]any) - Problem: If a config key is both a leaf and a parent (e.g.
a.b=1anda.b.c=2),current[part]is astring, and the assertion panics. Nookcheck. - Fix:
next, ok := current[part].(map[string]any); if !ok { next = make(map[string]any); current[part] = next }; current = next
4. Type-assertion panic in Apollo GetInternalProperty
- File:
config_center/apollo/impl.go:121 - Code:
return value.(string), nil - Problem:
cache.Get(key)returnsinterface{}; a non-string cached value (e.g. a number or nested map) panics on the assertion. - Fix:
s, ok := value.(string); if !ok { return "", perrors.New(...) }
5. File-descriptor leak in cache_manager.loadCache
- File:
registry/servicediscovery/store/cache_manager.go:106-127 - Problem: On decode failure the function
return errbeforecf.Close(), leaking the open file. Only the success path closes it. Missingdefer cf.Close(). - Fix:
cf, err := os.Open(...); if err != nil { return err }; defer cf.Close()
6. File-descriptor leak in accesslog.openLogFile
- File:
filter/accesslog/filter.go:321-349 - Problem: On
Statfailure /Renamefailure / log-rotation paths, the freshlyOpenFile'd*os.Fileis not closed → fd leak that accumulates over long-running services. - Fix: Ensure
defer f.Close()(or close on every error branch) before reassigning the package-level file handle.
7. Goroutine leak in FailbackClusterInvoker.process
- File:
cluster/cluster/failback/cluster_invoker.go:94-121 - Problem:
for range ticker.C { ... }has noselect { case <-ctx.Done(): ... }exit;tickeris neverStop()-ed viadefer. The goroutine only exits whentaskList.Dispose()is called. - Fix: Add
defer ticker.Stop()and acase <-ctx.Done(): returnbranch.
🟡 P1 — High Risk
8. Subscription goroutine has no exit mechanism
- File:
registry/directory/directory.go:205-209 - Code:
go func() { if err := dir.registry.Subscribe(url, dir); err != nil { ... } }() - Problem: No
contextbound to the goroutine lifecycle. IfSubscribeblocks,Destroycannot terminate it → goroutine leak. - Fix: Pass a cancellable
ctx;cancel()onDestroy.
9. Hessian encode errors silently ignored (request)
- File:
protocol/dubbo/hessian2/hessian_request.go:129,151,153,168 - Problem:
_, _ = encoder.Encode(...)discards errors; an encoding failure still sends a truncated frame, causing hard-to-diagnose decode errors on the peer side.
10. Hessian encode errors silently ignored (impl)
- File:
protocol/dubbo/impl/hessian.go:128(and surrounding) - Problem: Same class of issue as go dep #9 in the legacy encoder path.
11. Triple handler registration failure swallowed
- File:
protocol/triple/server.go:546 - Problem:
RegisterHandlerfailure is logged but not propagated; service appears "up" while actually broken.
12. gRPC ReflectResponse error ignored
- File:
protocol/grpc/grpc_invoker.go:128 - Problem: Error from
ReflectResponseis ignored; malformed responses go undetected.
13. Unchecked type assertion (registry protocol)
- File:
registry/protocol/protocol.go:97 - Problem: Type assertion without
ok; wrong config type → panic.
14. Unchecked type assertion (registry directory)
- File:
registry/directory/directory.go:502 - Problem: Type assertion without
okon a value pulled from a map.
15. base_registry retry loop has no ctx exit
- File:
registry/base_registry.go:330 - Problem: Retry loop continues without honoring
contextcancellation → can block shutdown.
16. getty pool time.Sleep ignores cancellation
- File:
remoting/getty/pool.go:81 - Problem:
time.Sleepcannot be interrupted byctx.Done(); connection acquisition may hang during shutdown.
17. MethodMapper chained type assertion panic risk
- File:
common/rpc_service.go:378 - Code:
method.Func.Call(...)[0].Interface().(map[string]string) - Problem: If
MethodMapperreturns a nil interface, the chained assertion can panic.
💭 P2 — Robustness / Anti-pattern
18. Explicit Unlock without defer
- File:
registry/directory/directory.go:771-773 - Problem:
registerLock.Lock(); ...; Unlock()— a panic between leaves the lock permanently held. - Fix:
defer dir.registerLock.Unlock().
19. GetLocalIP error ignored
- File:
common/host_util.go:47 - Problem:
localIp, _ = gxnet.GetLocalIP()— on failurelocalIpis empty, producing an invalid registry address silently.
20. Config validity errors ignored
- File:
remoting/getty/config.go:143,169 - Problem:
defaultClientConfig.CheckValidity()/defaultServerConfig.CheckValidity()results discarded.
21. JSON unmarshal error ignored
- File:
remoting/polaris/parser/parser.go:91 - Problem:
json.Unmarshal(data, &searchVal)error discarded.
22. stopListen error ignored
- File:
config_center/nacos/listener.go:242 - Problem: Returned error from
stopListendiscarded.
23. recover without logging
- File:
graceful_shutdown/shutdown.go:425 - Problem: A
recover()swallows the panic silently, hiding the root cause.
24. Attachment type assertion (accesslog)
- File:
filter/accesslog/filter.go - Problem: Attachment values are type-asserted without
ok; unexpected attachment types panic.
Suggested Next Steps
- Immediate (P0): fix jsonrpc server feature #1–change client.yml & server.yaml registry_config.timeout config unit to time.duration #7. jsonrpc server feature #1 (ZK concurrent map) is the most severe — it can crash the process on any concurrent config push + data change.
- Enablers: enable
errorlint,bodyclose,noctx,nilerrin.golangci.yml(already discussed inCODE_REVIEW.md) to catch P1/P2 systematically. - Tests: add
-racetomake testto surface the goroutine-leak / concurrent-map issues in CI.
Happy to open PRs for any of these if maintainers confirm the preferred fix direction.
Activity
AlexStocks commentedon Jul 28, 2026
go vet verification (2026-07-28)
Ran
GOTOOLCHAIN=local go vet ./...with local Go 1.26.2 on current develop tip (HEAD 53d81d1).Result: EXIT=0, zero warnings.
Coverage note
The default
go vetanalyzers (printf, structtag, copylocks, lostcancel, unreachable, unsafeptr, etc.) did not flag any issue in this thread. This is expected —go vetdoes not cover:bodycloselinter)noctx+ manual review)assertanalyzer, and not these cases)errorlint/nilerr)These are exactly the linters proposed in the enhanced golangci config (
docs/golangci-enhanced.example.yml). Enabling them would surface these issues at PR time and prevent regressions.Note on the earlier run
The first
go vet ./...usedGOTOOLCHAIN=go1.25.0+autoand hung downloading the 1.25.0 toolchain (network). Switching to the locally-installedgo1.26.2(GOTOOLCHAIN=local) completed in seconds via cached build artifacts.XnLemon commentedon Jul 28, 2026
pls assign me to sweep these
AlexStocks commentedon Jul 28, 2026
done
fix(config_center): do not panic when an Apollo key is both a leaf an…
Alanxtl commentedon Oct 31, 2026
done
fix(config_center): do not panic when an Apollo key is both a leaf an…