diff --git a/src/core/surface/channel_create.c b/src/core/surface/channel_create.c index 3291ac3a4a69e376b8c279a240400b5b21f1551e..921f8c275eb2e0df5c17669aff9d15eb8c6c36c2 100644 --- a/src/core/surface/channel_create.c +++ b/src/core/surface/channel_create.c @@ -82,7 +82,10 @@ static void connector_unref(grpc_exec_ctx *exec_ctx, grpc_connector *con) { } } -static void do_nothing(grpc_exec_ctx *exec_ctx, void *arg, int success) {} +static void on_initial_connect_string_sent(grpc_exec_ctx *exec_ctx, void *arg, + int success) { + connector_unref(exec_ctx, arg); +} static void connected(grpc_exec_ctx *exec_ctx, void *arg, int success) { connector *c = arg; @@ -90,10 +93,12 @@ static void connected(grpc_exec_ctx *exec_ctx, void *arg, int success) { grpc_endpoint *tcp = c->tcp; if (tcp != NULL) { if (!GPR_SLICE_IS_EMPTY(c->args.initial_connect_string)) { - grpc_closure_init(&c->initial_string_sent, do_nothing, NULL); + grpc_closure_init(&c->initial_string_sent, on_initial_connect_string_sent, + c); gpr_slice_buffer_init(&c->initial_string_buffer); gpr_slice_buffer_add(&c->initial_string_buffer, c->args.initial_connect_string); + connector_ref(arg); grpc_endpoint_write(exec_ctx, tcp, &c->initial_string_buffer, &c->initial_string_sent); } diff --git a/test/core/client_config/set_initial_connect_string_test.c b/test/core/client_config/set_initial_connect_string_test.c index 0b51eba73230475f3c82118918819fd77183b4c8..13517b7c1f591d6ea8a701edb5483855f0e3e9b6 100644 --- a/test/core/client_config/set_initial_connect_string_test.c +++ b/test/core/client_config/set_initial_connect_string_test.c @@ -48,7 +48,7 @@ struct rpc_state { char *target; - grpc_credentials *creds; + grpc_channel_credentials *creds; grpc_completion_queue *cq; grpc_channel *channel; grpc_call *call; @@ -145,7 +145,7 @@ static void cleanup_rpc(void) { grpc_event ev; gpr_slice_buffer_destroy(&state.incoming_buffer); gpr_slice_buffer_destroy(&state.temp_incoming_buffer); - grpc_credentials_unref(state.creds); + grpc_channel_credentials_unref(state.creds); grpc_call_destroy(state.call); grpc_completion_queue_shutdown(state.cq); do { diff --git a/test/core/util/test_tcp_server.c b/test/core/util/test_tcp_server.c index e78d83005828b7872c85c7cd6d6dee4509b2de16..c700d3637f4a6e0834fbad6cb57d1a25183bd4bd 100644 --- a/test/core/util/test_tcp_server.c +++ b/test/core/util/test_tcp_server.c @@ -49,6 +49,7 @@ void test_tcp_server_init(test_tcp_server *server, grpc_tcp_server_cb on_connect, void *user_data) { grpc_init(); server->tcp_server = NULL; + server->shutdown = 0; grpc_pollset_init(&server->pollset); server->pollsets[0] = &server->pollset; server->on_connect = on_connect; @@ -90,16 +91,29 @@ void test_tcp_server_poll(test_tcp_server *server, int seconds) { grpc_exec_ctx_finish(&exec_ctx); } -static void do_nothing(grpc_exec_ctx *exec_ctx, void *ignored, int success) {} +static void on_server_destroyed(grpc_exec_ctx *exec_ctx, void *data, + int success) { + test_tcp_server *server = data; + server->shutdown = 1; +} + +static void do_nothing(grpc_exec_ctx *exec_ctx, void *arg, int success) {} void test_tcp_server_destroy(test_tcp_server *server) { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_closure do_nothing_closure[2]; - grpc_closure_init(&do_nothing_closure[0], do_nothing, NULL); - grpc_closure_init(&do_nothing_closure[1], do_nothing, NULL); - grpc_tcp_server_destroy(&exec_ctx, server->tcp_server, - &do_nothing_closure[0]); - grpc_pollset_shutdown(&exec_ctx, &server->pollset, &do_nothing_closure[1]); + gpr_timespec shutdown_deadline; + grpc_closure server_shutdown_cb; + grpc_closure do_nothing_cb; + grpc_closure_init(&server_shutdown_cb, on_server_destroyed, server); + grpc_closure_init(&do_nothing_cb, do_nothing, NULL); + grpc_tcp_server_destroy(&exec_ctx, server->tcp_server, &server_shutdown_cb); + shutdown_deadline = gpr_time_add(gpr_now(GPR_CLOCK_MONOTONIC), + gpr_time_from_seconds(5, GPR_TIMESPAN)); + while (!server->shutdown && + gpr_time_cmp(gpr_now(GPR_CLOCK_MONOTONIC), shutdown_deadline) < 0) { + test_tcp_server_poll(server, 1); + } + grpc_pollset_shutdown(&exec_ctx, &server->pollset, &do_nothing_cb); grpc_exec_ctx_finish(&exec_ctx); grpc_pollset_destroy(&server->pollset); grpc_shutdown(); diff --git a/test/core/util/test_tcp_server.h b/test/core/util/test_tcp_server.h index 448d8f963327fa13a4182f21164e97452241d3f0..deb65eef119fa23227fa9dc3474360f1278115dd 100644 --- a/test/core/util/test_tcp_server.h +++ b/test/core/util/test_tcp_server.h @@ -39,6 +39,7 @@ typedef struct test_tcp_server { grpc_tcp_server *tcp_server; + int shutdown; grpc_pollset pollset; grpc_pollset *pollsets[1]; grpc_tcp_server_cb on_connect;