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

Windows clients disconnect en masse #165

Closed
illej opened this issue Jul 22, 2021 · 2 comments
Closed

Windows clients disconnect en masse #165

illej opened this issue Jul 22, 2021 · 2 comments

Comments

@illej
Copy link

illej commented Jul 22, 2021

Hey there,

I've been making a basic chat application using the code snippets provided in the tutorial and it mostly works great, but I've come across a strange problem:

When I have multiple clients connected to a server, if one of the clients initiates a disconnect, then other clients will be disconnected by the server shortly after.

I have narrowed it down to this code block that is issuing the disconnect.

static int
enet_protocol_check_timeouts (ENetHost * host, ENetPeer * peer, ENetEvent * event)
{
       ...

       if (peer -> earliestTimeout != 0 &&
             (ENET_TIME_DIFFERENCE (host -> serviceTime, peer -> earliestTimeout) >= peer -> timeoutMaximum ||
               (outgoingCommand -> roundTripTimeout >= outgoingCommand -> roundTripTimeoutLimit &&
                 ENET_TIME_DIFFERENCE (host -> serviceTime, peer -> earliestTimeout) >= peer -> timeoutMinimum)))
       {
          enet_protocol_notify_disconnect (host, peer, event);

          return 1;
       }

The odd thing is this only happens to windows clients. Specifically, if I have 4 clients connected to a server, 2 on windows and 2 on linux, if one of the windows clients disconnects, all other windows clients will be forcefully disconnected by the server - the linux clients are unaffected.

Just wondering if anyone knows what could be the cause of this? I plan on digging a bit deeper at some point but figured I would report it in case anyone else was encountering something similar.

Cheers!

@lsalzman
Copy link
Owner

lsalzman commented Jul 22, 2021 via email

@illej
Copy link
Author

illej commented Aug 10, 2021

I apologise - you were right!

My chat clients were setup to read stdio in the main thread and shuttle messages to another thread that was servicing ENet. However, on windows I was using a named event object to signal the ENet thread, not knowing that if multiple separate processes all wait on a named event object of the same name they will all receive the signal, leading to the ENet threads in all windows clients halting and therefore getting disconnected.. whoops!

Sorry for wasting your time, and thank you for your response.

Great library by the way!

@illej illej closed this as completed Aug 10, 2021
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

2 participants