Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NullReferenceException from ZeroMQ.ZPollItems.PollIn in ROUTER<-->DEALER communication #210

Open
AntiTenzor opened this issue Sep 13, 2021 · 0 comments

Comments

@AntiTenzor
Copy link

I'm trying to have fun with ROUTER<-->DEALER scenario.

To avoid blocking reads I try to poll ROUTER socket before reading data from it.
But my router becomes crazy from time to time.
I do not know at the moment how to reproduce this situation in a toy project.

Environment:

  • Windows Server 2019 64 bit
  • clrzmq4 (for me it is ZeroMQ.dll) build from recent git.
  • native libzmq.dll (unreleased v4.3.5 from AppVeyor)

Idea of what I do:

// Constructor of a class ZRouter
public ZRouter()
        {
            clrZmqContext = ZContext.Current;

            mainThread = new Thread(mainThreadImpl);

            clrZmqPollIn = ZPollItem.CreateReceiver();
            clrZmqRouter = new ZSocket(clrZmqContext, ZSocketType.ROUTER);
            
            ...
         }

// Later when initialization is done
mainThread.Start();

// There is infinite loop in mainThread:

while(true)
{
  if (!clrZmqRouter.PollIn(clrZmqPollIn, out ZMessage incoming, out ZError error, TimeSpan.FromSeconds(0.7)))
  {
      continue;
  }

  string identity = incoming.PopString();
  string msg = incoming.PopString();
  
  // Further processing
}

// Other threads could send messages from ROUTER to its DEALERS.

The sad part of a story:
After some hours of working I start to get a NullReferenceException from the line
if (!clrZmqRouter.PollIn(clrZmqPollIn, out ZMessage incoming, out ZError error, TimeSpan.FromSeconds(0.7)))

Here is a stack trace:

System.NullReferenceException: Object reference not set to an instance of an object.
   at ZeroMQ.lib.zmq.zmq_poll(Void* items, Int32 numItems, Int64 timeout)
   at ZeroMQ.ZPollItems.Win32.PollSingle(ZSocket socket, ZPollItem item, ZPoll pollEvents, ZError& error, Nullable`1 timeout) in w:\git\clrzmq4\ZPollItems.Win32.cs:line 79
   at ZeroMQ.ZPollItems.Poll(ZSocket socket, ZPollItem item, ZPoll pollEvents, ZMessage& message, ZError& error, Nullable`1 timeout) in w:\git\clrzmq4\ZPollItems.cs:line 47
   at ZeroMQ.ZPollItems.PollIn(ZSocket socket, ZPollItem item, ZMessage& incoming, ZError& error, Nullable`1 timeout) in w:\git\clrzmq4\ZPollItems.cs:line 32
   at ZRouter.ZRouter.mainThreadImpl() in W:\...\ZRouter\ZRouter.cs:line 185

Is ZSocket thread safe for multithreaded environment?
Should I create special ZContext inside mainThread?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant