We're updating the issue view to help you get more done. 

Assertion failure caused by too many sockets

Description

I was stress-testing a my language bindings (LabVIEW) and came across an assertion failure if too many sockets are created, as demonstrated by the below test-program

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 #include <zmq.h> #include <stdio.h> #include <stdlib.h> int main( int nargs, char** args ) { int i, N = 1024; void *ctx = zmq_ctx_new(); void **socks; if ( nargs > 1 ) N = atoi( args[1] ); socks = calloc( N, sizeof( void* )); printf( "Creating %i sockets\n", N ); for ( i = 0; i < N; ++i ) { socks[i] = zmq_socket( ctx, ZMQ_PAIR ); if ( !socks[i] ) { printf( "%i: %s\n", i, zmq_strerror( zmq_errno())); break; } } N = i; printf( " %i sockets created\n",i ); for ( i = 0; i < N; ++i ) if ( socks[i] ) zmq_close( socks[i] ); free( socks ); puts( "Destroy" ); zmq_ctx_destroy( ctx ); return 0; }

The behaviour of this code depends on OS - I have tested on Win7 (32-bit) and Gentoo (3.8.13/32-bit) both with zmq v3.2.4

On Win7 machine, the code executes properly for N<1024, has an assertion failure for N=1024, and returns EMFILE for N>1024, then assertion fails at the context destroy. The assertion failure is

Assertion failed: fds.size () <= FD_SETSIZE (..\..\..\src\select.cpp:70)

On Gentoo the critical number is more like 1016 (varies), but the assertion failure occurs at zmq_socket:

Too many open files (signaler.cpp:234)

It seems like something is not quite right with handling too many sockets; I would expect a return code like EMFILE not assertion failure if a user errs and too many sockets get created.

Obviously creating this many sockets is not "normal operation", but it has arisen in a debugging situation, and the assertion failure occurring on ctx_destroy on Win7 caused some confusion.

Environment

Win7 (32-bit) MSVC10, Gentoo 3.8.13 GCC 4.6.3

Status

Assignee

Unassigned

Reporter

Martijn Jasperse

Labels

None

Components

Fix versions

Affects versions

3.2.4

Priority

Major