]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
unit-tests: Let the TLS server thread close its own socket
authorTobias Brunner <tobias@strongswan.org>
Tue, 6 Sep 2022 13:31:41 +0000 (15:31 +0200)
committerTobias Brunner <tobias@strongswan.org>
Tue, 6 Sep 2022 13:40:32 +0000 (15:40 +0200)
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

index 369685fff2cfd6cdaafed1e092ab0d4238dd2ffd..2c75d9efc3a0a5b01a6a86f68a0b84d52f7efcd8 100644 (file)
@@ -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;
 }