MirrorNetworking / Mirror

#1 Open Source Unity Networking Library
https://mirror-networking.com
MIT License
5.18k stars 767 forks source link

KCP Threaded Client Error On Disconnect #3787

Closed joshuameurey closed 1 week ago

joshuameurey commented 7 months ago

Describe the bug Application produces this error "Skipped Data message handling because connection is null." each time one client is disconnecting normally from the host.

[IMPORTANT] How can we reproduce the issue, step by step: Please tell us how to reproduce your issue, STEP BY STEP, with one of our built in examples. -> Configure project to use Threaded KCP transport -> Build and run a standalone application (this will be the host: client+server) -> Run application in Unity Editor (this is a pure client), connect to the host -> Disconnect properly the client (not in any bad/error conditions) -> Log error appears in Unity Log It appears that it remains data (bytes) in stack to process when the transport is disconnected

Any bug that can be reproduced, can be fixed. If we can't reproduce it, we can't fix.

Expected behavior Since the client is disconnected, no mater what is remaining in bytes data stack, it should not produce error.

Screenshots N/A

StackTrace Skipped Data message handling because connection is null. UnityEngine.Debug:LogError (object) Mirror.NetworkClient:OnTransportData (System.ArraySegment1<byte>,int) (at Assets/Mirror/Core/NetworkClient.cs:395) Mirror.ThreadedTransport:ClientEarlyUpdate () (at Assets/Mirror/Transports/Threaded/ThreadedTransport.cs:410) Mirror.NetworkClient:NetworkEarlyUpdate () (at Assets/Mirror/Core/NetworkClient.cs:1489) Mirror.NetworkLoop:NetworkEarlyUpdate () (at Assets/Mirror/Core/NetworkLoop.cs:193)

Desktop (please complete the following information):

Additional context Important: this is produced using Threaded KCP transport

miwarnec commented 2 weeks ago

checking

miwarnec commented 2 weeks ago

ok i can reproduce this with tanks demo, but not with benchmark.

in tanks demo: build = host, editor=client, client disconnects while moving.

image

miwarnec commented 2 weeks ago

only seems to happen sometimes, about 1/5 tests

miwarnec commented 2 weeks ago

never happens for regular kcp

miwarnec commented 2 weeks ago

checking where and when its set to null: image

Ghetaldus commented 2 weeks ago

only seems to happen sometimes, about 1/5 tests

Yes, it happens for me too at about same rate.

miwarnec commented 2 weeks ago

here's what usually happens when it works image

miwarnec commented 2 weeks ago

there are probably two issues here. 1) threadedkcp still spitting out data messages after disconnect 2) stopclient shouldn't call shutdown immediately, as already indicated here: image

miwarnec commented 2 weeks ago

actually no, threadedtransport is fine. it spits out a few pending data messages, and then the disconnect message.

the problem is only this above

miwarnec commented 1 week ago

fixed both: https://github.com/MirrorNetworking/Mirror/pull/3913/commits