Allow pty.kill to be awaited#734
Allow pty.kill to be awaited#734TheLazySquid wants to merge 5 commits intomicrosoft:mainfrom TheLazySquid:main
Conversation
|
@microsoft-github-policy-service agree |
src/windowsTerminal.ts
Outdated
There was a problem hiding this comment.
Shouldn’t the outer promise be rejected when the this._agent.kill() promise fails?
| return new Promise((res) => { | |
| this._deferNoArgs(() => { | |
| if (signal) { | |
| throw new Error('Signals not supported on windows.'); | |
| } | |
| this._close(); | |
| this._agent.kill().then(res); | |
| return new Promise((res, rej) => { | |
| this._deferNoArgs(() => { | |
| if (signal) { | |
| throw new Error('Signals not supported on windows.'); | |
| } | |
| this._close(); | |
| this._agent.kill().then(res, rej); |
There was a problem hiding this comment.
This may or may not be out of scope for this PR, but anyway.
As far as I can tell, the callbacks passed to this._deferNoArgs are called later, asynchronously. So it looks like the throw here cannot be caught. This is not a new issue in this PR. But with this PR, it’s less expected to throw errors since the function returns a Promise – I’d expect the promise to be rejected instead. We have the possibility to do that:
| return new Promise((res) => { | |
| this._deferNoArgs(() => { | |
| if (signal) { | |
| throw new Error('Signals not supported on windows.'); | |
| } | |
| this._close(); | |
| this._agent.kill().then(res); | |
| return new Promise((res, rej) => { | |
| this._deferNoArgs(() => { | |
| if (signal) { | |
| rej(new Error('Signals not supported on windows.')); | |
| } else { | |
| this._close(); | |
| this._agent.kill().then(res, rej); | |
| } |
However, I don’t know if this is wanted or not by end consumers. They can always check caughtError.message === 'Signals not supported on windows.' but 🤷
If this change is made, this line needs to be updated in node-pty.d.ts:
@throws Will throw when signal is used on Windows.
There was a problem hiding this comment.
I think it makes more sense to reject the promise if signal is used, especially if the thrown error would sometimes not be caught. I'm not entirely sure how promise rejections should be described in jsdoc, but changing it to @throws Will reject when signal is used on Windows. seems to be fine.
There was a problem hiding this comment.
Nice!
Note that your commit (unlike my suggestion above) changes behavior: Previously, this._close() and this._agent.kill() were not run if signal is truthy. In your commit, the promise is rejected and then those two methods are run anyway.
There was a problem hiding this comment.
Whoops, should be fixed now.
|
I wouldn't be surprised if CI is failing because it is trying to run on a fork. #727, which splits the current pipeline into two and makes the CI pipeline use the unofficial template might help. |
|
@rzhao271 can we get it to run on a PR branch that gets merged into main with an approve and run button? Alternatively, we could just have SDL blocking the release step and only run on main after the PR is merged. |
|
Turns out this won't be needed after #755 since the whole function will be performed synchronously 🎉 |
Currently there isn't a good way to know when a pseudoterminal is fully killed, since there is some asynchronous logic on windows. This means that there isn't a good way to clean up any active pseudoterminals in electron before shutdown, as described in #733, because if the app is quit before the terminals are fully killed the process will hang. This PR allows
pty.killto be awaited, so the app can be shut down only after any pseudoterminals are fully killed, making a clean solution like this possible:Fixes #733