mas-bandwidth / yojimbo

A network library for client/server games written in C++
BSD 3-Clause "New" or "Revised" License
2.45k stars 238 forks source link

Windows: cannot connect while other clients are timing out #170

Closed Freeeaky closed 8 months ago

Freeeaky commented 2 years ago

It seems like it's not possible to connect to the server while other clients are timing out. Similarly, when clients send messages at this time, they are only received after a significant delay (>3 seconds).

Steps to reproduce:

I have tested this on my machine & on an AWS-hosted server with similar results.

gafferongames commented 2 years ago

Does each client above have a unique port number, or are you reusing a port number shared with a timing out client?

Freeeaky commented 2 years ago

@gafferongames every client has a unique port number.

Looks like I found the issue, only needed to doubt Windows.. Apparently Windows is emitting ICMP packets about the connection failure - even though we are using UDP here. Here is a source code code snippet for netcode_socket_create:

#define SIO_UDP_CONNRESET _WSAIOW(IOC_VENDOR, 12)

#if NETCODE_PLATFORM == NETCODE_PLATFORM_WINDOWS
    BOOL bNewBehavior = FALSE;
    DWORD dwBytesReturned = 0;
    WSAIoctl(s->handle, SIO_UDP_CONNRESET, &bNewBehavior, sizeof bNewBehavior, NULL, 0, &dwBytesReturned, NULL, NULL);
#endif

With the fix in place, the issue mentioned above is solved.

Reading material, including the source of the fix:

gafferongames commented 2 years ago

Very interesting

gafferongames commented 8 months ago

A similar fix has been applied to netcode, and will be merged shortly. Closing.