Skip to content

Fix network game race condition from event batching#9911

Merged
tool4ever merged 1 commit intoCard-Forge:masterfrom
MostCromulent:fix/network-race-condition
Feb 27, 2026
Merged

Fix network game race condition from event batching#9911
tool4ever merged 1 commit intoCard-Forge:masterfrom
MostCromulent:fix/network-race-condition

Conversation

@MostCromulent
Copy link
Copy Markdown
Contributor

@tool4ever


The batching commit (742c7ba) introduced a race condition for network games. Events were queued and flushed on the Swing EDT, leaving the game thread free to modify FCollection/EnumMap objects while Netty serialized them on the I/O thread -causing ArrayIndexOutOfBoundsException in EnumMap.writeObject().

This fix flushes events on the game thread instead of EDT, so the game thread blocks during serialization. Batching is preserved via time (50ms) and size (50 event) thresholds. A pre-send flush in NetGuiGame guarantees events reach the client before any interactive prompt.

3 files changed, no engine modifications.

Tested in local network play (host + remote client) - previously had repeated ArrayIndexOutOfBoundsException during serialization, now no errors following fix.


🤖 Generated with Claude Code

Flush game events on the game thread instead of EDT so the game thread
blocks during Netty serialization, preventing concurrent modification
of FCollection/EnumMap objects that caused ArrayIndexOutOfBoundsException.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
MostCromulent added a commit to MostCromulent/forge that referenced this pull request Feb 27, 2026
- Make convertToAI public so the test calls the production method
  instead of reimplementing its logic inline (fixes clear-then-swap
  ordering bug — production correctly does swap-then-clear)
- Move UPnP preference into FModel.initialize callback alongside
  other test preferences, removing manual save/restore
- Remove dead code: findHumanController helper, 7 unused imports

Test passes with 0 send errors when Card-Forge#9911 fix is applied.
Without Card-Forge#9911, fails with 47 send errors (expected — known race).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@tool4ever tool4ever merged commit a5b7dcf into Card-Forge:master Feb 27, 2026
2 checks passed
MostCromulent added a commit to MostCromulent/forge that referenced this pull request Feb 28, 2026
Incorporates upstream event batching race condition fix (Card-Forge#9911),
CI network integration test (Card-Forge#9935), and adopt real EDT threading
for headless test infrastructure.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@MostCromulent MostCromulent deleted the fix/network-race-condition branch March 1, 2026 20:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants