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

Server.IsListening wrong behavior when MaxConnections reached #169

Open
TheNybbler opened this issue Nov 16, 2022 · 1 comment
Open

Server.IsListening wrong behavior when MaxConnections reached #169

TheNybbler opened this issue Nov 16, 2022 · 1 comment

Comments

@TheNybbler
Copy link

I recently encountered a strange bug when trying to close down a server.
I had set the MaxConnections to 1, and when trying to close the server, I disconnect each client, then try to stop the server.
Here is a code snippet:

foreach (var client in Server.GetClients())
{
    Server.DisconnectClient(client);
}

if (Server.IsListening)
{
    Server.Stop();
}

// Dispose the server to release underlying socket
Server.Dispose();

The issue is that the IsListening property gets set to false once the MaxConnections is reached, so my code never calls the Server.Stop method.
If I don't call Server.Stop, the underlying socket does not get released.
If I attempt to call Server.Stop when IsListening is false, it throws an exception.

I think that there should be 2 separate properties, IsListening and IsAcceptingConnections

@TheNybbler
Copy link
Author

Update. It seems the behaviour is different when running on Linux compared to Windows. In Linux, the listener thread never restarts when max connections is reached, and then a client disconnects. This makes it impossible to shutdown the server.

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

1 participant