zeromq / jzmq

Java binding for ZeroMQ
http://www.zeromq.org
GNU General Public License v3.0
590 stars 364 forks source link

org.zeromq.ZMQException: Socket operation on non-socket #443

Open jivk opened 8 years ago

jivk commented 8 years ago

I am using a DEALER-ROUTER socket combination with an in process endpoint to send messages within my application. Message is sent through a DEALER socket, received via the ROUTER socket. Both sockets are created by the same Context. Below is the code that handles receipt of messages from the ROUTER socket.

    final byte[] identity = getSocket().recv();
    final String senderId = new String(identity);

    final LinkedList<byte[]> messageParts = new LinkedList<>();
    messageParts.add(getSocket().recv());
    while (getSocket().hasReceiveMore()) {
        messageParts.add(getSocket().recv());
    }

    getLogger().info("Received Command from [{}] with part count [{}]", senderId, messageParts.size());
    final ControlCommand command = getCodec().decode(messageParts);
    command.execute(ioLoop);

    getSocket().send(identity, ZMQ.SNDMORE);
    getSocket().send("EXECUTED");

Immediately after reading the message, executing an action, it replies back. However, the first socket send is causing the following exception to be thrown.

    org.zeromq.ZMQException: Socket operation on non-socket
        at org.zeromq.ZMQ$Socket.send(Native Method) ~[jzmq-jni-0-SNAPSHOT.jar:${buildNumber} 2016-10-04 16:25 +0100]
        at org.zeromq.ZMQ$Socket.send(ZMQ.java:1665) ~[jzmq-jni-0-SNAPSHOT.jar:${buildNumber} 2016-10-04 16:25 +0100]

Please can you help me understand what is wrong?

jivk commented 7 years ago

Can anyone help with this? Do I need to post more detail?

jivk commented 7 years ago

@armen @trevorbernard @saarons @ellisonbg @jleahy Can anyone help with this query?

trevorbernard commented 7 years ago

I would also poll the zeromq mailing list. This error is coming from libzmq and being propagated as ZMQException.

jivk commented 7 years ago

I have subscribed to the mailing list. However I don't need to post this question anymore as I have figured out what the problem was.

TheMaverickProgrammer commented 7 years ago

What was the problem @jivk ? I have found this issue on many forums and am having this problem myself.

jivk commented 7 years ago

I think this message occurs whenever you try to do an operation on a socket that has been closed. Message is very misleading in that respect.