question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Listening stops with many connections (pub/sub)

See original GitHub issue

My demo bench is a small Net Core app with 20 connections as publishers, and other 20 as listeners. The broker is reached as 127.0.0.1 on Windows 10. Still I haven’t understand what’s going on, but I found an issue at this point: https://github.com/nats-io/csharp-nats/blob/d2ed82da04b2d2ddee770f1424302c0faf482289/NATS.Client/Conn.cs#L1047 Basically, the task does not start although apparently there’s no reason on that. The result is that the inner method is not called, and no message is listen to any of the subscribers. I solved turning the line as: new Thread(() => spinUpSocketWatchers()).Start(); Another way is to calling the method directly, but I guess you don’t want to halt the caller. I’ll dig into a little more, but…BAH!..let me know your opinion on.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:13 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
sebastien-curutchetcommented, Dec 8, 2017

If the threadpool doesn’t have enough available threads to do the connection, you have a timeout. It is because of this code client.ConnectAsync(s.url.Host, s.url.Port).Wait(TimeSpan.FromMilliseconds(timeoutMillis)). I have a similar issue on a stressed environment. I’m trying to implement the timeout by another way based on BeginConnect /EndConnect and TCPClient.Client.Poll method.

For now I did a workaround which avoids Timeout but doesn’t resolve the delay to execute the Connect method.

public static bool Connect(this TcpClient client, string host, int port, int actionTimeoutInMs, int totalTimeoutInMs = int.MaxValue)
        {
            client.Client.SendTimeout = totalTimeoutInMs;
            ManualResetEvent mre = new ManualResetEvent(false);
            var task = Task.Run(() =>
            {
                mre.Set();
                client.Connect(host, port);
            });
            if (mre.WaitOne(totalTimeoutInMs))
            {
                if (!task.Wait(actionTimeoutInMs))
                {
                    return false;
                }
                return true;
            }
            return false;
        }
1reaction
sixlettervariablescommented, Nov 10, 2017

You’re basically exhausting the thread pool. On my 32 core workstation, things got unwieldy past the 500 thread mark…

Any reason why you need so many NATS connections? Within an application one connection can handle arbitrarily many publishers and subscribers.

Your second example fails because most of the publishers finish publishing before the subscribers are even ready to listen.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Listening stops with many connections (pub/sub) · Issue #190
Any reason why you need so many NATS connections? Within an application one connection can handle arbitrarily many publishers and subscribers.
Read more >
Firebase cloud pubsub subscriptions stops listening for ...
I'm trying to connect my firebase cloud functions project to a third party pub/sub (a separate project). According to this thread this is ......
Read more >
Handle message failures | Cloud Pub/Sub
In this case, it's possible that Pub/Sub will resend multiple messages that can't be acknowledged.
Read more >
Things I wish I knew about Google Cloud Pub/Sub: Part 2
If your client pulls too many messages at once, it may not be able to process all of the messages, leading to many...
Read more >
Google Pub/Sub operation
This operation listens for messages from Google Pub/Sub subscriptions. ... how many stream connections the client establishes with the Pub/Sub service.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found