Skip to content

fix(eth/peer/wit): concurrent data read/write cases#1742

Merged
kamuikatsurgi merged 1 commit intodevelopfrom
kamui/data-race-fixes
Sep 2, 2025
Merged

fix(eth/peer/wit): concurrent data read/write cases#1742
kamuikatsurgi merged 1 commit intodevelopfrom
kamui/data-race-fixes

Conversation

@kamuikatsurgi
Copy link
Copy Markdown
Member

@kamuikatsurgi kamuikatsurgi commented Sep 1, 2025

Fixes #1729 and #1736

Description

Issue in #1729:

The original code had a data race between:

  • READ: where we read witReqs to create wrapperReq := &ethWitRequest{Request: ethReqShim, witReqs: witReqs}.
  • WRITE: where doWitnessRequest() does *witReqs = append(*witReqs, witReq)

The race occurred because buildWitnessRequests was called asynchronously in a goroutine, allowing the main goroutine to read witReqs while the background goroutine was still populating it via append operations.

By calling buildWitnessRequests synchronously, we ensure all initial witness requests are built and appended to witReqs BEFORE the main goroutine reads the slice, eliminating the possibility of concurrent read/write access.

Issue in #1736:

The original code had a data race between:

  • READ: where we read announce.time for logging/timestamping
  • WRITE: handleWitnessFetchFailureExt() where it does state.announce.time = time.Now().Add(fetchTimeout)

The race occurred because this read was unprotected while handleWitnessFetchFailureExt() was writing to the same announce.time field under mutex protection. Both operations access the same memory location but with different synchronisation. By protecting this read with the same mutex used by the writer, we ensure synchronised access to announce. time, eliminating the data race.

@kamuikatsurgi kamuikatsurgi mentioned this pull request Sep 1, 2025
@kamuikatsurgi kamuikatsurgi requested review from cffls and lucca30 and removed request for lucca30 September 1, 2025 18:16
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Sep 1, 2025

Quality Gate Failed Quality Gate failed

Failed conditions
B Maintainability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

Copy link
Copy Markdown
Contributor

@lucca30 lucca30 left a comment

Choose a reason for hiding this comment

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

lgtm!

@kamuikatsurgi kamuikatsurgi merged commit 72d0e83 into develop Sep 2, 2025
11 of 12 checks passed
@kamuikatsurgi kamuikatsurgi deleted the kamui/data-race-fixes branch September 2, 2025 15:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants