fix(protocol): fix panic caused by race condition during invoker destruction#3184
fix(protocol): fix panic caused by race condition during invoker destruction#3184HGD-coder wants to merge 5 commits intoapache:developfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #3184 +/- ##
===========================================
+ Coverage 47.80% 47.83% +0.02%
===========================================
Files 460 463 +3
Lines 33011 33726 +715
===========================================
+ Hits 15782 16133 +351
- Misses 15963 16295 +332
- Partials 1266 1298 +32 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
加一下bug发生场景的test case |
|
我觉得这个方法还是太不优雅了,因为上游对于url为nil时候的处理是不一样的,简单粗暴的返回一个空链接我个人觉得不好 只在发生panic的那个上游加一个对于nil的检测可以吗,GetURL这个函数这样改 |
|
你举的这个例子,如果返回一个“empty”不也是一样的结果吗 |
There was a problem hiding this comment.
Pull request overview
Fixes a panic caused by Invoker.GetURL() returning nil during concurrent invoker destruction by introducing a non-nil placeholder URL.
Changes:
- Introduces a package-level
emptyURLplaceholder. - Updates
BaseInvoker.GetURL()to returnemptyURLwhen the internal URL has been cleared. - Updates
BaseInvokertests to assertGetURL()is safe afterDestroy().
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
protocol/base/base_invoker.go |
Adds emptyURL and changes GetURL() to return a non-nil placeholder when destroyed. |
protocol/base/base_invoker_test.go |
Updates assertions to reflect the new non-nil behavior of GetURL() after destroy. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
这个 PR 确实比 #3191 更优雅一些,但是需要更广泛的考虑下其他地方也跟着修改下 |
|
你 LGTM,那就是先把这个 PR 合并,其他受影响的地方后面再提 PR 吗? |








Description
Fixes #3153
1. The Issue (Race Condition)
As described in #3153, a panic (
runtime error: invalid memory address) occurs under high concurrency whenReferenceConfig.Destroy()is triggered:Destroy()setsbi.url = nilto release resources.GetURL()returnnil.nilURL (e.g.,url.GetParam()), causing the panic.2. Solution: Null Object Pattern
This PR introduces a Null Object Pattern to fix the panic safely:
emptyURLinitialized viacommon.NewURLWithOptions.GetURL()to returnemptyURLinstead ofnilwhenbi.urlis destroyed.3. Why we chose this solution (Comparison of Alternatives)
We evaluated three potential solutions. Here is why the Null Object Pattern is the best choice:
Option A: Remove
bi.url = nilin Destroy()use of closed network connectionerrors. It also prevents the URL (and its large Map) from being GC'd, causing potential memory leaks.Option B: Add
if url != nilchecks at every call siteGetURL()is a fundamental method used in 50+ files. Missing just one spot means the panic persists.Option C: Null Object Pattern (This PR)
GetURL()never returns nil.emptyURLreturns empty parameters, so upper layers (like Router) will naturally filter out this destroyed invoker (e.g., matching params fails gracefully).4. Verification
url=nil5. Request for Review
I have verified that this change passes the reproduction script for #3153.
Could reviewers please help check if introducing this
emptyURL(Null Object) might have any unexpected side effects on other modules (e.g., Service Discovery or Metrics)?Checklist
develop