From 626a07df5bae2b32f88863edb9f4404b42de1ad6 Mon Sep 17 00:00:00 2001 From: Eugene Ostroukhov Date: Thu, 15 Sep 2016 10:40:22 -0700 Subject: [PATCH] inspector: restore 9229 as a default port Some tools are now relying on 9229 to be node.js "inspector" port (I see Chrome extensions, some online blog posts, etc.) Also, having same default port values for old and new protocols may lead to some confusion, e.g. when tools are trying to autodiscover debuggable Node instances. This is a partial revert of 9f1f7e2. This commit preserves the fix for issue #8201 bringing back the behavior that the old and new protocols run on different ports.run on different ports. PR-URL: https://github.com/nodejs/node/pull/8550 Reviewed-By: ofrobots - Ali Ijaz Sheikh Reviewed-By: cjihrig - Colin Ihrig --- src/node.cc | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/node.cc b/src/node.cc index 6175453a10..be0c42b19f 100644 --- a/src/node.cc +++ b/src/node.cc @@ -147,7 +147,9 @@ static const bool use_inspector = false; static bool use_debug_agent = false; static bool debug_wait_connect = false; static std::string* debug_host; // coverity[leaked_storage] -static int debug_port = 5858; +static const int default_debugger_port = 5858; +static const int default_inspector_port = 9229; +static int debug_port = -1; static const int v8_default_thread_pool_size = 4; static int v8_thread_pool_size = v8_default_thread_pool_size; static bool prof_process = false; @@ -2874,7 +2876,10 @@ static Local GetFeatures(Environment* env) { static void DebugPortGetter(Local property, const PropertyCallbackInfo& info) { - info.GetReturnValue().Set(debug_port); + int port = debug_port; + if (port < 0) + port = use_inspector ? default_inspector_port : default_debugger_port; + info.GetReturnValue().Set(port); } @@ -3765,15 +3770,17 @@ static void DispatchMessagesDebugAgentCallback(Environment* env) { static void StartDebug(Environment* env, const char* path, bool wait) { CHECK(!debugger_running); if (use_inspector) { - debugger_running = v8_platform.StartInspector(env, path, debug_port, wait); + debugger_running = v8_platform.StartInspector(env, path, + debug_port >= 0 ? debug_port : default_inspector_port, wait); } else { env->debugger_agent()->set_dispatch_handler( DispatchMessagesDebugAgentCallback); const char* host = debug_host ? debug_host->c_str() : "127.0.0.1"; + int port = debug_port >= 0 ? debug_port : default_debugger_port; debugger_running = - env->debugger_agent()->Start(host, debug_port, wait); + env->debugger_agent()->Start(host, port, wait); if (debugger_running == false) { - fprintf(stderr, "Starting debugger on %s:%d failed\n", host, debug_port); + fprintf(stderr, "Starting debugger on %s:%d failed\n", host, port); fflush(stderr); return; }