From c239e0416d54c0a19b55a056fa1c92bbd400cac7 Mon Sep 17 00:00:00 2001
From: Soheil Hassas Yeganeh <soheil@google.com>
Date: Sun, 31 Mar 2019 20:18:13 -0400
Subject: [PATCH] Initialize time as part of basic initialization.

`gpr_time_init` must happen in `do_basic_init`, because
for normal initialization we may need the precise clock
(e.g., if profilers are enabled).

Otherwise, we will have an stack overflow.

Fixes #18589
---
 src/core/lib/surface/init.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/core/lib/surface/init.cc b/src/core/lib/surface/init.cc
index fdb584da68f..b67d4f12252 100644
--- a/src/core/lib/surface/init.cc
+++ b/src/core/lib/surface/init.cc
@@ -73,6 +73,7 @@ static void do_basic_init(void) {
   g_shutting_down = false;
   grpc_register_built_in_plugins();
   grpc_cq_global_init();
+  gpr_time_init();
   g_initializations = 0;
 }
 
@@ -132,7 +133,6 @@ void grpc_init(void) {
     }
     grpc_core::Fork::GlobalInit();
     grpc_fork_handlers_auto_register();
-    gpr_time_init();
     gpr_arena_init();
     grpc_stats_init();
     grpc_slice_intern_init();