Skip to content

socket.send() hangs forever when trying to send data to unbound socket with inproc protocol #34

Description

@SlavikBaranov

Here is minimal testcase:

package jmqtest;

import java.util.Arrays;
import org.jeromq.ZMQ;

public class JmqTest {

    public static String endpoint = "inproc://service1";
    //public static String endpoint = "tcp://127.0.0.1:10050";
    private static ZMQ.Context ctx = ZMQ.context(1);
    private static byte[] msg = new byte[] {1, 2, 3};

    private static final Runnable r = new Runnable() {

        @Override
        public void run() {
            ZMQ.Socket server = ctx.socket(ZMQ.REP);
            try {
                Thread.sleep(1000);
            } catch (InterruptedException ex) {
                System.out.println(ex);
            }
            server.bind(endpoint);
            byte[] recMsg = server.recv(0);
            boolean r = Arrays.equals(msg, recMsg);
            System.out.println(r ? "OK" : "Wrong message received");
            server.close();
        }

    };

    public static void main(String[] args) throws Exception {
        Thread t = new Thread(r);
        t.start();
        //Thread.sleep(1000);
        ZMQ.Socket client = ctx.socket(ZMQ.REQ);
        client.connect(endpoint);
        client.send(msg, 0);
        System.out.println("Waiting for thread to receive message...");
        t.join();
        client.close();
        ctx.term();
    }
}

When using jzmq instead of jeromq (change import in line 4), following exception is thrown:

Exception in thread "main" org.zeromq.ZMQException: Connection refused(0x3d)
at org.zeromq.ZMQ$Socket.connect(Native Method)
at jmqtest.JmqTest.main(JmqTest.java:37)

If bind() occurs before connect() (comment out lines 18-22 and uncomment line 35) everything works fine.

When using tcp transport instead of inproc (lines 8-9), late binding occurs and everything works fine too.

From the convenience point of view, late binding on inproc sockets would be ideal. From the interoperability point of view, exception on connect() should be thrown. In current state it's hard to diagnose, for example, misspelling of socket names in bind() and connect().

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions