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.

Timeout not working as expected

See original GitHub issue

I’m doing some testing on failure scenarios, and am testing what happens if the NATS server is stopped while my process is running.

I’m finding the timeout periods seem to be getting ignored, assuming I’ve configured it correctly.

Here is my reproduce code.

using NATS.Client;
using System;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;

namespace TestNats
{
    class Program
    {
        static void Main(string[] args)
        {
            Task.Run(() => Run());
            Console.ReadLine();
            
        }

        static async Task Run()
        {
            Console.WriteLine("Hello World!");
            var cf = new ConnectionFactory();
            var opts = ConnectionFactory.GetDefaultOptions();
            opts.Timeout = 1000;
            opts.AllowReconnect = false;
            var conn = cf.CreateConnection(opts);
            conn.SubscribeAsync("test", (p, a) => conn.Publish(a.Message.Reply, new byte[0]));
            await conn.RequestAsync("test", new byte[0], 1000);

            Console.WriteLine("Now stop nats server, you have 5 seconds");
            Thread.Sleep(5000);
            
            var s = new Stopwatch();
            s.Start();
            try
            {
                await conn.RequestAsync("test", new byte[0], 1000);
                s.Stop();
                Console.WriteLine(s.ElapsedMilliseconds / 1000 + "s");
            }
            catch (Exception ex)
            {
                s.Stop();
                Console.WriteLine(s.ElapsedMilliseconds / 1000 + "s");
                Console.WriteLine(ex.Message);
            }
        }
    }
}

Output:

Hello World!
Now stop nats server, you have 5 seconds
60s
Timeout occurred.

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
chrismcvcommented, Mar 29, 2017

@ColinSullivan1 no problem - and thank for the quick response too.

I’ve tested your PR and it is giving the following output for my sample code.

Hello World!
Now stop nats server, you have 5 seconds
0s
Timeout occurred.

This seems good to me. Thanks for your help!

0reactions
ColinSullivan1commented, Mar 29, 2017

@chrismcv, Great - thank you for testing! My local tests pass as well; I’ll merge the PR.

Read more comments on GitHub >

github_iconTop Results From Across the Web

javascript - Timeout is not working as expected
In this code i'm trying to print Timeout in console after 0.5 second, and there is a while loop which terminates after a...
Read more >
Wait timeout and waitproperty not working as expected
I pass in two arguments the object and an integer value of how long I want it to wait for the exists property...
Read more >
Idle timeout not working as expected. - Claris Community
What I've tried: 1. Set the "fmreauthenticate60" to 60 minutes and made sure there were no other fmreauthenticate's set to the privilege set....
Read more >
HD72535: PART: TIMEOUT NOT WORKING AS EXPECTED
PART: TIMEOUT NOT WORKING AS EXPECTED Scenario: 1. start CATIA by using CNEXT ?workbench empty 2. CATIA will be started without product window...
Read more >
Timeout does not work in expect script
I would explicitly expect the timeout: set timeout 10 spawn vpnc expect : send [lindex $argv 0]\r expect { timeout {error "incorrect ...
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