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.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user