Are race conditions a worry when receiving multiple `rpc` commands?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By shianiawhite

I have a setup where multiple users can be “using” a scene. When a client wants to access the scene, they make a request to the server. If the scene already exists, the server gives the current state of the scene to the client. If the scene does not already exist, the server creates the scene and sends that initial state to the client. If all clients stop using a scene, the scene is deleted.

If the server decides there is no client using the scene, but at the same time, receives a new client requesting the scene, this might end up a deleted scene trying to send its state to the client.

Does Godot handle multiple incoming rpc commands in parallel (or handle a single rpc command in parallel with the server’s own code? Or are all the functions run in order for that frame of the game? (e.g. server runs local _process functions completely before moving to the first rpc received during this frame which is handled completely before the second rpc…) Does this kind of code require some kind of mutex lock? Or am I in the clear to leave it simple without the lock?

Thank you!

:bust_in_silhouette: Reply From: hungrymonkey

There is only one network tree in scenetree.

Network commands may not be queued in order but they are emitted one at a time.