fix: prevent profile switch queue from breaking after failed switch

This commit is contained in:
xmk23333 2026-01-19 12:55:21 +08:00
parent 56e328191f
commit 3c148f2c01
2 changed files with 34 additions and 19 deletions

View File

@ -263,7 +263,7 @@ jobs:
arch: arch:
- x64 - x64
- arm64 - arm64
runs-on: ubuntu-latest runs-on: ubuntu-20.04
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v6 uses: actions/checkout@v6

View File

@ -65,26 +65,33 @@ export async function getProfileItem(id: string | undefined): Promise<IProfileIt
export async function changeCurrentProfile(id: string): Promise<void> { export async function changeCurrentProfile(id: string): Promise<void> {
// 使用队列确保 profile 切换串行执行,避免竞态条件 // 使用队列确保 profile 切换串行执行,避免竞态条件
changeProfileQueue = changeProfileQueue.then(async () => { let taskError: unknown = null
const { current } = await getProfileConfig() changeProfileQueue = changeProfileQueue
if (current === id) return .catch(() => {
})
.then(async () => {
const { current } = await getProfileConfig()
if (current === id) return
try { try {
await updateProfileConfig((config) => { await updateProfileConfig((config) => {
config.current = id config.current = id
return config return config
}) })
await restartCore() await restartCore()
} catch (e) { } catch (e) {
// 回滚配置 // 回滚配置
await updateProfileConfig((config) => { await updateProfileConfig((config) => {
config.current = current config.current = current
return config return config
}) })
throw e taskError = e
} }
}) })
await changeProfileQueue await changeProfileQueue
if (taskError) {
throw taskError
}
} }
export async function updateProfileItem(item: IProfileItem): Promise<void> { export async function updateProfileItem(item: IProfileItem): Promise<void> {
@ -249,6 +256,14 @@ export async function createProfile(item: Partial<IProfileItem>): Promise<IProfi
useProxy: true, useProxy: true,
timeout: subscriptionTimeout timeout: subscriptionTimeout
}) })
} else if (newItem.substore) {
// SubStore requests (especially collections) need more time as they fetch and merge multiple subscriptions
// Use the full subscriptionTimeout since SubStore is a local server and doesn't need smart fallback
result = await fetchAndValidateSubscription({
...baseOptions,
useProxy: false,
timeout: subscriptionTimeout
})
} else { } else {
const smartTimeout = 5000 const smartTimeout = 5000
try { try {