Skip to content

Commit

Permalink
ipc/tcp stream tests: use dup() to avoid confusion and hang in teardown
Browse files Browse the repository at this point in the history
This was observed only in the select poller, but the behavior of having
the same file descriptor registered in the poller more than once is undefined.
  • Loading branch information
gdamore committed Dec 30, 2024
1 parent fcc3922 commit a74d853
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
5 changes: 5 additions & 0 deletions src/platform/ipc_stream_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ test_ipc_listen_activation(void)
NUTS_PASS(nng_stream_dialer_alloc(&d, addr));

NUTS_PASS(nng_stream_listener_get_int(l1, NNG_OPT_LISTEN_FD, &fd));
fd = dup(fd);
// dupe this because we need to separate the file descriptors to
// prevent confusion when we clean up (only one FD can be registered at
// a time!)
NUTS_ASSERT(fd >= -1);
NUTS_PASS(nng_stream_listener_alloc(&l2, addr));
NUTS_PASS(nng_stream_listener_set_int(l2, NNG_OPT_LISTEN_FD, fd));
nng_stream_dialer_dial(d, aio2);
Expand Down
10 changes: 6 additions & 4 deletions src/platform/tcp_stream_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,6 @@ test_tcp_stream(void)
NUTS_TRUE(sa2.s_in.sa_addr == sa.s_in.sa_addr);
NUTS_TRUE(sa2.s_in.sa_port == sa.s_in.sa_port);

nng_stream_listener_close(l);
nng_stream_dialer_close(d);
nng_stream_listener_stop(l);
nng_stream_dialer_stop(d);
nng_stream_listener_free(l);
nng_stream_dialer_free(d);
nng_aio_free(aio1);
Expand Down Expand Up @@ -214,6 +210,12 @@ test_tcp_listen_activation(void)
NUTS_PASS(nng_stream_dialer_alloc(&d, url));

NUTS_PASS(nng_stream_listener_get_int(l1, NNG_OPT_LISTEN_FD, &fd));
fd = dup(fd);
// dupe this because we need to separate the file descriptors to
// prevent confusion when we clean up (only one FD can be registered at
// a time!)
NUTS_ASSERT(fd >= -1);

NUTS_PASS(nng_stream_listener_alloc(&l2, "tcp4://"));
NUTS_PASS(nng_stream_listener_set_int(l2, NNG_OPT_LISTEN_FD, fd));
nng_stream_dialer_dial(d, aio2);
Expand Down

0 comments on commit a74d853

Please sign in to comment.