Fix terminal hang when user exits browser without logging in (#15748)

This commit is contained in:
Christian Gunderman
2026-01-05 11:02:55 -08:00
committed by GitHub
parent b4b49e7029
commit 3997c7ff80
2 changed files with 170 additions and 1 deletions
+35 -1
View File
@@ -325,7 +325,41 @@ async function initOauthClient(
}, authTimeout);
});
await Promise.race([webLogin.loginCompletePromise, timeoutPromise]);
// Listen for SIGINT to stop waiting for auth so the terminal doesn't hang
// if the user chooses not to auth.
let sigIntHandler: (() => void) | undefined;
let stdinHandler: ((data: Buffer) => void) | undefined;
const cancellationPromise = new Promise<never>((_, reject) => {
sigIntHandler = () =>
reject(new FatalCancellationError('Authentication cancelled by user.'));
process.on('SIGINT', sigIntHandler);
// Note that SIGINT might not get raised on Ctrl+C in raw mode
// so we also need to look for Ctrl+C directly in stdin.
stdinHandler = (data) => {
if (data.includes(0x03)) {
reject(
new FatalCancellationError('Authentication cancelled by user.'),
);
}
};
process.stdin.on('data', stdinHandler);
});
try {
await Promise.race([
webLogin.loginCompletePromise,
timeoutPromise,
cancellationPromise,
]);
} finally {
if (sigIntHandler) {
process.removeListener('SIGINT', sigIntHandler);
}
if (stdinHandler) {
process.stdin.removeListener('data', stdinHandler);
}
}
coreEvents.emit(CoreEvent.UserFeedback, {
severity: 'info',