-
Notifications
You must be signed in to change notification settings - Fork 30.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
debugger: fix stuck debugger when debuggee exits #6332
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -128,6 +128,11 @@ void Agent::Enable() { | |
parent_env()->AssignToContext(debug_context); | ||
} | ||
|
||
static void close_handle(uv_handle_t* handle, void* data) { | ||
if (!uv_is_closing(handle)) { | ||
uv_close(handle, nullptr); | ||
} | ||
} | ||
|
||
void Agent::Stop() { | ||
int err; | ||
|
@@ -149,6 +154,9 @@ void Agent::Stop() { | |
CHECK_EQ(err, 0); | ||
|
||
uv_close(reinterpret_cast<uv_handle_t*>(&child_signal_), nullptr); | ||
// Close all remaining handles: | ||
// uv_loop_close will return UV_EBUSY for handles which are not closed. | ||
uv_walk(&child_loop_, close_handle, nullptr); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a workaround. I can't explain why there are always two pipe handles left referenced.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. They are the stdout and stderr pipes. Closing them like that is not very optimal, it leaves their PipeWrap instances in an invalid state. Proper cleanup is one of the things I have to tackle for the multi-isolate work. I'll try to get around to it later this week. |
||
uv_run(&child_loop_, UV_RUN_NOWAIT); | ||
|
||
err = uv_loop_close(&child_loop_); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
'use strict'; | ||
console.log('debug'); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
'use strict'; | ||
const path = require('path'); | ||
const spawn = require('child_process').spawn; | ||
const assert = require('assert'); | ||
|
||
const common = require('../common'); | ||
|
||
const fixture = path.join( | ||
common.fixturesDir, | ||
'debugger-stuck-regression-fixture.js' | ||
); | ||
|
||
const args = [ | ||
'debug', | ||
`--port=${common.PORT}`, | ||
fixture | ||
]; | ||
|
||
const TEST_TIMEOUT_MS = common.platformTimeout(4000); | ||
|
||
function onTestTimeout() { | ||
common.fail('The debuggee did not terminate.'); | ||
} | ||
|
||
const testTimeout = setTimeout(onTestTimeout, TEST_TIMEOUT_MS); | ||
|
||
const proc = spawn(process.execPath, args, { stdio: 'pipe' }); | ||
proc.stdout.setEncoding('utf8'); | ||
proc.stderr.setEncoding('utf8'); | ||
|
||
const STATE_WAIT_BREAK = 0; | ||
const STATE_WAIT_PROC_TERMINATED = 1; | ||
const STATE_EXIT = 2; | ||
|
||
let stdout = ''; | ||
let stderr = ''; | ||
let state = 0; | ||
let cycles = 2; | ||
|
||
proc.stdout.on('data', (data) => { | ||
stdout += data; | ||
|
||
switch (state) { | ||
case STATE_WAIT_BREAK: | ||
// check if the debugger stopped at line 1 | ||
if (stdout.includes('> 1')) { | ||
stdout = ''; | ||
|
||
// send continue to the debugger | ||
proc.stdin.write('c\n'); | ||
state = STATE_WAIT_PROC_TERMINATED; | ||
} | ||
break; | ||
case STATE_WAIT_PROC_TERMINATED: | ||
// check if the debuggee has terminated | ||
if (stdout.includes('program terminated')) { | ||
stdout = ''; | ||
|
||
// If cycles is greater than 0, | ||
// we re-run the debuggee. | ||
// Otherwise exit the debugger. | ||
if (cycles > 0) { | ||
--cycles; | ||
state = STATE_WAIT_BREAK; | ||
proc.stdin.write('run\n'); | ||
} else { | ||
// cancel the test timeout | ||
clearTimeout(testTimeout); | ||
state = STATE_EXIT; | ||
proc.stdin.write('.exit\n'); | ||
} | ||
|
||
} | ||
break; | ||
case STATE_EXIT: | ||
// fall through | ||
default: | ||
break; | ||
} | ||
}); | ||
|
||
proc.stderr.on('data', (data) => { | ||
stderr += data; | ||
}); | ||
|
||
proc.stdin.on('error', (err) => { | ||
console.error(err); | ||
}); | ||
|
||
process.on('exit', (code) => { | ||
assert.equal(code, 0, 'the program should exit cleanly'); | ||
assert.equal(stderr, '', 'stderr should be empty'); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this ends up calling
this.socket.destroy
I didn't dig too much further, but is this operation synchronous? If not there might be some unexpected behavior here
/cc @bnoordhuis
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will dig into this. I used destroy, because it was already used in the close event.
Maybe
this.socket.end()
would be sufficient here.Edit: It seems that
this.socket.end()
also works. But it eventually will also call destroy.