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

KCP - created with cookie #3795

Open
Ghetaldus opened this issue Mar 26, 2024 · 2 comments
Open

KCP - created with cookie #3795

Ghetaldus opened this issue Mar 26, 2024 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@Ghetaldus
Copy link

Ghetaldus commented Mar 26, 2024

Describe the bug
Spam with "created with cookie" with different cookie numbers is coming up when client gets timeout and then returns to the game.
For example when user minimize his app on the android and then returns after timeout have occured, his connection does not drop instantly but instead spam with cookies goes on for a while before disconnect happens.

[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.

  • Import latest Mirror version from git
  • Open scene MirrorBasic from Basic example and enable debug for KCP
  • Switch build target to Android and build it
  • Start in Unity editor as server only
  • Run your build as a client (I've used Bluestacks 5 emulator here)
  • Minimize your app on the device and wait 10s for timeout and server to disconnect the client
  • Now maximize back client's app and watch server's logs in Unity editor
  • There will be plenty of lines with "[KCP] kcp2k.KcpServerConnection: created with cookie=1884780640" (see screenshot bellow)

Expected behavior
"created with cookie" should not be spammed so many times

Desktop (please complete the following information):

  • OS: Windows 10
  • Build target: Android
  • Unity version: 2021.3.35 & 2022.3.21
  • Mirror branch: 89.6.0
created_with_cookie
@Ghetaldus
Copy link
Author

To add that I've just found out that this seems to happen only when using emulator to run your app.
Tested now with 2 real different devices and it did not reproduce with these.

@imerr
Copy link
Contributor

imerr commented Mar 26, 2024

Assuming these are packets from the previous connection still arriving at the server, we could check if the cookie is 0 before creating the connection @miwarnec?

if (!connections.TryGetValue(connectionId, out KcpServerConnection connection))
{
// create a new KcpConnection based on last received
// EndPoint. can be overwritten for where-allocation.
connection = CreateConnection(connectionId);
// DO NOT add to connections yet. only if the first message
// is actually the kcp handshake. otherwise it's either:
// * random data from the internet
// * or from a client connection that we just disconnected
// but that hasn't realized it yet, still sending data
// from last session that we should absolutely ignore.
//
//
// TODO this allocates a new KcpConnection for each new
// internet connection. not ideal, but C# UDP Receive
// already allocated anyway.
//
// expecting a MAGIC byte[] would work, but sending the raw
// UDP message without kcp's reliability will have low
// probability of being received.
//
// for now, this is fine.
// now input the message & process received ones
// connected event was set up.
// tick will process the first message and adds the
// connection if it was the handshake.
connection.RawInput(segment);
connection.TickIncoming();
// again, do not add to connections.
// if the first message wasn't the kcp handshake then
// connection will simply be garbage collected.
}
// existing connection: simply input the message into kcp

@MrGadget1024 MrGadget1024 added the bug Something isn't working label Apr 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants