[zeromq-dev] Address in use error when re-binding socket

Matthias Kluwe mkluwe at gmail.com
Sat Apr 5 15:19:04 CEST 2014


Hi!

I noticed some unexpected behaviour when trying to re-use a closed
socket in my server. It boils down to this small example:

#include <cassert>
#include <iostream>

#include "zmq.h"

int main() {
    void *ctx = zmq_ctx_new();
    assert( ctx );
    void *skt;

    skt = zmq_socket( ctx, ZMQ_REP );
    assert( skt );
    assert( zmq_bind( skt, "tcp://*:5555" ) == 0 );
    assert( zmq_close( skt ) == 0 );

    skt = zmq_socket( ctx, ZMQ_REP );
    assert( skt );
    int fail = 0;
    while ( zmq_bind( skt, "tcp://*:5555" ) ) { ++fail; }
    std::cout << fail << std::endl;
}

I'm using ZeroMQ 4.0.3 on Windows XP SP3, compiler is VS 2008.
libzmq.dll has been built with the provided Visual Studio solution.

This prints 1 here when doing a "Debug" build (both of the code above
and of libzmq.dll) and 0 using a "Release" build. Strange enough, when
running the code above with mixed build configuration (Debug with
Release lib), fail counts up to 6.

I've posted this on SO
(http://stackoverflow.com/questions/22656225/zeromq-address-in-use-error-when-re-binding-socket)
and it was suggested that the problem might be that the TCP socket
entered the TIME-WAIT state. Is that correct?

Regards,
Matthias



More information about the zeromq-dev mailing list