Repository navigation
Conversation
RegisterRPC takes a HandlerThread: Packet (the default, as before), Tick or Script. A Tick or Script handler is decoded on the packet thread and posted to the thread that owns the mod state it changes, in arrival order, with the same Sender and World. A mod's services keep plain members instead of each mod writing its own hop to the tick. The Instance sets where both go before PostInit; a NetworkServer used alone calls SetHandlerPoster, and registering for a thread with no poster aborts. Documented in server_threading.md and the packet thread migration guide.
|
Caution Review failedThe pull request is closed. WalkthroughRPC handlers can now run on the packet, tick, or script thread. The server decodes posted handlers on the packet thread, then sends them to configured tick or script posters. Tests and documentation cover the routing behavior. ChangesRPC handler thread routing
Estimated code review effort: 3 (Moderate) | ~20 minutes Change: Feature Sequence Diagram(s)sequenceDiagram
participant NetworkServer
participant SchedulerOwner
participant ScriptThread
NetworkServer->>SchedulerOwner: Post tick handler with decoded payload, sender, and world
NetworkServer->>ScriptThread: Post script handler with decoded payload, sender, and world
Suggested reviewers: Merge Risk:
|
|
Closing: this adds a second way to do what the Framework already prescribes. Handlers stay on the packet thread and mod state is registered with the world (World::RegisterState). The mod that motivated this should register its state instead of hopping to the tick. |
What
NetworkServer::RegisterRPCtakes aHandlerThread:Packet(the default, unchanged),TickorScript.SenderandWorld.Reply,DropandAvatarstill work;Avatar()is 0 if the connection closed in between.slow-packet-handler-ms.Instancesets both posters beforePostInit. A bareNetworkServercallsSetHandlerPoster. Registering for a thread with no poster logs critical and aborts, like the other misuse checks.Why
Since 42, a handler that touches a mod's own state (a service's maps) races with
PostUpdateand scripts unless the mod registers that state with the world or guards it. Porting a server mod, every service-touching handler ended up wrapped in the same project-side helper that posts to the tick. This is FiveM's arrangement: a packet's work is handed to the thread that owns what it changes (gscomms_execute_callback_on_main_thread/_on_sync_thread). Built in, mods keep plain service members and say where each handler runs.No wire, scripting or ABI-breaking change. The existing
RegisterRPCcalls compile unchanged.Tests
Two new cases in
server_packet_thread:Tickhandler runs on the tick thread, 50 of them in order, each finding the sender's avatar and replying.Scripthandler runs on the script thread, which is neither the tick thread nor the packet thread.Local Windows run:
server_packet_thread21/21 passed.server,packet,network,world,task_schedulermodules: 169/169 passed. Not formatted with clang-format locally (not installed here).Docs:
server_threading.md("Running a handler on the tick or the script thread") andmigrating_to_the_packet_thread.mdsection 3.Summary by CodeRabbit