From b41db3396b09faa66ffd12f3d7434595bf29f7a3 Mon Sep 17 00:00:00 2001 From: Eugene Ostroukhov Date: Fri, 2 Dec 2016 11:02:44 -0800 Subject: [PATCH] inspector: check if connected before waiting Fixes: https://github.com/nodejs/node/issues/10093 PR-URL: https://github.com/nodejs/node/pull/10094 Reviewed-By: Colin Ihrig Reviewed-By: James M Snell Reviewed-By: Ben Noordhuis --- src/inspector_agent.cc | 10 ++++++---- test/inspector/test-inspector-stops-no-file.js | 15 +++++++++++++++ 2 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 test/inspector/test-inspector-stops-no-file.js diff --git a/src/inspector_agent.cc b/src/inspector_agent.cc index fd7968ff68ced1..ec713942f50e7e 100644 --- a/src/inspector_agent.cc +++ b/src/inspector_agent.cc @@ -548,10 +548,12 @@ bool AgentImpl::IsStarted() { } void AgentImpl::WaitForDisconnect() { - shutting_down_ = true; - fprintf(stderr, "Waiting for the debugger to disconnect...\n"); - fflush(stderr); - inspector_->runMessageLoopOnPause(0); + if (state_ == State::kConnected) { + shutting_down_ = true; + fprintf(stderr, "Waiting for the debugger to disconnect...\n"); + fflush(stderr); + inspector_->runMessageLoopOnPause(0); + } } #define READONLY_PROPERTY(obj, str, var) \ diff --git a/test/inspector/test-inspector-stops-no-file.js b/test/inspector/test-inspector-stops-no-file.js new file mode 100644 index 00000000000000..d0f3a753464096 --- /dev/null +++ b/test/inspector/test-inspector-stops-no-file.js @@ -0,0 +1,15 @@ +'use strict'; +require('../common'); +const spawn = require('child_process').spawn; + +const child = spawn(process.execPath, + [ '--inspect', 'no-such-script.js' ], + { 'stdio': 'inherit' }); + +function signalHandler(value) { + child.kill(); + process.exit(1); +} + +process.on('SIGINT', signalHandler); +process.on('SIGTERM', signalHandler);