Browse Source

fix: make process.uptime() return the correct time (#19567)

Micha Hanselmann 5 years ago
parent
commit
5614ae4241

+ 1 - 0
patches/node/.patches

@@ -54,3 +54,4 @@ fix_ensure_js2c_maps_internal-fs_streams.patch
 chore_read_nobrowserglobals_from_global_not_process.patch
 chore_use_v8_inspector_js_protocol_to_find_pdl_file.patch
 chore_split_createenvironment_into_createenvironment_and.patch
+fix_set_uptime_offset_in_correct_init_method.patch

+ 1 - 1
patches/node/chore_split_createenvironment_into_createenvironment_and.patch

@@ -8,7 +8,7 @@ This allows us to run operations on a created but not yet bootstrapped
 environment such as setting up an InspectorAgent
 
 diff --git a/src/api/environment.cc b/src/api/environment.cc
-index e313460a13ced7e7a9982db6f4a988699ec56111..faeba6d4e687261df1a58ad3c1e14d53b0e6d832 100644
+index e313460a13ced7e7a9982db6f4a988699ec56111..51353924cb0aef2a61f4aa799b6a90326c7a65ad 100644
 --- a/src/api/environment.cc
 +++ b/src/api/environment.cc
 @@ -269,7 +269,8 @@ Environment* CreateEnvironment(IsolateData* isolate_data,

+ 29 - 0
patches/node/fix_set_uptime_offset_in_correct_init_method.patch

@@ -0,0 +1,29 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Micha Hanselmann <[email protected]>
+Date: Thu, 1 Aug 2019 09:59:48 -0700
+Subject: fix: set uptime offset in correct init method
+
+This patch can be removed after 'https://github.com/nodejs/node/pull/28849' landed here.
+
+diff --git a/src/node.cc b/src/node.cc
+index c0a8bdd28a403b399f2766e40b2fe90e76fca849..193a4b3e91a744b6934658f531b2f46698ad8323 100644
+--- a/src/node.cc
++++ b/src/node.cc
+@@ -624,6 +624,9 @@ int InitializeNodeWithArgs(std::vector<std::string>* argv,
+   // Make sure InitializeNodeWithArgs() is called only once.
+   CHECK(!init_called.exchange(true));
+ 
++  // Initialize node_start_time to get relative uptime.
++  per_process::node_start_time = uv_hrtime();
++
+   // Register built-in modules
+   binding::RegisterBuiltinModules();
+ 
+@@ -810,7 +813,6 @@ void Init(int* argc,
+ InitializationResult InitializeOncePerProcess(int argc, char** argv) {
+   atexit([] () { uv_tty_reset_mode(); });
+   PlatformInit();
+-  per_process::node_start_time = uv_hrtime();
+ 
+   CHECK_GT(argc, 0);
+