Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
ef8cee4
feat(metadata): add internal RWMutex for MetadataInfo and fix json se…
jieguo-coder Jun 3, 2026
605d0b2
feat(metadata): add lock protection for global registry and instances…
jieguo-coder Jun 3, 2026
abf50a7
feat(metadata): fix concurrency safety in listener callbacks and exte…
jieguo-coder Jun 3, 2026
8bc0aaa
style: format import blocks using dubbo-go imports-formatter
jieguo-coder Jun 3, 2026
ea83f92
style: format metadata.go and report_instance.go to pass CI
jieguo-coder Jun 3, 2026
0048c16
fix(metadata): resolve data races pointed out in code review
jieguo-coder Jun 4, 2026
e65f694
test: fix failing tests and improve unit test coverage
jieguo-coder Jun 4, 2026
a7bad03
test: fix testifylint error by avoiding require in goroutines
jieguo-coder Jun 4, 2026
3cf2c5a
fix(metadata): deep copy ServiceInfo to prevent write-on-read data ra…
jieguo-coder Jun 7, 2026
9bf63a0
chore: trigger CI re-run for codecov gpg issue
jieguo-coder Jun 7, 2026
21cedcc
chore: resolve merge conflicts with develop and fix code formatting
jieguo-coder Jun 7, 2026
1bd679e
refactor(metadata): implement no-lock helper to fix data race and avo…
jieguo-coder Jun 11, 2026
c77d53a
chore: resolve merge conflict with #3369, integrating deterministic f…
jieguo-coder Jun 11, 2026
f8d3248
test: fix compilation error in instance changed listener tests by add…
jieguo-coder Jun 11, 2026
d3f571d
fix(metadata): add RLock around global map lookup in RemoveService an…
jieguo-coder Jun 13, 2026
3bf11e4
chore: resolve merge conflicts with #3370, keeping DeepCopy for concu…
jieguo-coder Jun 13, 2026
11cc932
chore: resolve test file conflict by keeping both listener and cache …
jieguo-coder Jun 13, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor(metadata): implement no-lock helper to fix data race and avo…
…id deadlocks in ReplaceExportedServices

Signed-off-by: jieguo-coder <1193249232@qq.com>
  • Loading branch information
jieguo-coder committed Jun 11, 2026
commit 1bd679e52bf944d44e7e0a4686ee80e08a95a692
11 changes: 10 additions & 1 deletion metadata/info/metadata_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ func (info *MetadataInfo) AddService(url *common.URL) {
info.mu.Lock()
defer info.mu.Unlock()

info.addServiceWithoutLock(url)
}

// addServiceWithoutLock adds a service URL without acquiring the lock.
// The caller must hold info.mu.Lock() before calling this method.
func (info *MetadataInfo) addServiceWithoutLock(url *common.URL) {
service := NewServiceInfoWithURL(url)
info.Services[service.GetMatchKey()] = service
addUrl(info.exportedServiceURLs, url)
Expand Down Expand Up @@ -200,10 +206,13 @@ func (info *MetadataInfo) GetServices() map[string]*ServiceInfo {
}

func (info *MetadataInfo) ReplaceExportedServices(urls []*common.URL) {
info.mu.Lock()
defer info.mu.Unlock()

info.Services = make(map[string]*ServiceInfo)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] 这里仍然绕过 MetadataInfo.mu 直接重置 Services 和 exportedServiceURLs。本 PR 已经让 AddService、RemoveService、GetServices、GetExportedServiceURLs 通过同一个 mutex 保护这些字段,但 ReplaceExportedServices 由 service_discovery_registry.go 调用时会无锁写 map;如果同时有 metadata 读取或实例变更处理在调用 GetServices/GetExportedServiceURLs,仍然可能触发 data race 或读到半重建状态。这里需要在函数入口持有写锁,并避免在持锁后直接调用会再次加锁的 AddService,可以拆出一个内部 no-lock helper 来复用写入逻辑。

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

好的,我现在使用了内部无锁辅助模式重构逻辑,并提取 addServiceWithoutLock 来处理核心映射更新。现在,ReplaceExportedServices 在入口获取 info.mu.Lock() 一次,并在循环中安全地重用辅助函数。

info.exportedServiceURLs = make(map[string][]*common.URL)
for _, serviceURL := range urls {
info.AddService(serviceURL)
info.addServiceWithoutLock(serviceURL)
}
}

Expand Down