linux: tcp_multi_accept2 hangs when binding to random loopback addresses #757

Closed
bnoordhuis opened this Issue Mar 30, 2013 · 0 comments

Projects

None yet

1 participant

@bnoordhuis
diff --git a/test/benchmark-multi-accept.c b/test/benchmark-multi-accept.c
index c6333e7..d9eb1c5 100644
--- a/test/benchmark-multi-accept.c
+++ b/test/benchmark-multi-accept.c
@@ -21,6 +21,7 @@

 #include "task.h"
 #include "uv.h"
+#include <string.h>

 #define IPC_PIPE_NAME TEST_PIPENAME
 #define NUM_CONNECTS  (250 * 1000)
@@ -101,6 +102,19 @@ static void cl_close_cb(uv_handle_t* handle);
 static struct sockaddr_in listen_addr;


+/* Bind to random loopback address in the range 127.0.0.1-127.255.255.254. */
+static void random_loopback_bind(handle_storage_t* handle) {
+  struct sockaddr_in in;
+  unsigned addr;
+  addr = 0x7f000001 + rand() % 0xfffffc;
+  memset(&in, 0, sizeof(in));
+  in.sin_family = AF_INET;
+  in.sin_port = 0;
+  in.sin_addr.s_addr = htonl(addr);
+  ASSERT(0 == uv_tcp_bind((uv_tcp_t*) handle, in));
+}
+
+
 static void ipc_connection_cb(uv_stream_t* ipc_pipe, int status) {
   struct ipc_server_ctx* sc;
   struct ipc_peer_ctx* pc;
@@ -333,6 +347,7 @@ static void cl_close_cb(uv_handle_t* handle) {
   }

   ASSERT(0 == uv_tcp_init(handle->loop, (uv_tcp_t*) &ctx->client_handle));
+  random_loopback_bind(&ctx->client_handle);
   ASSERT(0 == uv_tcp_connect(&ctx->connect_req,
                              (uv_tcp_t*) &ctx->client_handle,
                              listen_addr,
@@ -374,6 +389,7 @@ static int test_tcp(unsigned int num_servers, unsigned int num_clients) {
     handle = (uv_tcp_t*) &ctx->client_handle;
     handle->data = "client handle";
     ASSERT(0 == uv_tcp_init(loop, handle));
+    random_loopback_bind(&ctx->client_handle);
     ASSERT(0 == uv_tcp_connect(&ctx->connect_req,
                                handle,
                                listen_addr,

The benchmark eventually hangs in epoll_wait(). It doesn't look like it's port exhaustion because there haven't been that many sockets created by the time it hangs, maybe a few thousand.

I'm running 3.9-rc4 so it might be a kernel bug. Will cross-check with 3.8.

@bnoordhuis bnoordhuis was assigned Mar 30, 2013
@bnoordhuis bnoordhuis removed their assignment May 12, 2015
@bnoordhuis bnoordhuis closed this May 12, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment