zeromq/clrzmq

Timeout on Receive results in ArgumentOutOfRangeException

Closed this issue · 2 comments

When using the string-based receive API, a receive that times out (tested on a SUB socket) results in an exception attempting to decode the buffer into a string. Using the byte array API works fine. Console app reproduction example below:

public class Program
{
    static void Main(string[] args)
    {
        var ctx = ZmqContext.Create();
        ZmqSocket socket = ctx.CreateSocket(SocketType.SUB);
        socket.Connect("tcp://localhost:8888");

        // Fails
        var message = socket.Receive(Encoding.UTF8, TimeSpan.FromSeconds(2));
        //  EXCEPTION STACK TRACE: 
        //  at System.Text.UTF8Encoding.GetString(Byte[] bytes, Int32 index, Int32 count)
        //  at ZeroMQ.SendReceiveExtensions.Receive(ZmqSocket socket, Encoding encoding, TimeSpan timeout) 
        //      in c:\Users\Johnny\Documents\Projects\clrzmq\src\ZeroMQ\SendReceiveExtensions.cs:line 219

        // Works
        //var buffer = new byte[0];
        //socket.Receive(buffer, TimeSpan.FromSeconds(2));
        //var message = Encoding.UTF8.GetString(buffer);

        Console.WriteLine("Received {0}", message);
        Console.ReadLine();
    }
}
jgoz commented

Thank you for submitting this. I'll investigate it ASAP.

jgoz commented

This was fixed as part of #80 and will be available in the next release.