Deleting body in multiplayer resulting in error

Godot Version

4.2.2

Question

I have a multiplayer running and its functioning normally. Recently I discovered that when someone disconnects it gives me this error :

E 0:00:13:0931   _remove_node_cache: Condition "!pinfo" is true. Continuing.
  <C++ Source>   modules/multiplayer/scene_cache_interface.cpp:57 @ _remove_node_cache()

It is centered around my disconnect function and I don’t know why it suddenly krept up.

this is what my spawning code as a whole looks like

extends Node3D

var random_location := 5

func _ready():
	print("level ready")
	if not multiplayer.is_server():
		return
	
	multiplayer.peer_connected.connect(peer_connected)
	multiplayer.peer_disconnected.connect(peer_disconnect)
	
	for player_id in multiplayer.get_peers():
		add_player(player_id)
	
	if not OS.has_feature("dedicated_server"):
		add_player(1)

func peer_connected(player_id:int):
	add_player(player_id)

func peer_disconnect(player_id:int):
	delete_player(player_id)

func add_player(player_id:int):
	print("add player:"+str(player_id))
	var player=preload("res://Assets/player/Bodies/player_drone_body.tscn").instantiate()
	player.player=player_id ##!!the variable after player is referancing player property!!##
	
	var player_position :=Vector2.from_angle(randf()*2*PI)
	player.position=Vector3(player_position.x*random_location*randf(),0,player_position.y*random_location*randf())
	player.name=str(player_id)
	$Portal.add_child(player,true)

func delete_player(player_id:int):
	if not $Portal.has_node(str(player_id)):
		return
	$Portal.get_node(str(player_id)).call_deferred("queue_free")

func _exit_tree():
	if not multiplayer.is_server():
		return
	multiplayer.peer_connected.disconnect(peer_connected)
	multiplayer.peer_disconnected.disconnect(peer_disconnect)

I have other questions related to:
multiplayer.peer_connected.connect(peer_connected)
multiplayer.peer_disconnected.connect(peer_disconnected)
multiplayer.connected_to_server.connect(connected_to_server)
multiplayer.connection_failed.connect(connection_failed)
^^^ I tried putting the code related to multiplayer in an autoloader but everything refused to work.

Technically the code works as-is. It deletes the body and the game continues forward as normal. I tried some prints to see if its somehow pinging the disconnect function twice but it looks like only does it on the single attempt. The session that is giving the error is the host. I turned off the disconnect function and the body continues to stay so the disconnect is the only thing messing with the bodies removal!? I wonder if its a timing thing or something. I am curious on thoughts. It does work, im just confused why the error started appearing and what it means? other than simply “im trying to delete a node that doesnt exist”.

Full disclosure I’ve done zero godot MP. But it’s my coffee break here and I have some thoughts anyways.

If I had to guess, the node in question still technically exists, but is no longer valid.

So where you check if $Portal has the node, get the node and cache the result, then test if the result is valid with is_instance_valid(), and if it is, then queue_free it.

Alternatively I suspect that calling delete_player itself deferred, and not just the queue_free end result may accomplish same thing. Checking if valid feels cleaner to me though.

gl! Now i wanna code some MP stuff, lol.