diff --git a/test/test-ipc-heavy-traffic-deadlock-bug.c b/test/test-ipc-heavy-traffic-deadlock-bug.c index 325305a6442..753fb7b7c20 100644 --- a/test/test-ipc-heavy-traffic-deadlock-bug.c +++ b/test/test-ipc-heavy-traffic-deadlock-bug.c @@ -55,7 +55,7 @@ static void write_cb(uv_write_t* req, int status) { } static void shutdown_cb(uv_shutdown_t* req, int status) { - ASSERT(status == 0); + ASSERT(status == 0 || status == UV_ENOTCONN); uv_close((uv_handle_t*) req->handle, NULL); } diff --git a/test/test-ipc.c b/test/test-ipc.c index 71d977d0f95..26cf1df010f 100644 --- a/test/test-ipc.c +++ b/test/test-ipc.c @@ -39,12 +39,14 @@ static int local_conn_accepted; static int remote_conn_accepted; static int tcp_server_listening; static uv_write_t write_req; +static uv_write_t write_req2; static uv_write_t conn_notify_req; static int close_cb_called; static int connection_accepted; static int tcp_conn_read_cb_called; static int tcp_conn_write_cb_called; static int closed_handle_data_read; +static int closed_handle_write; typedef struct { uv_connect_t conn_req; @@ -54,7 +56,15 @@ typedef struct { #define CONN_COUNT 100 #define BACKLOG 128 -#define LARGE_SIZE 1000000 +#define LARGE_SIZE 100000 + +static uv_buf_t large_buf; +static char buffer[LARGE_SIZE]; +static uv_write_t write_reqs[300]; +static int write_reqs_completed; + +static unsigned int write_until_data_queued(void); +static void send_handle_and_close(void); static void close_server_conn_cb(uv_handle_t* handle) { @@ -574,11 +584,17 @@ static void tcp_connection_write_cb(uv_write_t* req, int status) { static void closed_handle_large_write_cb(uv_write_t* req, int status) { ASSERT(status == 0); ASSERT(closed_handle_data_read = LARGE_SIZE); + if (++write_reqs_completed == ARRAY_SIZE(write_reqs)) { + write_reqs_completed = 0; + if (write_until_data_queued() > 0) + send_handle_and_close(); + } } static void closed_handle_write_cb(uv_write_t* req, int status) { ASSERT(status == UV_EBADF); + closed_handle_write = 1; } @@ -689,7 +705,6 @@ int ipc_helper(int listen_after_write) { * over which a handle will be transmitted. */ struct sockaddr_in addr; - uv_write_t write_req; int r; uv_buf_t buf; @@ -789,26 +804,28 @@ int ipc_helper_tcp_connection(void) { return 0; } - -int ipc_helper_closed_handle(void) { +static unsigned int write_until_data_queued() { + unsigned int i; int r; - struct sockaddr_in addr; - uv_write_t write_req; - uv_write_t write_req2; - uv_buf_t buf; - char buffer[LARGE_SIZE]; - - r = uv_pipe_init(uv_default_loop(), &channel, 1); - ASSERT(r == 0); - uv_pipe_open(&channel, 0); + i = 0; + do { + r = uv_write(&write_reqs[i], + (uv_stream_t*)&channel, + &large_buf, + 1, + closed_handle_large_write_cb); + ASSERT(r == 0); + i++; + } while (((uv_stream_t*)&channel)->write_queue_size == 0 && + i < ARRAY_SIZE(write_reqs)); - ASSERT(1 == uv_is_readable((uv_stream_t*) &channel)); - ASSERT(1 == uv_is_writable((uv_stream_t*) &channel)); - ASSERT(0 == uv_is_closing((uv_handle_t*) &channel)); + return ((uv_stream_t*)&channel)->write_queue_size; +} - memset(buffer, '.', LARGE_SIZE); - buf = uv_buf_init(buffer, LARGE_SIZE); +static void send_handle_and_close() { + int r; + struct sockaddr_in addr; r = uv_tcp_init(uv_default_loop(), &tcp_server); ASSERT(r == 0); @@ -818,26 +835,40 @@ int ipc_helper_closed_handle(void) { r = uv_tcp_bind(&tcp_server, (const struct sockaddr*) &addr, 0); ASSERT(r == 0); - r = uv_write(&write_req, - (uv_stream_t*)&channel, - &buf, - 1, - closed_handle_large_write_cb); - ASSERT(r == 0); - - r = uv_write2(&write_req2, + r = uv_write2(&write_req, (uv_stream_t*)&channel, - &buf, + &large_buf, 1, (uv_stream_t*)&tcp_server, closed_handle_write_cb); ASSERT(r == 0); uv_close((uv_handle_t*)&tcp_server, NULL); +} + +int ipc_helper_closed_handle(void) { + int r; + + memset(buffer, '.', LARGE_SIZE); + large_buf = uv_buf_init(buffer, LARGE_SIZE); + + r = uv_pipe_init(uv_default_loop(), &channel, 1); + ASSERT(r == 0); + + uv_pipe_open(&channel, 0); + + ASSERT(1 == uv_is_readable((uv_stream_t*) &channel)); + ASSERT(1 == uv_is_writable((uv_stream_t*) &channel)); + ASSERT(0 == uv_is_closing((uv_handle_t*) &channel)); + + if (write_until_data_queued() > 0) + send_handle_and_close(); r = uv_run(uv_default_loop(), UV_RUN_DEFAULT); ASSERT(r == 0); + ASSERT(closed_handle_write == 1); + MAKE_VALGRIND_HAPPY(); return 0; } @@ -849,8 +880,6 @@ int ipc_helper_bind_twice(void) { * over which two handles will be transmitted. */ struct sockaddr_in addr; - uv_write_t write_req; - uv_write_t write_req2; int r; uv_buf_t buf;