[zeromq-dev] Assertion failed: Address already in use

Pieter Hintjens ph at imatix.com
Thu Jun 5 11:01:39 CEST 2014


Right, I appreciate that the point of the test was to break things.

Doing a little research, I see that Windows will sometimes return
WSAEADDRINUSE when reconnecting to a port. It's not what you'd expect,
and the code does not handle it, and so asserts. See
http://dev.mainsoft.com/Default.aspx?tabid=107.

Would you add a test for err = WSAEADDRINUSE to that code and rerun
the test case. I'd expect that the error will provoke a reconnect, if
the thread gives the socket time for that, and nothing if the socket
is closed too rapidly.

If it works, we can make a pull request. Thanks for working through
this. ZeroMQ should assert only when it's gotten into an inconsistent
state.

-Pieter

On Wed, Jun 4, 2014 at 9:14 PM, Matthias Kluwe <mkluwe at gmail.com> wrote:
> Hi!
>
> I tried the current master today: Same result, except that the assertion
> moved to line 323 in tcp_connecter.cpp.
>
> Just a side note: Although I did have the feeling that you "should not
> do" what my test code does, I did write that in purpose to see what
> problems I might run into. In fact, it was *meant* to provoke an error
> (to test some code of mine, and to see what kind of diagnostic I'd be
> able to provide).
>
> Matthias
>
> Am 04.06.2014 11:09, schrieb Pieter Hintjens:
>> It may well be a Windows issue.
>>
>> You're right that the exception should not be escaping. It's also a
>> strange error to get in the tcp_connector... Could you test again with
>> the current master, and perhaps we can dig in to see what's happening.
>>
>> -Pieter
>>
>> On Wed, Jun 4, 2014 at 7:33 AM, Matthias Kluwe <mkluwe at gmail.com> wrote:
>>> Obviously it is. I won't really do this in real code.
>>>
>>> I just was surprised by the uncaught exception escaping from the library.
>>>
>>> Perhaps this is a Windows specific issue. The test code runs for hours on my
>>> Ubuntu box.
>>>
>>> Am 03.06.2014 22:43 schrieb "Pieter Hintjens" <ph at imatix.com>:
>>>
>>>> It's poor design to bind on the same port over and over like this.
>>>> There are timing dependent tear-downs that will hit. E.g. as long as
>>>> there's a pending connection, the bound address won't be free for new
>>>> binds.
>>>>
>>>>
>>>> On Tue, Jun 3, 2014 at 10:40 PM, Matthias Kluwe <mkluwe at gmail.com> wrote:
>>>>> Hi!
>>>>>
>>>>> I'm experiencing an unexpected error when using and tearing down a ZMQ
>>>>> context in a rapid sequence. I tried this with Windows XP using ZeroMQ
>>>>> 4.04.
>>>>>
>>>>> Test code is as follows (using a "fresh" REQ-REP connection once in a
>>>>> loop):
>>>>>
>>>>>     #include "zmq.h"
>>>>>     #include <string.h>
>>>>>
>>>>>     int c_send_receive() {
>>>>>         char buf[ 4 ];
>>>>>
>>>>>         void *ctx = zmq_ctx_new();
>>>>>         if ( ctx == 0 ) return 0;
>>>>>
>>>>>         void *rep = zmq_socket( ctx, ZMQ_REP );
>>>>>         if ( rep == 0 ) return 0;
>>>>>         if ( zmq_bind( rep, "tcp://*:5555" ) == -1 ) return 0;
>>>>>
>>>>>         void *req = zmq_socket( ctx, ZMQ_REQ );
>>>>>         if ( req == 0 ) return 0;
>>>>>         if ( zmq_connect( req, "tcp://localhost:5555" ) == -1 )
>>>>>             return 1;
>>>>>
>>>>>         if ( zmq_send( req, "MSG", 3, 0 ) == -1 ) return 0;
>>>>>         memset( buf, 0, 4 );
>>>>>         if ( zmq_recv( rep, buf, 3, 0 ) == -1 ) return 0;
>>>>>         if ( strcmp( "MSG", buf ) != 0 ) return 0;
>>>>>
>>>>>         if ( zmq_close( rep ) == -1 ) return 0;
>>>>>         if ( zmq_close( req ) == -1 ) return 0;
>>>>>         if ( zmq_ctx_term( ctx ) == -1 ) return 0;
>>>>>
>>>>>         return 1;
>>>>>     }
>>>>>
>>>>>     int main() {
>>>>>         while ( c_send_receive() );
>>>>>     }
>>>>>
>>>>> The code above tries to check for all error code (hopefully), but it
>>>>> fails throwing the following exception:
>>>>>
>>>>> Assertion failed: Address already in use
>>>>> (..\..\..\src\tcp_connecter.cpp:284)
>>>>>
>>>>> I guess this is due to ZeroMQ encountering some unexpected condition.
>>>>>
>>>>> Regards,
>>>>> Matthias
>
> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev at lists.zeromq.org
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev



More information about the zeromq-dev mailing list