Skip to content

fix: eliminate data race in maelstrom message parsing#918

Merged
mattisonchao merged 1 commit intomainfrom
fix/maelstrom-message-parsing-data-race
Feb 27, 2026
Merged

fix: eliminate data race in maelstrom message parsing#918
mattisonchao merged 1 commit intomainfrom
fix/maelstrom-message-parsing-data-race

Conversation

@mattisonchao
Copy link
Copy Markdown
Member

@mattisonchao mattisonchao commented Feb 26, 2026

Summary

  • parseRequest() deserialized messages into singleton struct pointers stored in jsonMsgMapping/protoMsgMapping
  • Since message handlers run as goroutines (dispatcher.go:136), the next incoming message would overwrite the singleton while the previous goroutine was still reading from it
  • This caused the Maelstrom lin-kv linearizability test to fail: a CAS(from=1, to=0) succeeded because its goroutine read From=1 from a singleton that had been overwritten by a later message, when the actual register value was 3
  • Use reflect.New() to create a fresh instance from each prototype on every parse, so each goroutine gets its own isolated copy

Test plan

  • Maelstrom lin-kv test passes in CI

parseRequest() deserialized messages into singleton struct pointers
stored in jsonMsgMapping/protoMsgMapping. Since message handlers run
as goroutines (dispatcher.go:136), the next incoming message would
overwrite the singleton while the previous goroutine was still reading
from it, causing linearizability violations in the Maelstrom lin-kv test.

Use reflect.New() to create a fresh instance from each prototype on
every parse, so each goroutine gets its own isolated copy.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@mattisonchao mattisonchao self-assigned this Feb 27, 2026
@mattisonchao mattisonchao merged commit 6f21677 into main Feb 27, 2026
13 of 15 checks passed
@mattisonchao mattisonchao deleted the fix/maelstrom-message-parsing-data-race branch February 27, 2026 02:18
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.

1 participant