Skip to content

Commit

Permalink
Fix UTLS remote address test case race
Browse files Browse the repository at this point in the history
Fix race condition in the UTLS remote address test case, where the
connection establishment would occasionally hit the TLS socket (which
is created first), rather than the UX socket, on the test UTLS server
socket.

The false positive was primarily seen on slow machines, when valgrind
was enabled.

Signed-off-by: Mattias Rönnblom <[email protected]>
  • Loading branch information
m-ronnblom committed Nov 2, 2023
1 parent 40f72ac commit 28b6e8a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
19 changes: 19 additions & 0 deletions test/testutil.c
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,25 @@ void tu_wait_for_server_port_binding(const char *ip, uint16_t port)
tu_msleep(10);
}

bool tu_unix_server_bound(const char *path, bool abstract)
{
char npath[strlen(path) + 2];

snprintf(npath, sizeof(npath), "%s%s", abstract ? "@" : "",
path);

int rc = tu_executef_es("netstat -n --unix --listen | grep -q -e ' %s$'",
npath);

return rc == 0;
}

void tu_wait_for_unix_server_binding(const char *path, bool abstract)
{
while (!tu_unix_server_bound(path, abstract))
tu_msleep(10);
}

struct search
{
const char *name;
Expand Down
3 changes: 3 additions & 0 deletions test/testutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ bool tu_is_kernel_at_least(int wanted_major, int wanted_minor);
bool tu_server_port_bound(const char *ip, uint16_t port);
void tu_wait_for_server_port_binding(const char *ip, uint16_t port);

bool tu_unix_server_bound(const char *path, bool abtract);
void tu_wait_for_unix_server_binding(const char *path, bool abstract);

enum tu_cmp_type { cmp_type_none, cmp_type_greater_than, cmp_type_equal };

int tu_assure_bool_attr(struct xcm_socket *s, const char *attr_name,
Expand Down
13 changes: 11 additions & 2 deletions test/xcm_testcases.c
Original file line number Diff line number Diff line change
Expand Up @@ -4155,6 +4155,12 @@ TESTCASE(xcm, tls_missing_certificate)
return UTEST_SUCCESS;
}

static void map_utls_to_ux(const char *utls_addr, char *ux_addr,
size_t capacity)
{
snprintf(ux_addr, capacity, "%s", utls_addr + strlen(XCM_UTLS_PROTO) + 1);
}

TESTCASE_SERIALIZED(xcm, utls_remote_addr)
{
const char *client_msg = "greetings";
Expand All @@ -4166,8 +4172,11 @@ TESTCASE_SERIALIZED(xcm, utls_remote_addr)
CHKNOERR((server_pid = simple_server(NULL, addr, client_msg, server_msg,
NULL, NULL, false)));

/* wait for both UX and TLS sockets to be created */
tu_msleep(500);
char ux_path[64];
map_utls_to_ux(addr, ux_path, sizeof(ux_path));

tu_wait_for_unix_server_binding(ux_path, true);

struct xcm_socket *client_conn = tu_connect_retry(addr, 0);
CHK(client_conn);

Expand Down

0 comments on commit 28b6e8a

Please sign in to comment.