Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@sunhao1296
Copy link
Contributor

Fix Problem

Concurrent calls to ImmutableResource.Get() could return (nil, nil) when:

  1. Multiple goroutines check resource == nil simultaneously
  2. Only one goroutine passes maybeRefresh check
  3. Other goroutines skip refresh due to time condition

@kevwan kevwan self-assigned this Aug 8, 2025
@kevwan kevwan requested review from Copilot and kevwan August 8, 2025 13:11
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes a concurrency issue in ImmutableResource.Get() where multiple goroutines could receive (nil, nil) results when accessing the resource simultaneously. The fix simplifies the synchronization logic by removing the separate maybeRefresh function and using a single write lock to ensure thread-safe resource initialization.

  • Replaces complex dual-lock pattern with simpler single write lock approach
  • Adds comprehensive concurrent access test to verify the fix
  • Removes unused refreshLock field and maybeRefresh method

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
core/syncx/immutableresource.go Simplifies concurrency control by using single write lock and removing maybeRefresh function
core/syncx/immutableresource_test.go Adds concurrent access test to verify thread safety with 100 goroutines

@codecov
Copy link

codecov bot commented Aug 8, 2025

Codecov Report

❌ Patch coverage is 84.21053% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
core/syncx/immutableresource.go 84.21% 2 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@kevwan kevwan force-pushed the fix_immutable_resource_concurrent_get branch from ea90f4b to a95daf8 Compare August 8, 2025 14:51
@kevwan kevwan merged commit b46d507 into zeromicro:master Aug 8, 2025
5 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants