zeromq / jeromq

Pure Java ZeroMQ
Mozilla Public License 2.0
2.34k stars 484 forks source link

ZMonitor stuck on close #984

Open inad9300 opened 3 months ago

inad9300 commented 3 months ago

I have a setup like the following (in version 0.5.4):

monitor = new ZMonitor(context, socket);
monitor.add(CONNECTED, DISCONNECTED);
monitor.start();
monitorFuture = runAsync(() -> {
    while (!closed) {
        var event = monitor.nextEvent(1000);
        if (event != null)
            // Log event...
    }
});

...

closed = true;
monitor.close();
context.close();

From time to time, monitor.close() gets stuck, using 100% of a CPU, while context.close() never gets to run. (Meantime, the monitoring thread manages to effectively terminate.)

inad9300 commented 3 months ago

I confirm the same behavior with 0.6.0.

inad9300 commented 3 months ago

Commenting out monitor.close() above leads me to the following occasional exception:

Exception in thread "reaper-1" java.lang.AssertionError
        at zmq.Own.unregisterTermAck(Own.java:228)
        at zmq.SocketBase.pipeTerminated(SocketBase.java:1403)
        at zmq.pipe.Pipe.processPipeTermAck(Pipe.java:413)
        at zmq.ZObject.processCommand(ZObject.java:91)
        at zmq.Command.process(Command.java:79)
        at zmq.SocketBase.processCommands(SocketBase.java:1178)
        at zmq.SocketBase.inEvent(SocketBase.java:1336)
        at zmq.poll.Poller.run(Poller.java:275)