godot: MultiplayerSynchronizer and RPCs lead to errors on the server when a client disconnects


Bugsquad note: This issue has been confirmed several times already. No need to confirm it further.


Godot version

4.0-beta9

System information

Windows 11

Issue description

Using the MultiplayerSynchronizer node, or sending RPCs every frame, leads to errors in the server’s console when there are multiple clients and one of them disconnects. It seems that increasing the Replication Interval of the MultiplayerSynchronizer or sending RPCs less frequently makes the problem less likely to occur, but it still will happen occasionally.

I wasn’t able to find an existing open issue for this, which is strange given how easy the issue is to encounter (at least in my testing). So, I may have been searching with the wrong keywords.

Here is an example of the type of errors produced:

ERROR: Condition "peer > 0 && !connected_peers.has(peer)" is true.
   at: _process_sys (modules/multiplayer/scene_multiplayer.cpp:317)
ERROR: Node not found: "World/Players/70163785" (relative to "/root").
   at: (scene/main/node.cpp:1359)
ERROR: Failed to get cached path: World/Players/70163785.
   at: get_cached_object (modules/multiplayer/scene_cache_interface.cpp:246)
ERROR: Invalid packet received. Requested node was not found.
   at: (modules/multiplayer/scene_rpc_interface.cpp:228)
ERROR: Condition "peer > 0 && !connected_peers.has(peer)" is true.
   at: _process_sys (modules/multiplayer/scene_multiplayer.cpp:317)

Steps to reproduce

The problem generally seems to occur under the following scenario:

  1. Use a MultiplayerSynchronizer node to synchronize a variable that the client has authority over. Alternatively, send a consistent stream of RPCs from one of the clients. (Both of these happen in the example).
  2. Start a server, connect multiple clients.
  3. Close one of the clients.
  4. Errors will appear in the console of the server.

Repeating these steps multiple times may lead to slightly different output, but the general errors are the same.

Minimal reproduction project

Networking.zip

Start one instance of the game with the “–server” flag. Start two or more other instances without the server flag, these are the clients. Close one of the clients. Errors are then printed in the server’s console.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 9
  • Comments: 33 (10 by maintainers)

Commits related to this issue

Most upvoted comments

I’d be inclined towards making these use print_verbose().

I get this error on 4.1.1.

In my opinion these cases (at least for my use case) shouldn’t be considered errors, so I made the following changes locally.

Code diff
diff --git a/modules/multiplayer/scene_cache_interface.cpp b/modules/multiplayer/scene_cache_interface.cpp
index f0da4f9dfc..40b2c59d70 100644
--- a/modules/multiplayer/scene_cache_interface.cpp
+++ b/modules/multiplayer/scene_cache_interface.cpp
@@ -241,10 +241,7 @@ Object *SceneCacheInterface::get_cached_object(int p_from, uint32_t p_cache_id)
 	ERR_FAIL_COND_V_MSG(!F, nullptr, vformat("ID %d not found in cache of peer %d.", p_cache_id, p_from));
 
 	PathGetCache::NodeInfo *ni = &F->value;
-	Node *node = root_node->get_node(ni->path);
-	if (!node) {
-		ERR_PRINT("Failed to get cached path: " + String(ni->path) + ".");
-	}
+	Node *node = root_node->get_node_or_null(ni->path);
 	return node;
 }
 
diff --git a/modules/multiplayer/scene_multiplayer.cpp b/modules/multiplayer/scene_multiplayer.cpp
index 5042a0502d..2824fa418f 100644
--- a/modules/multiplayer/scene_multiplayer.cpp
+++ b/modules/multiplayer/scene_multiplayer.cpp
@@ -314,7 +314,10 @@ void SceneMultiplayer::_process_sys(int p_from, const uint8_t *p_packet, int p_p
 			bool should_process = false;
 			if (get_unique_id() == 1) { // I am the server.
 				// Direct messages to server should not go through relay.
-				ERR_FAIL_COND(peer > 0 && !connected_peers.has(peer));
+				// Don't continue if the peer is no longer connected.
+				if (peer > 0 && !connected_peers.has(peer)) {
+					return;
+				}
 				// Send relay packet.
 				relay_buffer->seek(0);
 				relay_buffer->put_u8(NETWORK_COMMAND_SYS);
diff --git a/modules/multiplayer/scene_rpc_interface.cpp b/modules/multiplayer/scene_rpc_interface.cpp
index a7e29dfcc7..d9f67adbcd 100644
--- a/modules/multiplayer/scene_rpc_interface.cpp
+++ b/modules/multiplayer/scene_rpc_interface.cpp
@@ -159,11 +159,7 @@ Node *SceneRPCInterface::_process_get_node(int p_from, const uint8_t *p_packet,
 
 		NodePath np = paths;
 
-		node = root_node->get_node(np);
-
-		if (!node) {
-			ERR_PRINT("Failed to get path from RPC: " + String(np) + ".");
-		}
+		node = root_node->get_node_or_null(np);
 		return node;
 	} else {
 		// Use cached path.
@@ -225,7 +221,9 @@ void SceneRPCInterface::process_rpc(int p_from, const uint8_t *p_packet, int p_p
 	}
 
 	Node *node = _process_get_node(p_from, p_packet, node_target, p_packet_len);
-	ERR_FAIL_COND_MSG(node == nullptr, "Invalid packet received. Requested node was not found.");
+	if (node == nullptr) {
+		return;
+	}
 
 	uint16_t name_id = 0;
 	switch (name_id_compression) {

Personally, I don’t think there should be errors logged due to using NetworkSynchronizer in what I believe is the intended way. RPCs sent to nodes that have just been destroyed by a client disconnecting should also be simply ignored in my opinion. However, I don’t have enough context on the networking system as a whole to be sure that the changes I made here don’t cause Godot to ignore actual errors. There might also be a very good reason to have errors in these situations that I’m not aware of.

@YuriSizov

Can confirm this problem still exists in Godot Engine v4.3.rc1.official.e343dbbcc

1722511842492

This error only occurs when there are multiple players connected to the server; if the last player leaves the game, there are no errors.

...
multiplayer.multiplayer_peer = server_peer
multiplayer.peer_connected.connect(_on_peer_connected)
multiplayer.peer_disconnected.connect(_on_peer_disconnected)
...

func _on_peer_disconnected(client_id: int) -> void:
	print("[server:client:disconnected]", str(client_id))
	if data["players"][str(client_id)]:
		var players_node = get_parent().get_node("Players")
		if players_node.has_node(str(client_id)):
			var player_node = players_node.get_node(str(client_id))
			player_node.queue_free()
			data["players"].erase(str(client_id))
			print("[server:client:disconnected:remove]", str(client_id))
			rpc("on_remove_player", client_id)

I don’t know if this will work for player synchronization, but for my bullets I currently bypassed it by setting the rootnode of the multiplayersynchronizer in the ready function to the parent where I know it would be.

func _ready(): $MultiplayerSynchronizer.set_root_path(“…/BulletSpawn”)

so far haven’t had the issues anymore (altho, limited testing) However, the error spam when despawning the bullets went away after I added it like that

I can confirm this is still present in latest master (68193bee9 as of writing).

Should I continue to provide feedback and the MRP here?

Can confirm this problem exists in v4.2.1.stable.official [b09f793f5] as well. Only happening on disconnect with more than one peer. (More than 2 if a player is the server.) It also happens multiple times that equal the remaining number of players who are not the server.

Just saw the bugsquad note at the top, sorry for the needless reconfirm, my bad.

Is there even a time when the error occurs as an actual mistake instead of by disconnecting?

Whoops, sorry for making you wait, I didn’t even work on it. I guess I could try figuring it out now. I just need more info.

Thank you very much. I have provided my minimal program and the steps to reproduce it in the previous reply, hoping it can help you.

Whoops, sorry for making you wait, I didn’t even work on it. I guess I could try figuring it out now. I just need more info.

The error log in the OP can be paraphrased as "SceneMultiplayer has received an update for node World/Players/70163785 that does not exist (anymore) by a player that is not connected (anymore); update discarded".

Most of the time, these logs are normal for networking. Sometimes, you are going to send an update, not knowing that either the pertaining player has already left, or the last updates by that leaving player are going to arrive after they alread left, and so on. Things have latency after all, and order of updates isn’t always guaranteed.

So most of the time, these are harmless (if you do not encounter any actual breakage). But sometimes, they can be indicative of a larger problem. If you get a lot of these suddenly after a change where you didn’t before, it is likely you got some ordering wrong somewhere, or some node paths are not matching up between clients, and so on.

So while it is noisy, sometimes it is useful. We may be able to trim them a bit, and may want to consider adding a way to silence them (optionally or by default).