Skip to content
Snippets Groups Projects
Commit a92a13c4 authored by Harvey Tuch's avatar Harvey Tuch
Browse files

Fix server_ssl.c thread race exposed by tsan by using gpr_event.

parent 27c876ec
No related branches found
No related tags found
No related merge requests found
...@@ -43,6 +43,7 @@ ...@@ -43,6 +43,7 @@
#include <grpc/support/alloc.h> #include <grpc/support/alloc.h>
#include <grpc/support/log.h> #include <grpc/support/log.h>
#include <grpc/support/string_util.h> #include <grpc/support/string_util.h>
#include <grpc/support/sync.h>
#include <grpc/support/thd.h> #include <grpc/support/thd.h>
#include "src/core/lib/iomgr/load_file.h" #include "src/core/lib/iomgr/load_file.h"
#include "test/core/util/port.h" #include "test/core/util/port.h"
...@@ -53,7 +54,7 @@ ...@@ -53,7 +54,7 @@
#define SSL_CA_PATH "src/core/lib/tsi/test_creds/ca.pem" #define SSL_CA_PATH "src/core/lib/tsi/test_creds/ca.pem"
// Handshake completed signal to server thread. // Handshake completed signal to server thread.
static bool client_handshake_complete = false; static gpr_event client_handshake_complete;
static int create_socket(int port) { static int create_socket(int port) {
int s; int s;
...@@ -111,7 +112,7 @@ static void server_thread(void *arg) { ...@@ -111,7 +112,7 @@ static void server_thread(void *arg) {
// Wait a bounded number of time until client_handshake_complete is set, // Wait a bounded number of time until client_handshake_complete is set,
// sleeping between polls. // sleeping between polls.
int retries = 10; int retries = 10;
while (!client_handshake_complete && retries-- > 0) { while (!gpr_event_get(&client_handshake_complete) && retries-- > 0) {
const gpr_timespec cq_deadline = GRPC_TIMEOUT_SECONDS_TO_DEADLINE(1); const gpr_timespec cq_deadline = GRPC_TIMEOUT_SECONDS_TO_DEADLINE(1);
grpc_event ev = grpc_completion_queue_next(cq, cq_deadline, NULL); grpc_event ev = grpc_completion_queue_next(cq, cq_deadline, NULL);
GPR_ASSERT(ev.type == GRPC_QUEUE_TIMEOUT); GPR_ASSERT(ev.type == GRPC_QUEUE_TIMEOUT);
...@@ -143,7 +144,7 @@ static bool server_ssl_test(const char *alpn_list[], unsigned int alpn_list_len, ...@@ -143,7 +144,7 @@ static bool server_ssl_test(const char *alpn_list[], unsigned int alpn_list_len,
grpc_init(); grpc_init();
int port = grpc_pick_unused_port_or_die(); int port = grpc_pick_unused_port_or_die();
client_handshake_complete = false; gpr_event_init(&client_handshake_complete);
// Launch the gRPC server thread. // Launch the gRPC server thread.
gpr_thd_options thdopt = gpr_thd_options_default(); gpr_thd_options thdopt = gpr_thd_options_default();
...@@ -233,7 +234,7 @@ static bool server_ssl_test(const char *alpn_list[], unsigned int alpn_list_len, ...@@ -233,7 +234,7 @@ static bool server_ssl_test(const char *alpn_list[], unsigned int alpn_list_len,
success = false; success = false;
} }
} }
client_handshake_complete = true; gpr_event_set(&client_handshake_complete, &client_handshake_complete);
SSL_free(ssl); SSL_free(ssl);
gpr_free(alpn_protos); gpr_free(alpn_protos);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment