Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ghost opened this issue Dec 4, 2020 · 13 comments
Open

Comments

@ghost
Copy link

ghost commented Dec 4, 2020

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/MirrorNetworking/Mirror/issues/2480]

@miwarnec
Copy link
Collaborator

@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 pushed a commit that referenced this issue Jan 12, 2021
…ET where in the benchmark demo we send so many unreliable messages that no reliable messages (or ping) was received in the timeout interval, causing the connection to disconnect even though it did receive unreliable messages. lastReceive is even set for unreliable messages while not enabled (=during scene changes) to prepare the fix for #8 (just needs ping to go over unreliable now)
miwarnec pushed a commit that referenced this issue Jan 12, 2021
miwarnec pushed a commit that referenced this issue Jan 12, 2021
miwarnec pushed a commit that referenced this issue Jan 12, 2021
…ed' boolean. This is faster than invoking a Func<bool> every time and allows us to fix #8 more easily later by calling .Pause/.Unpause from OnEnable/OnDisable in MirrorTransport.
@miwarnec miwarnec reopened this Jan 12, 2021
@miwarnec
Copy link
Collaborator

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
Copy link
Collaborator

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

@miwarnec miwarnec reopened this Jan 12, 2021
@miwarnec
Copy link
Collaborator

there might be another issue according to mrgadget in discord.

@ghost
Copy link
Author

ghost commented Jan 14, 2021

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
Copy link

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

@Roamer79
Copy link

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

@SnaiperoG3D
Copy link

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
Copy link

Roamer79 commented Nov 3, 2021 via email

@SnaiperoG3D
Copy link

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

@Roamer79
Copy link

Roamer79 commented Nov 3, 2021 via email

@SnaiperoG3D
Copy link

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
Copy link

Roamer79 commented Nov 4, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants