Skip to content

Conversation

@deepak1556
Copy link
Contributor

@deepak1556 deepak1556 commented Jan 23, 2025

Fix for microsoft/vscode#225719
Fixes #733

Based on etl profiles, we see that the OpenConsole processes are leaked since they are waiting on I/O from the pseudo client processes that are not terminated even when pty.kill command was issued.

The changes associates all the client process to a job handle with JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE and the handle gets destroyed when the process hosting pty module gets torn down.

@deepak1556 deepak1556 added this to the January 2025 milestone Jan 23, 2025
@deepak1556 deepak1556 self-assigned this Jan 23, 2025
@deepak1556 deepak1556 force-pushed the robo/fix_process_cleanup branch from 16ab761 to 483e7c7 Compare January 23, 2025 03:28
@deepak1556 deepak1556 requested a review from Tyriar January 23, 2025 03:28
@deepak1556 deepak1556 marked this pull request as ready for review January 23, 2025 03:36
Copy link
Member

@Tyriar Tyriar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also means we don't need the async PR either?

});
(this._ptyNative as IConptyNative).kill(this._pty, this._useConptyDll);
});
(this._ptyNative as IConptyNative).kill(this._pty, this._useConptyDll);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this means we can remove conpty_console_list_agent.ts and win/conpty_console_list.cc

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah left it as such incase you had use cases in future. Happy to remove them.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove if we don't need

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I retain the old tree kill logic for useConpty mode while useConptyDll mode uses the new logic. This allows for a possible fallback incase things go horribly wrong. We can merge the two paths once we gain confidence.

@deepak1556
Copy link
Contributor Author

This also means we don't need the async PR either?

Yeah it won't be needed with this change

};

static std::vector<pty_baton*> ptyHandles;
static std::vector<std::unique_ptr<pty_baton>> ptyHandles;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small cleanup to ensure proper lifetime management when the process exits.

CloseHandle(baton->hIn);
CloseHandle(baton->hOut);
CloseHandle(baton->hShell);
assert(remove_pty_baton(baton->id));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We were previously closing the client handle in pty.kill which would invalidate waiting on the exit callback. Moved it closer to when the client has signaled exit.

@deepak1556 deepak1556 requested a review from Tyriar January 27, 2025 07:47
@Tyriar Tyriar self-assigned this Feb 3, 2025
@Tyriar Tyriar modified the milestones: January 2025, 1.1.0 Feb 3, 2025
@Tyriar Tyriar merged commit 358750c into main Feb 3, 2025
7 checks passed
@Tyriar Tyriar deleted the robo/fix_process_cleanup branch February 3, 2025 12:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Electron process doesn't exit if pseudoterminal isn't fully killed before app is quit

3 participants