fix: dedicated server thread safety, disconnect deadlock, and console freeze

- Protect PlayerList and ServerConnection players vectors with critical
  sections; all iterations use copy-on-read snapshots to prevent iterator
  invalidation during concurrent join/leave
- Add null check on player bounding box in movement validation to prevent
  crash when player is removed mid-tick
- Re-validate socket player pointer immediately before SendData to narrow
  the TOCTOU race window on disconnect
- Replace inline disconnect cleanup with a queued system drained on the
  main tick thread, eliminating the done_cs -> m_playersCS lock inversion
  that caused deadlocks under load
- Disable Windows QuickEdit mode at server startup to prevent console
  input selection from freezing the process
- Move chunk priority sort behind ServerConnection::sortPlayersByChunkPriority()
  to keep the players vector lock-protected
This commit is contained in:
itsRevela
2026-04-10 01:12:59 -05:00
parent 055bce517d
commit 20229fc07b
9 changed files with 309 additions and 158 deletions
+3
View File
@@ -20,6 +20,7 @@ private:
int connectionCounter;
private:
CRITICAL_SECTION pending_cs; // 4J added
CRITICAL_SECTION players_cs; // Protects players vector for concurrent access
vector< shared_ptr<PendingConnection> > pending;
vector< shared_ptr<PlayerConnection> > players;
@@ -47,4 +48,6 @@ public:
void handleTextureAndGeometryReceived(const wstring &textureName);
void handleServerSettingsChanged(shared_ptr<ServerSettingsChangedPacket> packet);
vector< shared_ptr<PlayerConnection> > *getPlayers();
vector< shared_ptr<PlayerConnection> > getPlayersSnapshot();
void sortPlayersByChunkPriority();
};