Skip to content

Run the server network loop on the main thread - #56

Merged
NeekoGta merged 2 commits into
aurora-mp:mainfrom
Masvidal99:fix/main-thread-network
Oct 14, 2026
Merged

NeekoGta merged 2 commits into
aurora-mp:mainfrom
Masvidal99:fix/main-thread-network

Conversation

@Masvidal99

Copy link
Copy Markdown
Contributor

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.

Masvidal99 and others added 2 commits October 7, 2026 23:31
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
NeekoGta merged commit 19e8ac9 into aurora-mp:main Oct 14, 2026
1 check failed
NeekoGta added a commit that referenced this pull request Oct 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Crash when spamming a button

2 participants