fix: 修复 getAvatarUrls 竞态导致 handle 为 null 的崩溃

在 await setImmediate 让出控制权前先捕获 handle,
await 后重新校验 handle 是否仍有效,避免连接关闭后
向 koffi DLL 传入 null 导致 TypeError。
This commit is contained in:
hicccc77
2026-03-15 14:15:51 +08:00
parent 2b97b6ac9d
commit 7be2c69256

View File

@@ -1488,10 +1488,19 @@ export class WcdbCore {
} }
// 让出控制权,避免阻塞事件循环 // 让出控制权,避免阻塞事件循环
const handle = this.handle
await new Promise(resolve => setImmediate(resolve)) await new Promise(resolve => setImmediate(resolve))
// await 后 handle 可能已被关闭,需重新检查
if (handle === null || this.handle !== handle) {
if (Object.keys(resultMap).length > 0) {
return { success: true, map: resultMap, error: '连接已断开' }
}
return { success: false, error: '连接已断开' }
}
const outPtr = [null as any] const outPtr = [null as any]
const result = this.wcdbGetAvatarUrls(this.handle, JSON.stringify(toFetch), outPtr) const result = this.wcdbGetAvatarUrls(handle, JSON.stringify(toFetch), outPtr)
// DLL 调用后再次让出控制权 // DLL 调用后再次让出控制权
await new Promise(resolve => setImmediate(resolve)) await new Promise(resolve => setImmediate(resolve))