jzmq icon indicating copy to clipboard operation
jzmq copied to clipboard

Java server cannot handle more than 62 connections at a time.

Open ghost opened this issue 11 years ago • 1 comments

I have a C++ client application which tries to create lots of ZeroMQ sockets and connections to a java server. The server side is using a combination of ROUTER/DEALER sockets. The problem I have is that my application crashes after exactly 62 connection establishments, where I send one message per connection. The application blocks when it hits this limit and then crashes due to some ZeroMQ code. The crash does not report any type of bug. It simply crashes. During tests my observation was that the crash resulted from a "poll"-method call of a ZMQ.Poller object. I don't think that the number 62 is specific to my application. This error prevents my server to accept more than 62 clients at a time, the most severe thing is that it simply crashes without any noise.

My configuration is this:

  • libzmq 3.2.2, current git repository version
  • jzmq, current git repository version (+ JDK 1.7.11)
  • Windows 8
  • compiled using MSVC 10 / 11

I managed to reproduce that error using this simplified Java server using jzmq:

public class AsyncServer {

    public static long getNumberFrom(byte[] bytes){
        long value = 0;
        for (int i = 0; i < bytes.length; i++)
        {
           value = (value << 8) + (bytes[i] & 0xff);
        }
        return value;
    }

    public static void main(String[] args){
        final Context context = ZMQ.context(1);

        ZMQ.Socket frontend = context.socket(ZMQ.ROUTER);
        frontend.bind("tcp://*:5050");

        ZMQ.Socket workers = context.socket(ZMQ.DEALER);
        workers.bind("inproc://workers");

        new Thread(){
            @Override
            public void run(){
                ZMQ.Socket wr = context.socket(ZMQ.DEALER);
                wr.connect("inproc://workers");

                while (true) {
                    byte connectionID[] = wr.recv(0);
                    byte msg[] = wr.recv(0);

                    System.out.println(getNumberFrom(connectionID) + " joined.");

                    wr.send(connectionID, ZMQ.SNDMORE);
                    wr.send(msg, 0);
                }
            }
        }.start();

        ZMQQueue queue = new ZMQQueue(context, frontend, workers);
        queue.run();
    }
}

And the Client is this (C++) using libzmq 3.2.2:

    while(1){
    char addr[28];

    sprintf(addr, "tcp://%s:%d", "127.0.0.1", 5050);

    void* context = zmq_ctx_new();
    void* socket = zmq_socket(context, ZMQ_DEALER);

    zmq_connect(socket, addr);
    zmq_msg_t zmsg;

    zmq_msg_init_size(&zmsg, 6);
    memcpy(zmq_msg_data(&zmsg), "Hello!", 6);
    zmq_msg_send(&zmsg, socket, 0);
    zmq_msg_close(&zmsg);

    Sleep(100);
    }

ghost avatar Apr 10 '13 20:04 ghost

@alecz Do you think you are having the same problem as this?

http://stackoverflow.com/questions/17209790/zeromq-pull-push-client-crashes-after-upon-connection-of-31-server-on-windows/17222309#17222309

trevorbernard avatar Jun 25 '13 02:06 trevorbernard