LabAPI icon indicating copy to clipboard operation
LabAPI copied to clipboard

[BUG]: ReferenceHub::connectionToClient.address getter throws error when client is disconnected

Open Someone-193 opened this issue 8 months ago • 4 comments

Before You Report

  • [x] I have searched for existing reports of this bug, and this bug report is unique.

Version

1.1.6, this is specifically a base game bug for the 14.2.6 beta

Description

When you use an event like PlayerLeft and then construct a footprint from that event, your code will now throw an error despite it still working last update. This happens due to (see title)

To Reproduce

subscribe to PlayerLeft event and then call the ReferenceHub::connectionToClient.address getter in 14.2.6

Expected Behavior

No error should happen

Additional Information

From what I can see in the base game code from previous SL versions, SL never actually cleared out the Peers array (now dictionary) in the custom mirror server implementation, I think this meant that peers actually stayed cached even after one disconnected or something? I dont fully know to be honest, you'd have to ask somebody who worked on the new custom mirror stuff tbh. Anyways, the new implementation actively removes peers from the dictionary so if I was correct, then really you could fix this by just not trying to remove peers from the dictionary when they disconnect, or you could just add a check to the footprint constructor to fix my use case specifically

Someone-193 avatar Mar 25 '26 15:03 Someone-193

Can you provide the error at all so we get a better understanding of the issue?

LumiFae avatar Mar 25 '26 16:03 LumiFae

I know this isnt ideal, but I had to look through my LA logs for this. What happened is I disconnected, then my role got set to spectator and the spawn reason was not destroyed somehow, then because of an Exiled config where you're supposed to drop all your items, ServerDropEverything was called which then needed to make footprints for the previous owner of the items. Do keep in mind that in this case specifically ServerDropAmmo caused the error, due to Exiled patching in setting PreviousOwner for that, but the same error would have occurred on ServerDropItem instead. Furthermore the same method would have been called by the base game (if you have the disconnect drop config on). Also I think because the new mirror stuff uses concurrent dictionaries, I'm struggling to recreate this.

[2026-03-24 22:52:42.738 -04:00] Player Someone disconnected
[2026-03-24 22:52:42.772 -04:00] [STDOUT] Cannot set the parent of the GameObject 'SpectatorRole(Clone)' while its new parent 'Player [connId=1]' is being destroyed
[2026-03-24 22:52:42.801 -04:00] [ERROR] [Exiled.Events] Method "OnChangingRole" of the class "Exiled.Events.Handlers.Internal.Round" caused an exception when handling the event "Exiled.Events.Features.Event`1[[Exiled.Events.EventArgs.Player.ChangingRoleEventArgs, Exiled.Events, Version=9.13.1.0, Culture=neutral, PublicKeyToken=null]]"
                                 System.Collections.Generic.KeyNotFoundException: The given key '1' was not present in the dictionary.
                                   at System.Collections.Concurrent.ConcurrentDictionary`2[TKey,TValue].ThrowKeyNotFoundException (System.Object key) [0x00010] in <13c0c460649d4ce49f991e2c222fa635>:0 
                                   at System.Collections.Concurrent.ConcurrentDictionary`2[TKey,TValue].get_Item (TKey key) [0x0000b] in <13c0c460649d4ce49f991e2c222fa635>:0 
                                   at Mirror.LiteNetLib4Mirror.LiteNetLib4MirrorServer.GetClientAddress (System.Int32 connectionId) [0x00000] in <72fad981453040f3bc624246ce4a913a>:0 
                                   at Mirror.LiteNetLib4Mirror.LiteNetLib4MirrorTransport.ServerGetClientAddress (System.Int32 connectionId) [0x00000] in <72fad981453040f3bc624246ce4a913a>:0 
                                   at Mirror.NetworkConnectionToClient.get_OriginalIpAddress () [0x00000] in <1bebde0895f14b11be97fb0c4e2cabe4>:0 
                                   at Mirror.NetworkConnectionToClient.get_address () [0x0000a] in <1bebde0895f14b11be97fb0c4e2cabe4>:0 
                                   at Footprinting.Footprint..ctor (ReferenceHub hub) [0x000ee] in <72fad981453040f3bc624246ce4a913a>:0 
                                   at (wrapper dynamic-method) InventorySystem.InventoryExtensions.InventorySystem.InventoryExtensions.ServerDropAmmo_Patch0(InventorySystem.Inventory,ItemType,uint16,bool)
                                   at InventorySystem.InventoryExtensions.ServerDropEverything (InventorySystem.Inventory inv) [0x00092] in <72fad981453040f3bc624246ce4a913a>:0 
                                   at Exiled.Events.Handlers.Internal.Round.OnChangingRole (Exiled.Events.EventArgs.Player.ChangingRoleEventArgs ev) [0x0003b] in <6d81dc63d0db469d8ea7e26e0e5f2404>:0 
                                   at Exiled.Events.Features.Event`1[T].BlendedInvoke (T arg) [0x00088] in <6d81dc63d0db469d8ea7e26e0e5f2404>:0

Someone-193 avatar Mar 25 '26 17:03 Someone-193

When the OnChaningRole run (I assume) is run after the client peer is removed. I recommend implement a Prefix patch in LiteNetLib4MirrorServer.OnPeerDisconnected so you still have the Peer & can get the connection / player before it actually gets destroyed. (so the disconnect on drop run before the role actually changes & you can still create a footprint)

SlejmUr avatar Mar 26 '26 10:03 SlejmUr

We will add Leaving event to overcome this + other issues

davidsebesta1 avatar Apr 08 '26 13:04 davidsebesta1