This repository was archived by the owner on Aug 18, 2026. It is now read-only.
Repository navigation
fix: race condition in GameServersQueue.PushToQueue causing nil pointer dereference - #506
Closed
Dimitris Gkanatsios (dgkanatsios) with Copilot wants to merge 4 commits into
Closed
Dimitris Gkanatsios (dgkanatsios) with Copilot wants to merge 4 commits into
Dimitris Gkanatsios (dgkanatsios) with Copilot wants to merge 4 commits into
Conversation
…rtbeat, queue, and controllers Co-authored-by: dgkanatsios <8256138+dgkanatsios@users.noreply.github.com> Agent-Logs-Url: https://github.com/PlayFab/thundernetes/sessions/29971878-6148-47a4-a4e9-689bafb2ef6e
…chmark robustness Co-authored-by: dgkanatsios <8256138+dgkanatsios@users.noreply.github.com> Agent-Logs-Url: https://github.com/PlayFab/thundernetes/sessions/29971878-6148-47a4-a4e9-689bafb2ef6e
…er dereference PushToQueue used a split RLock/Lock pattern: it checked if a build entry existed under RLock, released it, then acquired Lock to use the entry. Between the RUnlock and the Lock, a concurrent PopFromQueue could delete the build entry (when the last GameServer was popped), causing a nil pointer dereference on the next access. Fix: hold a single write lock for the entire PushToQueue operation, eliminating the TOCTOU race window. Added a regression test (TestGameServerQueueConcurrentPushPopSameBuild) that exercises concurrent push/pop on the same build ID, which would consistently panic before this fix. Updated the benchmark to use a shared build ID instead of per-goroutine IDs, proving the race is resolved. Co-authored-by: dgkanatsios <8256138+dgkanatsios@users.noreply.github.com> Agent-Logs-Url: https://github.com/PlayFab/thundernetes/sessions/9c73c26e-828a-4b5f-89db-5e79167f2115
Dimitris Gkanatsios (dgkanatsios)
marked this pull request as ready for review
March 24, 2026 03:28
Collaborator
Copilot started work on behalf of
Dimitris Gkanatsios (dgkanatsios)
March 24, 2026 03:30
View session
Contributor
Author
Confirmed — PR #505 includes the exact same fix for Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes a TOCTOU (time-of-check-time-of-use) race condition in
GameServersQueue.PushToQueuethat could cause a nil pointer dereference under concurrent access.The Bug
PushToQueueused a split RLock/Lock pattern:Between steps 2 and 3, a concurrent
PopFromQueuecould pop the last GameServer for a build and delete the build's entry from the map. WhenPushToQueuethen proceeds to accessgsq.queuesPerBuilds[gs.BuildID], it getsnil→ panic.The Fix
Hold a single write lock for the entire
PushToQueueoperation, eliminating the TOCTOU race window. SincePushToQueuealways writes to the map (at minimumnamespacedNameToBuildId), a write lock was needed anyway, so there's no real performance penalty.Changes
gameserverqueue.goPushToQueuestress_test.goTestGameServerQueueConcurrentPushPopSameBuild— regression test with concurrent push/pop on the same build ID (10 runs × 1000 iterations each)gameserverqueue_benchmark_test.goTesting
All tests pass with
-race:CodeQL: 0 security alerts.