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 stops responding after 65536 requests in simple test app #95

Open
Jepplar opened this issue Oct 2, 2023 · 1 comment
Open

Server stops responding after 65536 requests in simple test app #95

Jepplar opened this issue Oct 2, 2023 · 1 comment

Comments

@Jepplar
Copy link

Jepplar commented Oct 2, 2023

I'm running into an issue where the CoAP server seemingly stops responding to the client after 2**16 requests in one of my applications.
I have separated the issue into a simple test server+client as outlined below which replicates the issue.

Even though the client sends 100k requests, only 65k of them are received by the server.
Adding a sleep when sending requests, waiting for ACK etc does not seem to make a difference.

Any ideas on how to resolve the issue?

Server code:

namespace CoapTestServer
{
    internal class Program
    {
        static void Main(string[] args)
        {
            CoapServer server = new CoapServer();

            server.Add(new TestResource());
            server.Start();

            Console.WriteLine("Running...");
            Console.ReadKey();
        }
    }

    class TestResource : Resource
    {
        static long connectionCount = 0;

        public TestResource() : base("test-resource")
        {
        }

        protected override void DoGet(CoapExchange exchange)
        {
            long newCount = Interlocked.Increment(ref connectionCount);
            Console.WriteLine($"Server received {newCount} requests");

            exchange.Respond("This is a response");
        }
    }
}

Client code:

Uri hostUri = new Uri("coap://localhost/test-resource");
for (int i = 0; i < 100 * 1000; i++)
{
    try
    {
        Request request = new(Method.GET, false)
        {
            URI = hostUri,
        };

        request.Send();
        request.WaitForResponse();

        Console.WriteLine($"Client sent {i} requests");
    }
    catch (Exception ex)
    {
        Console.WriteLine($"{ex.Message}");
    }
}

Console.WriteLine("Finished, press enter to exit");
Console.ReadLine();

Output:
image

I am using NuGet package 1.10.0 of "Com.AugustCellars.CoAP" with .NET 7.0 and Visual Studio 2022 on Windows 10.

@Jepplar
Copy link
Author

Jepplar commented Oct 2, 2023

I have managed to find a workaround for the issue by lowering ExchangeLifetime to 5000 in the server config from its default value. It seems to be connected to deduplication although I'm not quite sure which side effects it might have.

I'm also not sure why it runs into an issue at 65k exchanges which seem a bit low. I am assuming that it runs out of some kind of handle or buffer space, which the above mentioned sweep resolves by removing old exchanges prematurely.

Is there perhaps a better solution?

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