From: Tobias Brunner Date: Tue, 6 Sep 2022 13:31:41 +0000 (+0200) Subject: unit-tests: Let the TLS server thread close its own socket X-Git-Tag: 5.9.8dr3~4 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=55f7268eb12a386526da05dd93591b380b1670b3;p=thirdparty%2Fstrongswan.git 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. --- diff --git a/src/libtls/tests/suites/test_socket.c b/src/libtls/tests/suites/test_socket.c index 369685fff2..2c75d9efc3 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; }