Skip to content
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

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions lib/_debug_agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ exports.start = function start() {
process.removeListener('SIGWINCH', fn);
});

// Disconnect all currently connected clients.
// Without this, the debugger agent loop will not unblock
// and the debuggee will get stuck.
agent.destroyAllClients();
agent.close();
};

Expand Down Expand Up @@ -81,6 +85,12 @@ Agent.prototype.notifyWait = function notifyWait() {
this.first = false;
};

Agent.prototype.destroyAllClients = function destroyAllClients() {
this.clients.forEach(function(client) {
client.destroy();
Copy link
Contributor

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

Copy link
Contributor Author

@reshnm reshnm Apr 21, 2016

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.

});
};

function Client(agent, socket) {
Transform.call(this, {
readableObjectMode: true
Expand Down
8 changes: 8 additions & 0 deletions src/debug-agent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

[--I] signal   0x30606e8
[-AI] async    0x3060530
[---] async    0x30603e8
[R--] pipe     0x7fd8a0058520
[R--] pipe     0x7fd8a0064260

Copy link
Member

Choose a reason for hiding this comment

The 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_);
Expand Down