You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by "mochengqian (via GitHub)" <gi...@apache.org> on 2026/04/26 13:00:51 UTC
[PR] fix(triple): make protocol initialization and invoker tracking race-safe [dubbo-go]
mochengqian opened a new pull request, #3307:
URL: https://github.com/apache/dubbo-go/pull/3307
### Description
Fixes #3304.
This PR removes data races in the Triple protocol initialization path and the shared `BaseProtocol` invoker tracking path.
## Why
When Triple clients/services are created concurrently, `go test -race` can report races in two places:
1. `triple.GetProtocol()` lazily initializes the global Triple protocol singleton without synchronization.
2. `BaseProtocol.SetInvokers()` appends to the shared invoker slice while other goroutines may read or destroy the same slice.
The second issue is not only a race detector warning. Concurrent appends can also lose invoker references, which can affect lifecycle cleanup.
## How
- Protect Triple protocol singleton initialization with `sync.Once`.
- Add an internal `RWMutex` for `BaseProtocol` invoker list access.
- Make `Invokers()` return a snapshot instead of exposing the internal slice.
- Make `Destroy()` snapshot and clear invokers under lock, then destroy invokers outside the lock.
- Add race regression tests for concurrent Triple protocol initialization and concurrent BaseProtocol invoker access.
- Fix the Triple health-watch test helper to avoid unsynchronized test-only slice access, so package-level race verification stays clean.
## Compatibility
This PR does not change Triple RPC semantics, method lookup behavior, retry/timeout/error propagation, serialization, or public protocol contracts.
The only intentional behavior tightening is that `Invokers()` now returns a snapshot instead of the internal slice, preventing external callers from mutating shared protocol state.
## Tests
go test -race ./protocol/base -count=1
go test -race ./protocol/triple -count=1
go test ./protocol/base ./protocol/triple -count=1
go test ./protocol/dubbo ./protocol/dubbo3 ./protocol/grpc ./protocol/jsonrpc ./protocol/rest -count=1
go test ./server -run TestTripleCaseInsensitiveRoute -count=1
go vet ./protocol/base ./protocol/triple
git diff --check
### Checklist
- [ ] I confirm the target branch is `develop`
- [ ] Code has passed local testing
- [ ] 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: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] fix(triple): make protocol initialization and invoker tracking race-safe [dubbo-go]
Posted by "Alanxtl (via GitHub)" <gi...@apache.org>.
Alanxtl commented on code in PR #3307:
URL: https://github.com/apache/dubbo-go/pull/3307#discussion_r3144718533
##########
protocol/base/base_protocol.go:
##########
@@ -87,13 +97,19 @@ func (bp *BaseProtocol) Refer(url *common.URL) Invoker {
// Destroy will destroy all invoker and exporter, so it only is called once.
func (bp *BaseProtocol) Destroy() {
+ // Do not hold invokersLock while calling Invoker.Destroy(); implementations may run protocol callbacks.
+ bp.invokersLock.Lock()
+ invokers := make([]Invoker, len(bp.invokers))
+ copy(invokers, bp.invokers)
+ bp.invokers = nil
Review Comment:
这里为什么是置为nil而不是[]Invoker{}
--
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: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] fix(triple): make protocol initialization and invoker tracking race-safe [dubbo-go]
Posted by "AlexStocks (via GitHub)" <gi...@apache.org>.
AlexStocks merged PR #3307:
URL: https://github.com/apache/dubbo-go/pull/3307
--
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: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] fix(triple): make protocol initialization and invoker tracking race-safe [dubbo-go]
Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #3307:
URL: https://github.com/apache/dubbo-go/pull/3307#issuecomment-4322092205
## [Codecov](https://app.codecov.io/gh/apache/dubbo-go/pull/3307?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
:white_check_mark: All modified and coverable lines are covered by tests.
:white_check_mark: Project coverage is 51.20%. Comparing base ([`ea93b8a`](https://app.codecov.io/gh/apache/dubbo-go/commit/ea93b8a9e1c0a9b8b05e786d955ab4f8aeaa221d?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`36cb792`](https://app.codecov.io/gh/apache/dubbo-go/commit/36cb7924e56c523620f182a0a92de3ad14b70e74?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
<details><summary>Additional details and impacted files</summary>
```diff
@@ Coverage Diff @@
## main #3307 +/- ##
==========================================
+ Coverage 50.79% 51.20% +0.41%
==========================================
Files 488 488
Lines 44203 36575 -7628
==========================================
- Hits 22451 18729 -3722
+ Misses 20242 16334 -3908
- Partials 1510 1512 +2
```
</details>
[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/apache/dubbo-go/pull/3307?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
<details><summary> :rocket: New features to boost your workflow: </summary>
- :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
</details>
--
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: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] fix(triple): make protocol initialization and invoker tracking race-safe [dubbo-go]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #3307:
URL: https://github.com/apache/dubbo-go/pull/3307#issuecomment-4322082403
## [](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=3307) **Quality Gate passed**
Issues
 [0 New issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=3307&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=3307&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_dubbo-go&pullRequest=3307&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=3307&metric=new_coverage&view=list)
 [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=3307&metric=new_duplicated_lines_density&view=list)
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=3307)
--
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: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] fix(triple): make protocol initialization and invoker tracking race-safe [dubbo-go]
Posted by "mochengqian (via GitHub)" <gi...@apache.org>.
mochengqian commented on code in PR #3307:
URL: https://github.com/apache/dubbo-go/pull/3307#discussion_r3145376645
##########
protocol/base/base_protocol.go:
##########
@@ -87,13 +97,19 @@ func (bp *BaseProtocol) Refer(url *common.URL) Invoker {
// Destroy will destroy all invoker and exporter, so it only is called once.
func (bp *BaseProtocol) Destroy() {
+ // Do not hold invokersLock while calling Invoker.Destroy(); implementations may run protocol callbacks.
+ bp.invokersLock.Lock()
+ invokers := make([]Invoker, len(bp.invokers))
+ copy(invokers, bp.invokers)
+ bp.invokers = nil
Review Comment:
Good catch! nil 和 []Invoker{} 对当前核心行为几乎等价:len == 0、range 安全、后续 append 都正常,仔细想了想确实是不必要修改.我将把 nil 还原回 []Invoker{}.
--
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: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] fix(triple): make protocol initialization and invoker tracking race-safe [dubbo-go]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #3307:
URL: https://github.com/apache/dubbo-go/pull/3307#issuecomment-4324883175
## [](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=3307) **Quality Gate passed**
Issues
 [0 New issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=3307&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=3307&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_dubbo-go&pullRequest=3307&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=3307&metric=new_coverage&view=list)
 [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=3307&metric=new_duplicated_lines_density&view=list)
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=3307)
--
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: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org