Skip to content

Commit 6041a2e

Browse files
committed
fix: bound subscription login completion time
1 parent 6f2074f commit 6041a2e

5 files changed

Lines changed: 21 additions & 5 deletions

File tree

core/internal/buildinfo/buildinfo.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import "strings"
44

55
// Set at link time via -ldflags (see .goreleaser.yaml).
66
var (
7-
Version = "dev0.1.91"
7+
Version = "dev0.1.92"
88
Commit = "none"
99
Date = "unknown"
1010
)

core/internal/subscriptionauth/oauth.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ const (
4141
codexScope = "openid profile email offline_access"
4242
codexAuthClaim = "https://api.openai.com/auth"
4343

44-
loginTimeout = 10 * time.Minute
44+
loginTimeout = 10 * time.Minute
45+
tokenExchangeTimeout = 45 * time.Second
4546
)
4647

4748
// claudeTokenURL is a var (not const) so tests can point it at a local server.
@@ -127,7 +128,9 @@ func loginClaude(ctx context.Context, openBrowser bool) (string, error) {
127128
if err != nil {
128129
return authURL, err
129130
}
130-
creds, err := exchangeClaudeCode(ctx, cb.Code, cb.State, pkce.Verifier, redirectURI)
131+
exchangeCtx, exchangeCancel := context.WithTimeout(ctx, tokenExchangeTimeout)
132+
defer exchangeCancel()
133+
creds, err := exchangeClaudeCode(exchangeCtx, cb.Code, cb.State, pkce.Verifier, redirectURI)
131134
if err != nil {
132135
return authURL, err
133136
}
@@ -178,7 +181,9 @@ func loginCodex(ctx context.Context, openBrowser bool) (string, error) {
178181
if err != nil {
179182
return authURL, err
180183
}
181-
creds, err := exchangeCodexCode(ctx, cb.Code, pkce.Verifier, redirectURI)
184+
exchangeCtx, exchangeCancel := context.WithTimeout(ctx, tokenExchangeTimeout)
185+
defer exchangeCancel()
186+
creds, err := exchangeCodexCode(exchangeCtx, cb.Code, pkce.Verifier, redirectURI)
182187
if err != nil {
183188
return authURL, err
184189
}

electron/clovapi-desktop.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ async function authLogin(provider) {
175175
const result = await runClovapiLongAsync(["auth", "login", "--provider", providerId, "--json"], {
176176
cancelKey: providerId,
177177
onOutput: outputHandler,
178+
timeout: AUTH_LOGIN_TIMEOUT,
178179
});
179180
if (result.cancelled) {
180181
return { ok: false, cancelled: true, error: "已取消登录" };

electron/clovapi-exec.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -699,12 +699,22 @@ async function runClovapiLongAsync(args, options = {}) {
699699
const stderrChunks = [];
700700
let settled = false;
701701
const onOutput = options.onOutput;
702+
const longRunTimeout = Number(options.timeout);
703+
let timeoutTimer = null;
704+
if (Number.isFinite(longRunTimeout) && longRunTimeout > 0) {
705+
timeoutTimer = setTimeout(() => {
706+
emitLongRunOutput(onOutput, "system", `\n[timeout] after ${longRunTimeout}ms\n`);
707+
killChildTree(child);
708+
}, longRunTimeout);
709+
timeoutTimer.unref?.();
710+
}
702711
emitLongRunOutput(onOutput, "system", `$ ${exe} ${args.join(" ")}\n`);
703712

704713
const finish = (result) => {
705714
if (settled) return;
706715
settled = true;
707716
if (cancelKey) activeLongRuns.delete(cancelKey);
717+
if (timeoutTimer) clearTimeout(timeoutTimer);
708718
resolve(result);
709719
};
710720

electron/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "clovapi-switcher",
33
"private": true,
4-
"version": "0.2.9",
4+
"version": "0.2.10",
55
"description": "ClovAPI Switcher desktop app",
66
"main": "main.js",
77
"type": "commonjs",

0 commit comments

Comments
 (0)