Skip to content

fix(udpserver): data race on a session record's stream cleanup between duplicate SESSION_INITs - #214

Merged
masterking32 merged 1 commit into
masterking32:mainfrom
BoofKoor:fix/server-duplicate-session-init-race
Nov 2, 2026
Merged

masterking32 merged 1 commit into
masterking32:mainfrom
BoofKoor:fix/server-duplicate-session-init-race

Conversation

@BoofKoor

@BoofKoor BoofKoor commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

handleSessionInitRequest set record.streamCleanup after findOrCreate had returned the record and released the session store's lock. A client races identical SESSION_INIT queries and resolvers retry them, so several DNS workers handle duplicates of one session init at once and get the same record: they write the field concurrently, and a duplicate that arrives later (a record is reused for SESSION_INIT_REUSE_TTL_SECONDS) writes it while onStreamClosed reads it as the session's streams close. go test -race reports the conflicting writes.

Keep the cleanup on the session store, set by New before the server runs, and copy it into each record as findOrCreate creates it, so a record's streamCleanup is never written afterwards.

Found with go test -race while running the client's session start against several resolvers.

Claude-Session: https://claude.ai/code/session_01EE5jVdfYhhc4swGjwfyXGW

handleSessionInitRequest set record.streamCleanup after findOrCreate had
returned the record and released the session store's lock. A client races
identical SESSION_INIT queries and resolvers retry them, so several DNS
workers handle duplicates of one session init at once and get the same
record: they write the field concurrently, and a duplicate that arrives
later (a record is reused for SESSION_INIT_REUSE_TTL_SECONDS) writes it
while onStreamClosed reads it as the session's streams close.
go test -race reports the conflicting writes.

Keep the cleanup on the session store, set by New before the server runs,
and copy it into each record as findOrCreate creates it, so a record's
streamCleanup is never written afterwards.

Found with go test -race while running the client's session start against
several resolvers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EE5jVdfYhhc4swGjwfyXGW
@masterking32
masterking32 merged commit cfb18fa into masterking32:main Nov 2, 2026
1 check 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.

3 participants