Repository navigation
Run the server network loop on the main thread - #56
Merged
Merged
Conversation
The asio io_context ran on a dedicated thread, so every Pawn callback (OnCefInitialize, OnCefReady, registered browser events, key events), every open.mp API call made while handling packets, and the shared UDP socket were used concurrently with the server's main thread. Pawn and the open.mp core are not thread-safe, which leads to memory corruption and crashes under load (see issue aurora-mp#42). The io_context is now polled from the server tick (CoreEventHandler::onTick for open.mp, ProcessTick for SA-MP), with a work guard and a per-tick cap on handlers. All plugin logic now runs on the main thread.
NeekoGta
added a commit
that referenced
this pull request
Oct 14, 2026
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #42.
The server component runs the asio io_context on its own thread, so all Pawn callbacks (OnCefInitialize, OnCefReady, registered browser events, OnCefPressKey) and open.mp calls made during the handshake (IsPlayerNpcBot, GetPlayerAddressIp) run off the main thread. The UDP socket is also used from both threads (CEF_EmitEvent on the main thread, receive on the network thread). Pawn and the open.mp core are not thread-safe, which explains the crashes under load.
This change removes the network thread and polls the io_context from the server tick (CoreEventHandler::onTick on open.mp, ProcessTick on SA-MP), with a work guard and a cap of 512 handlers per tick. All plugin code now runs on the main thread, without extra locking. The client and the network protocol are unchanged.
Alternative to #48, smaller and server-only.
Tested on open.mp 1.5.8 (Windows x86) with a live CEF UI: handshake, resource download, browser events in both directions.