agatho and Claude Opus 4.5
2bdad4f24e
fix(spawner): P1 - Fix DespawnAllBots iterator race with atomic swap
...
**Problem:**
Range-based for loop over TBB concurrent_hash_map in DespawnAllBots() was NOT
atomic. Other threads could modify _activeBots during iteration, causing:
- Iterator invalidation
- Missing bots (removed during iteration)
- Seeing bots twice (if rehash happens)
- Potential crashes from concurrent modification
**Root Cause:**
```cpp
// UNSAFE - NOT atomic, race condition window
for (auto const& [guid, zoneId] : _activeBots) {
botsToRemove.push_back(guid);
}
```
While iterating, other threads could call SpawnBot/DespawnBot, modifying the
underlying hash table structure.
**Solution:**
Implemented atomic swap pattern:
1. Create empty concurrent_hash_maps
2. Atomically swap with _activeBots and _botsByZone (TBB swap is atomic)
3. Process isolated snapshot with zero race condition risk
4. Directly cleanup sessions (bypass DespawnBot since entries already removed)
**Benefits:**
- Thread-safe: No race conditions possible
- Fast: Single pass, no repeated lookups
- Clean: All session cleanup handled properly
- Stats: Batch updates for performance
**Technical Details:**
- Used tbb::concurrent_hash_map::swap() atomic operation
- Isolated oldBots map guarantees no concurrent access
- Direct session cleanup via RemoveAllPlayerBots()
- Atomic counter updates with memory_order_release
- Batch stat updates (single fetch_add vs N individual calls)
**Testing:**
- Compiled cleanly (RelWithDebInfo)
- No new warnings
**Location:** src/modules/Playerbot/Lifecycle/BotSpawner.cpp:1256-1300
**Priority:** P1 (Race condition in mass despawn operation)
**Task:** SESSION_LIFECYCLE_FIXES Task 2/7
Co-Authored-By: Claude Opus 4.5 <[email protected] >
Signed-off-by: luis <[email protected] >
2026-02-04 21:03:36 -03:00
..
2026-02-04 21:00:18 -03:00
2026-02-04 21:03:36 -03:00
2026-01-28 18:45:01 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-28 18:45:01 -03:00
2026-02-04 21:03:36 -03:00
2026-02-04 21:00:18 -03:00
2026-02-04 21:00:18 -03:00
2026-02-04 21:00:18 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-24 08:23:18 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-02-04 21:00:18 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-02-04 21:00:18 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-28 18:45:01 -03:00
2026-01-20 21:24:33 -03:00
2026-02-04 21:00:18 -03:00
2026-02-04 21:00:18 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-02-04 21:00:18 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-02-04 20:36:57 -03:00
2026-01-20 21:24:33 -03:00
2026-02-04 21:00:18 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-02-04 21:00:18 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-28 18:45:01 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-02-04 20:57:25 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-02-04 21:00:18 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-01-20 21:24:33 -03:00
2026-02-04 20:28:56 -03:00
2026-02-04 21:00:18 -03:00