From 55f7268eb12a386526da05dd93591b380b1670b3 Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Tue, 6 Sep 2022 15:31:41 +0200 Subject: [PATCH] unit-tests: Let the TLS server thread close its own socket Closing the socket from the main thread, while the server thread is still in accept() (or is just about to enter it), seems to occasionally cause a deadlock on macOS. --- src/libtls/tests/suites/test_socket.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/libtls/tests/suites/test_socket.c b/src/libtls/tests/suites/test_socket.c index 369685fff..2c75d9efc 100644 --- a/src/libtls/tests/suites/test_socket.c +++ b/src/libtls/tests/suites/test_socket.c @@ -493,13 +493,17 @@ START_TEARDOWN(teardown_creds) if (server_config) { shutdown(server_config->fd, SHUT_RDWR); - close(server_config->fd); free(server_config); server_config = NULL; } } END_TEARDOWN +static void close_fd_ptr(void *fd) +{ + close(*(int*)fd); +} + /** * Run an echo server */ @@ -519,6 +523,7 @@ static job_requeue_t serve_echo(echo_server_config_t *config) } sfd = config->fd; thread_cleanup_push((thread_cleanup_t)server->destroy, server); + thread_cleanup_push(close_fd_ptr, &sfd); while (TRUE) { oldstate = thread_cancelability(TRUE); @@ -554,6 +559,7 @@ static job_requeue_t serve_echo(echo_server_config_t *config) close(cfd); } thread_cleanup_pop(TRUE); + thread_cleanup_pop(TRUE); return JOB_REQUEUE_NONE; }