mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-20 02:00:40 -07:00
fix(core): clear 5-minute timeouts in oauth flow to prevent memory leaks (#24968)
This commit is contained in:
@@ -424,6 +424,7 @@ async function authWithUserCode(client: OAuth2Client): Promise<boolean> {
|
||||
'\n\n',
|
||||
);
|
||||
|
||||
let authTimeoutId: NodeJS.Timeout | undefined;
|
||||
const code = await new Promise<string>((resolve, reject) => {
|
||||
const rl = readline.createInterface({
|
||||
input: process.stdin,
|
||||
@@ -431,20 +432,29 @@ async function authWithUserCode(client: OAuth2Client): Promise<boolean> {
|
||||
terminal: true,
|
||||
});
|
||||
|
||||
const timeout = setTimeout(() => {
|
||||
rl.close();
|
||||
reject(
|
||||
const abortController = new AbortController();
|
||||
authTimeoutId = setTimeout(() => {
|
||||
abortController.abort(
|
||||
new FatalAuthenticationError(
|
||||
'Authorization timed out after 5 minutes.',
|
||||
),
|
||||
);
|
||||
}, 300000); // 5 minute timeout
|
||||
authTimeoutId.unref();
|
||||
|
||||
const onAbort = () => {
|
||||
rl.close();
|
||||
reject(abortController.signal.reason);
|
||||
};
|
||||
abortController.signal.addEventListener('abort', onAbort, { once: true });
|
||||
|
||||
rl.question('Enter the authorization code: ', (code) => {
|
||||
clearTimeout(timeout);
|
||||
abortController.signal.removeEventListener('abort', onAbort);
|
||||
rl.close();
|
||||
resolve(code.trim());
|
||||
});
|
||||
}).finally(() => {
|
||||
if (authTimeoutId) clearTimeout(authTimeoutId);
|
||||
});
|
||||
|
||||
if (!code) {
|
||||
|
||||
Reference in New Issue
Block a user