diff --git a/src/inspector_agent.cc b/src/inspector_agent.cc index 79bd71e24d0db2..60c11ea636cf0f 100644 --- a/src/inspector_agent.cc +++ b/src/inspector_agent.cc @@ -515,10 +515,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);