zeromq / netmq

A 100% native C# implementation of ZeroMQ for .NET
Other
2.94k stars 742 forks source link

Subscriber sockets not receiving data in linux on .NET 6 #1026

Closed timfarrar closed 2 years ago

timfarrar commented 2 years ago

Environment

NetMQ Version:    4.0.1.8
Operating System: linux  Ubuntu-20.04
.NET Version:  6.0.302   

Expected behaviour

Subscriber socket on TCP should receive messages on linux as well as Windows when publisher is on Windows using libzmq

Actual behaviour

Subscriber socket on TCP on linux never gets any messages Response socket works as expected

Steps to reproduce the behaviour

protected void RunZMQSubThread()
{
    // [various thread setup stuff here] 

    String ZMQSubscriberURL = "tcp://localhost:5557";
    String topic = "";
    Console.WriteLine("ZMQ Subscriber listening on {0}", ZMQSubscriberURL);
    using (var subSocket = new SubscriberSocket())
    {
        Console.WriteLine("ZMQ Subscriber connecting");
        subSocket.Connect(ZMQSubscriberURL);
        Console.WriteLine("ZMQ Subscriber subscribing to topic {0}", topic);
        subSocket.Subscribe(topic);

        byte[] data = null;
        Msg msg = new Msg();
        msg.InitEmpty();

        while (myThreadIsRunning)
        {
            if (responseSocket.TryReceive(ref msg, new TimeSpan(0, 0, 0, 0, 10)))
            {
                Console.WriteLine("Got data");
            }
        }
    }

   // [thread shutdown stuff here]
}

This code works fine with running in Windows, but not in linux.

The program this thread is in is running before the publisher is running.

I have run it with a NetMQMonitor. It shows a continuous pattern of connect delayed, connect retried, closed as the thread loops. (as expected)

When the publisher starts, on Windows it will show a connect from the monitor, and will start to receive data, but not when running on linux.

On another thread, we have a ResponseSocket listening on another port. That works fine in both Windows and linux.

The publisher is in C++, using libzmq. It is sending large (1.5 MB or so) byte arrays on a regular basis. It is using

zmq_msg_init_data(); // with the zmq_free callback to free the buffer after transmission
zmq_msg_send();
zmq_msg_close();
timfarrar commented 2 years ago

After further investigation, it's not clear to me that the issue has anything to do with .NET 6 on linux. I'm going to close until I get a better understanding of the problem.