Skip to content

Server: read a client's title under the server lock - #168

Merged
undecuple merged 2 commits into
mainfrom
fork-commid-race
Nov 13, 2026
Merged

undecuple merged 2 commits into
mainfrom
fork-commid-race

Conversation

@undecuple

Copy link
Copy Markdown
Owner

Why

When a new connection says HELLO with the name and address of an existing player (a title that restarted), the server clears the old connection's title (commID) under the server lock and closes it. The old connection's own goroutine checks commID at the start of every request without taking that lock. If a request arrives in that window, the two accesses are unsynchronized, and go test -race reports a data race.

Change

  • server/server.go: handle reads commID under s.mu. Nothing else changes; the takeover and its replies are as before.
  • server/commid_race_test.go: 400 rounds of a takeover while the old connection keeps sending a request. It is meant to run under -race, as CI does.
  • CHANGELOG Server: entry; the generated site files are regenerated.

Tests

  • go test -race ./server passes, and the new test passed 3 of 3 runs.
  • Without the server.go change the new test fails under -race in 5 of 5 runs (WARNING: DATA RACE, write in hello, read in handle).
  • gofmt, go vet, python3 tools/features.py, python3 tools/site.py, python3 tools/repo_check.py and scripts/check-deploy.sh pass.

Evidence

Before the change the race detector reported the write at hello (o.commID = "") against the read at the top of handle, in about one of 400 takeover rounds.

Not in this change

The name-takeover rules are unchanged.

Overlap

None open on server/server.go except #164 (the per-address key, a different function). Touches CHANGELOG.md, site/index.html and site/data.json, which other open PRs also change.

Developed with AI agent assistance.

@undecuple
undecuple merged commit 24b212f into main Nov 13, 2026
10 checks passed
@undecuple
undecuple deleted the fork-commid-race branch November 13, 2026 04:34
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