MirrorNetworking / kcp2k

MIT License
280 stars 48 forks source link

Mirror: KCP client disconnects if ServerChangeScene takes a lot of time #8

Open ghost opened 3 years ago

ghost commented 3 years ago

During ServerChangeScene, server stops to receive any messages. It is also affect for ping\pong messages.

Is scene is big enough it could take more than 10 seconds to load and all clients with KCP transport disconnect because of checking this timeout.

The behavior could be easily emulated by adding following code System.Threading.Thread.Sleep(15000); at the beginning of FinishLoadScene method of NetworkManager.

[https://github.com/vis2k/Mirror/issues/2480]

miwarnec commented 3 years ago

@t96bb thanks for reporting. most likely sounds like kcp's timeout. can you confirm that you saw exactly the kcp timeout message in logs?

will look into a fix.

miwarnec commented 3 years ago

switching kcp2k OnCheckEnabled hook to .paused boolean. this allows us to call Pause/Unpause from MirrorTransport.OnEnable/OnDisable.

=> should make it easy to also pause the timeout in Pause()/Unpause() to fix this bug.

miwarnec commented 3 years ago

should be fixed in latest kcp version. thanks for bug report @t96bb . added a test to make sure this will never happen again :)

miwarnec commented 3 years ago

there might be another issue according to mrgadget in discord.

ghost commented 3 years ago

Hi

Sorry, it's still there.

Please, have a look at client log

00:04.935 ConnectionSend connection(0) bytes:7F-81-02-DD-4D-A6-C0-F8-FF-3F 00:04.987 ConnectionRecv connection(0) msgType:Mirror.NetworkPongMessage content:39-28-02-DD-4D-A6-C0-F8-FF-3F-04-E2-75-FD-02-48-5A-40 00:06.937 ConnectionSend connection(0) bytes:7F-81-53-42-0B-64-D1-FF-0F-40 00:06.982 ConnectionRecv connection(0) msgType:Mirror.NetworkPongMessage content:39-28-53-42-0B-64-D1-FF-0F-40-23-77-22-D2-00-C8-5A-40 00:08.939 ConnectionSend connection(0) bytes:7F-81-D5-22-A2-98-BC-01-18-40 00:08.985 ConnectionRecv connection(0) msgType:Mirror.NetworkPongMessage content:39-28-D5-22-A2-98-BC-01-18-40-53-3D-99-7F-F4-47-5B-40 00:10.945 ConnectionSend connection(0) bytes:7F-81-61-91-BA-F8-36-04-20-40 00:10.984 ConnectionRecv connection(0) msgType:Mirror.NetworkPongMessage content:39-28-61-91-BA-F8-36-04-20-40-63-B6-64-55-04-C8-5B-40 00:12.952 ConnectionSend connection(0) bytes:7F-81-79-9C-58-96-9E-07-24-40 00:12.995 ConnectionRecv connection(0) msgType:Mirror.NetworkPongMessage content:39-28-79-9C-58-96-9E-07-24-40-1A-12-F7-58-FA-48-5C-40 00:14.954 ConnectionSend connection(0) bytes:7F-81-E7-20-43-22-C8-08-28-40 00:14.999 ConnectionRecv connection(0) msgType:Mirror.NetworkPongMessage content:39-28-E7-20-43-22-C8-08-28-40-06-30-C0-99-F3-C8-5C-40 00:16.955 ConnectionSend connection(0) bytes:7F-81-1F-E9-1D-B8-14-09-2C-40 00:16.996 ConnectionRecv connection(0) msgType:Mirror.NetworkPongMessage content:39-28-1F-E9-1D-B8-14-09-2C-40-8D-5B-CC-CF-0D-49-5D-40 00:18.963 ConnectionSend connection(0) bytes:7F-81-FD-5E-54-9C-B4-06-30-40 00:18.995 ConnectionRecv connection(0) msgType:Mirror.NetworkPongMessage content:39-28-FD-5E-54-9C-B4-06-30-40-11-1B-87-55-17-C9-5D-40 00:20.968 ConnectionSend connection(0) bytes:7F-81-34-2F-E2-96-EA-07-32-40 00:22.971 ConnectionSend connection(0) bytes:7F-81-38-C2-FD-DB-C0-08-34-40 00:24.973 ConnectionSend connection(0) bytes:7F-81-4C-A6-0A-46-25-09-36-40 00:26.974 ConnectionSend connection(0) bytes:7F-81-D2-AF-08-59-71-09-38-40 00:28.980 ConnectionSend connection(0) bytes:7F-81-F4-27-3B-47-2E-0B-3A-40 00:30.048 KCP: Connection timed out after not receiving any message for 10000ms. Disconnecting.

Before 20s - normal reply from server with pong message. Then ServerChangeScene was called on server with delay 15 sec.

After 10 seconds KCP connection disconnects automatically from server.

Roamer79 commented 3 years ago

I have this same issue. Longer scene changes = client booted. Switch back to Telepathy - OK USA

Roamer79 commented 3 years ago

Changing the default timeout on KCP connection fixed this issue. Needs to be public in the transport window

SnaiperoG3D commented 2 years ago

Duplicate my message here:

  1. I had this bug 6 mounth ago: "issue with kcp. i have two servers with two different maps on each one. first server have small map, second server have big map. both servers placed on linux. so client connect fine to server with small map, but when i try to connect to server with big map i have this error on server: KCP: Connection timed out after not receiving any message for 10000ms. Disconnecting. i guess while client load big map, there are no packages going to server or something, it reach 10000ms and server disconned the client. which does not make any sense because client doesnt even load the map there is no such problem on tcp"

I got temp solutioon by: "increase TIMEOUT for TickIncoming_Authenticated -> HandleTimeout method in KcpConnection.cs"

But it cause as i think this problem: "hello, someone know what to do in that case? Android. When any player connect to server, play some time, then manual disable internet connection, client auto disconnecting. But he still present on server. As a result, that client reenable internet connection, connect to server, and there are 2 same players. How can i prevent it?"

I got this bug only with KCP.

  1. I have Gaia usage in my game which load and unload terrain scenes and its a big problem for me

  2. I found a solution, it should be changed and optimized but i think this description will be enough to understand how to solve that, main idea is to channge timeout for specific client which start load map after connect to server:

I added another const to KcpConnection with load map timeout, for me 50000 is enough. But timeout var will be overrided by KcpTransport Component, so new const should be exposed here too. I made vars: server and client at KcpTransport as public to have access to connections of server and connection of client. Then i added this code to my custom network manager, but i think it should present at NetworkManager https://pastebin.com/KpdThNkb Now i have 50000ms timeout when player handshake with server and when client starts load new scene, because server and client have their own timeout checkers and default 10000ms after. But on server it should run not with OnServerConnect but on similar method as client has OnClientChangeScene. Because it can be situation when player dies and will be respawned far away from dead position which means it will be full load as if he have first connect and it should be 50000ms again.

Also i already changed this code for my game case (added stop coroutines when, etc.), but as i said i made it only for demostration and it should be changed for general usage

Roamer79 commented 2 years ago

Thanks for this. As it turns out it wasn’t this issue. They put some retarded idea in the transport so if any error occurs it will boot the client assuming it was malicious. I just took that out of the code as client authentication should be done on connection and that should be enough.

Cheers,

Nick

From: SnaiperoG3D @.> Reply-To: vis2k/kcp2k @.> Date: Wednesday, 3 November 2021 at 12:37 am To: vis2k/kcp2k @.> Cc: Nick Perry @.>, Comment @.***> Subject: Re: [vis2k/kcp2k] Mirror: KCP client disconnects if ServerChangeScene takes a lot of time (#8)

Duplicate my message here: I had this bug 6 mounth ago: "issue with kcp. i have two servers with two different maps on each one. first server have small map, second server have big map. both servers placed on linux. so client connect fine to server with small map, but when i try to connect to server with big map i have this error on server: KCP: Connection timed out after not receiving any message for 10000ms. Disconnecting. i guess while client load big map, there are no packages going to server or something, it reach 10000ms and server disconned the client. which does not make any sense because client doesnt even load the map there is no such problem on tcp" I got temp solutioon by: "increase TIMEOUT for TickIncoming_Authenticated -> HandleTimeout method in KcpConnection.cs"

But it cause as i think this problem: "hello, someone know what to do in that case? Android. When any player connect to server, play some time, then manual disable internet connection, client auto disconnecting. But he still present on server. As a result, that client reenable internet connection, connect to server, and there are 2 same players. How can i prevent it?"

I got this bug only with KCP. I have Gaia usage in my game which load and unload terrain scenes and its a big problem for me I found a solution, it should be changed and optimized but i think this description will be enough to understand how to solve that, main idea is to channge timeout for specific client which start load map after connect to server: I added another const to KcpConnection with load map timeout, for me 50000 is enough. But timeout var will be overrided by KcpTransport Component, so new const should be exposed here too. I made vars: server and client at KcpTransport as public to have access to connections of server and connection of client. Then i added this code to my custom network manager, but i think it should present at NetworkManager https://pastebin.com/KpdThNkb Now i have 50000ms timeout when player handshake with server and when client starts load new scene, because server and client have their own timeout checkers and default 10000ms after. But on server it should run not with OnServerConnect but on similar method as client has OnClientChangeScene. Because it can be situation when player dies and will be respawned far away from dead position which means it will be full load as if he have first connect and it should be 50000ms again.

Also i already changed this code for my game case (added stop coroutines when, etc.), but as i said i made it only for demostration and it should be changed for general usage

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android.

SnaiperoG3D commented 2 years ago

Ok, it will be fixed in next release? Just to know when i can check this out

Roamer79 commented 2 years ago

Ah no it won't be fixed. The devs thought I was a moron for even raising the problem. Apparently they think its perfectly reasonable to disconnect clients upon any error.  Clearly they have never published a release before!! I even suggested a simple toggle for the strictness but too hard to add a public boolean I guess!

⁣Get BlueMail for Android ​

On 3 Nov 2021, 9:16 pm, at 9:16 pm, SnaiperoG3D @.***> wrote:

Ok, it will be fixed in next release? Just to know when i can check this out

-- You are receiving this because you commented. Reply to this email directly or view it on GitHub: https://github.com/vis2k/kcp2k/issues/8#issuecomment-958823997

SnaiperoG3D commented 2 years ago

Well, so what we will do next? This problem with long client loading map and disconnecting wont be fixed? I making a mobile game with big map which split by parts by Gaia asset of Unity and takes a lot of time for some devices to load it and as a result there is no connection between client and server in the proccess, and as i found im not alone who got this problem, so what we should do? I see for now only one way to preload the map.

Roamer79 commented 2 years ago

Well you can just use Telepathy as a transport instead? Or, go to Mirror discord and search the issue. You will find some posts and the code removal I did much to the displeasure of the devs!!

From: SnaiperoG3D @.> Reply-To: vis2k/kcp2k @.> Date: Wednesday, 3 November 2021 at 10:40 pm To: vis2k/kcp2k @.> Cc: Nick Perry @.>, Comment @.***> Subject: Re: [vis2k/kcp2k] Mirror: KCP client disconnects if ServerChangeScene takes a lot of time (#8)

Well, so what we will do next? This problem with long client loading map and disconnecting wont be fixed? I making a mobile game with big map which split by parts by Gaia asset of Unity and takes a lot of time for some devices to load it and as a result there is no connection between client and server in the proccess, and as i found im not alone who got this problem, so what we should do? I see for now only one way to preload the map.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android.