From 8e3fb8b844ebb3134257577883ba255afeed1f87 Mon Sep 17 00:00:00 2001 From: Hannah Shi Date: Fri, 24 Apr 2020 08:58:42 +0000 Subject: [PATCH] do no re-create persisted channels in forked child process --- src/php/ext/grpc/channel.c | 12 +++++++++--- src/php/ext/grpc/channel.h | 2 ++ src/php/ext/grpc/php_grpc.c | 5 ++--- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/php/ext/grpc/channel.c b/src/php/ext/grpc/channel.c index 059e8333db1..304ed932868 100644 --- a/src/php/ext/grpc/channel.c +++ b/src/php/ext/grpc/channel.c @@ -586,6 +586,13 @@ void php_grpc_delete_persistent_list_entry(char *key, php_grpc_int key_len gpr_mu_unlock(&global_persistent_list_mu); } +// Clean all channels in the persistent list +// Called at post fork +void php_grpc_clean_persistent_list(TSRMLS_D) { + zend_hash_clean(&grpc_persistent_list); + zend_hash_clean(&grpc_target_upper_bound_map); +} + // A destructor associated with each list entry from the persistent list static void php_grpc_channel_plink_dtor(php_grpc_zend_resource *rsrc TSRMLS_DC) { @@ -615,12 +622,11 @@ static void php_grpc_target_bound_dtor(php_grpc_zend_resource *rsrc #ifdef GRPC_PHP_DEBUG /** -* Clean all channels in the persistent. Test only. +* Clean all channels in the persistent * @return void */ PHP_METHOD(Channel, cleanPersistentList) { - zend_hash_clean(&grpc_persistent_list); - zend_hash_clean(&grpc_target_upper_bound_map); + php_grpc_clean_persistent_list(TSRMLS_C); } char *grpc_connectivity_state_name(grpc_connectivity_state state) { diff --git a/src/php/ext/grpc/channel.h b/src/php/ext/grpc/channel.h index ce17c4a58a7..373e9877ea4 100644 --- a/src/php/ext/grpc/channel.h +++ b/src/php/ext/grpc/channel.h @@ -60,6 +60,8 @@ void generate_sha1_str(char *sha1str, char *str, php_grpc_int len); void php_grpc_delete_persistent_list_entry(char *key, php_grpc_int key_len TSRMLS_DC); +void php_grpc_clean_persistent_list(TSRMLS_D); + typedef struct _channel_persistent_le { grpc_channel_wrapper *channel; } channel_persistent_le_t; diff --git a/src/php/ext/grpc/php_grpc.c b/src/php/ext/grpc/php_grpc.c index 6dcfef08814..c2d0fac0f19 100644 --- a/src/php/ext/grpc/php_grpc.c +++ b/src/php/ext/grpc/php_grpc.c @@ -206,9 +206,8 @@ void postfork_child() { grpc_init(); grpc_php_init_completion_queue(TSRMLS_C); - // re-create grpc_channel and point wrapped to it - // unlock wrapped grpc channel mutex - restart_channels(); + // clean all channels in the persistent list + php_grpc_clean_persistent_list(TSRMLS_C); } void postfork_parent() {