weixin_39908985 2020-11-30 07:20
浏览 0

Race condition in ZLoop

Looks like there is some issue in ZLoop: as long as I interrupt the thread for loop, the ZContext cannot be destroyed. It is stuck on waiting for in the Ctx:


//  Wait till reaper thread closes all the sockets.
Command cmd = termMailbox.recv(WAIT_FOREVER);

Sometimes it can pass though, but in most cases it looks like in dead lock situation. Here is some test-case to reproduce:



    public void test() throws InterruptedException {
        ExecutorService executorService = Executors.newFixedThreadPool(1);

        ZContext ctx = new ZContext();

        ZMQ.Socket socket = ctx.createSocket(SocketType.PULL);
        socket.bind("ipc://test");

        ZLoop zLoop = new ZLoop(ctx);

        ZMQ.PollItem pollItem = new ZMQ.PollItem(socket, ZMQ.Poller.POLLIN);

        zLoop.addPoller(pollItem, (loop, item, arg) -> 0, null);

        Future<integer> future = executorService.submit(zLoop::start);

        Thread.sleep(1000);

        future.cancel(true);

        socket.close();
        ctx.close();

        executorService.shutdownNow();
    }
</integer>

JeroMQ version is 0.5.2.

I won't mind though if I use this API wrong way: I'm just in the beginning of ZeroMQ journey.

Thanks in advance for any hints!

该提问来源于开源项目:zeromq/jeromq

  • 写回答

0条回答 默认 最新

    报告相同问题?