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.

SendAndWait TimeoutException with 4.0.0 version

See original GitHub issue

Hi, today i’ve updated WatsonTcp library in my projects from 3.1.4 to 4.0.0 version and the SendAndWait calls throws always a Timeoutexception.

I’ve created a minimal example project to check if i did something wrong but the problem is in the library and the Expiration field in header message (i think is the string format of datetime with the Z).

enabling debug messages and log i can see the server trashes the message immediatly after receiving it:

11:46:13.450 --> [WatsonTcpServer] Starting on 0.0.0.0:23456
11:46:22.981 --> [WatsonTcpServer] Starting data receiver for 10.10.3.12:38387
11:46:22.981 --> [WatsonTcpServer] Accepted connection from 10.10.3.12:38387
Client connected: 10.10.3.12:38387
11:46:31.952 --> [WatsonMessage] ReadHeaders found header demarcation
11:46:32.122 --> [WatsonMessage] ReadHeaders header processing complete {"Status":"Normal","SyncRequest":true,"SyncResponse":false,"Expiration":"2020-04-10T09:47:01.7335196Z","ConversationGuid":"8d201325-9be4-44d2-bd08-162f4101f14f" ,"ContentLength":24,"Metadata":{}}    
11:46:32.123 --> [WatsonTcpServer] Expired synchronous request received and discarded from 10.10.3.12:38387

this is the client log:

11:46:22.921 --> [WatsonTcpClient] Connecting to rds-dev:23456
11:46:23.000 --> [WatsonTcpClient] Connected to server
Connected to server
Write 'q' to quit application or 's' to send sync request.
s
11:46:31.732 --> start sync request
11:47:01.798 --> System.TimeoutException: A response to a synchronous request was not received within the timeout window.
   at WatsonTcp.WatsonTcpClient.GetSyncResponse(String guid, DateTime expirationUtc)
   at WatsonTcp.WatsonTcpClient.SendAndWaitInternal(WatsonMessage msg, Int32 timeoutMs, Int64 contentLength, Stream stream)
   at WatsonTcp.WatsonTcpClient.SendAndWaitInternal(WatsonMessage msg, Int32 timeoutMs, Byte[] data)
   at WatsonTcp.WatsonTcpClient.SendAndWait(Dictionary`2 metadata, Int32 timeoutMs, Byte[] data)
   at WatsonTcp.WatsonTcpClient.SendAndWait(Int32 timeoutMs, String data)
   at Client.Program.Main(String[] args) in C:\Users\xxxxx\Source\Repos\WatsonTCP\TestSyncCall\Client\Client\Program.cs:line 33
Write 'q' to quit application or 's' to send async request.

this is the server file:

class Program
{
    static string clientIpPort;
    static WatsonTcpServer srv;

    static void Main(string[] args)
    {
        srv = new WatsonTcpServer("", 23456);
        srv.ClientConnected += Srv_ClientConnected;
        srv.ClientDisconnected += Srv_ClientDisconnected;
        srv.MessageReceived += Srv_MessageReceived;
        srv.SyncRequestReceived = SyncRequestReceived;
        srv.Logger = log;
        srv.DebugMessages = true;
        srv.Start();

        Console.ReadLine();
    }

    private static void log(string txt)
    {
        Console.WriteLine(DateTime.Now.ToString("HH:mm:ss.fff") + " --> " + txt);
    }

    private static void Srv_MessageReceived(object sender, MessageReceivedFromClientEventArgs e)
    {
        Console.WriteLine($"Message received from {e.IpPort}: {Encoding.UTF8.GetString(e.Data)}");
    }



    private static SyncResponse SyncRequestReceived(SyncRequest req)
    {
        Console.WriteLine($"Syncrequest received from {req.IpPort}: {Encoding.UTF8.GetString(req.Data)}");
        SyncResponse ret;

        System.Threading.Thread.Sleep(5000);
        ret = new SyncResponse(req, "Long work done :-)");

        Console.WriteLine("Syncrequest completed");
        return ret;
    }

    private static void Srv_ClientConnected(object sender, ClientConnectedEventArgs e)
    {
        clientIpPort = e.IpPort;
        Console.WriteLine($"Client connected: {e.IpPort}");
    }
    private static void Srv_ClientDisconnected(object sender, ClientDisconnectedEventArgs e)
    {
        clientIpPort = null;
        Console.WriteLine($"Client DISCONNECTED: {e.IpPort}");
    }
}

This is the client:

class Program
{

    static void Main(string[] args)
    {
        WatsonTcpClient cli = new WatsonTcpClient("rds-dev", 23456);
        cli.ServerConnected += Cli_ServerConnected;
        cli.MessageReceived += Cli_MessageReceived;
        cli.DebugMessages = true;
        cli.Logger = log;
        cli.Start();

        Console.WriteLine("Write 'q' to quit application or 's' to send sync request.");
        string read= Console.ReadLine();

        while (read != "q")
        {
            if (read == "s")
            {
                try
                {
                    log("start sync request");
                    SyncResponse rsp = cli.SendAndWait(30000, "Long execution requested");
                    log($"Response from server: {Encoding.UTF8.GetString(rsp.Data)}");
                }
                catch(Exception ex)
                {
                    log(ex.ToString());
                }
            }

            Console.WriteLine("Write 'q' to quit application or 's' to send async request.");
            read = Console.ReadLine();

        }
    }

    private static void log(string txt) {
        Console.WriteLine(DateTime.Now.ToString("HH:mm:ss.fff") + " --> " + txt);
    }

    private static void Cli_MessageReceived(object sender, MessageReceivedFromServerEventArgs e)
    {
        Console.WriteLine($"Message received from server: {Encoding.UTF8.GetString(e.Data)}");
    }

    private static void Cli_ServerConnected(object sender, EventArgs e)
    {
        Console.WriteLine($"Connected to server");
    }
}

thanks for attention 😃 Ozrecsec

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
ozrecseccommented, Apr 14, 2020

I’ve tested directly the 4.02 version and it works great 👍 but only on my local machine… i can’t test with two machines across different timezones thanks bye

1reaction
jchristncommented, Apr 10, 2020

Here you go @ozrecsec - updated in NuGet to v4.0.1. Going on to approve and integrate your PR then will update NuGet with v4.0.2!

NuGet v4.0.1: https://www.nuget.org/packages/WatsonTcp/4.0.1 Commit: https://github.com/jchristn/WatsonTcp/commit/75672a679d2708239f52c625ab6b2f1f958387b8

Thanks again!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Possible concurrency issue in DevTools #9889
I am intercepting traffic using the org.openqa.selenium.devtools.v93.fetch.Fetch class. In rare cases a TimeoutException Unable to process: {" ...
Read more >
Unable to Create Session using org.openqa.selenium. ...
Exception in thread "main" org.openqa.selenium.TimeoutException: java.util.concurrent.TimeoutException Build info: version: '4.0.0-alpha-2', ...
Read more >
Use org.openqa.selenium.devtools.DevToolsException in ...
Want to learn how to use DevToolsException class in org.openqa.selenium.devtools package for your next Selenium project? LambdaTest Automation Testing ...
Read more >
org.seleniumhq.selenium selenium-remote-driver - javadoc.io
A command codec that adheres to the W3C's WebDriver wire protocol. AbstractHttpCommandCodec() - Constructor for class org.openqa.selenium.remote.codec.
Read more >
org.openqa.selenium.devtools.Connection Maven / Gradle ...
The class is part of the package ➦ Group: org.seleniumhq.selenium ➦ Artifact: selenium-devtools ➦ Version: 4.0.0-alpha-3.
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