فینورا پرو - سامانه جامع حسابداری و صدور فاکتور
fix(A07): bound blocked IndexedDB upgrade waits and allow safe retry
davoodmehraban89 committed
Oct 14, 2026 at 23:57 UTC
a4e67fce8ec348a2d78749e2443d7da7e70b47e2
1 file changed
+21
-5
src/core/StorageService.js
+21
-5
@@ -58,6 +58,7 @@ class StorageServiceImpl {
58
constructor() {
59
this.db = null;
60
this._opening = null;
61
+ this.blockedTimeoutMs = 12000;
62
}
63
64
// ---------- باز کردن پایگاه داده ----------
@@ -68,6 +69,15 @@ class StorageServiceImpl {
69
70
this._opening = new Promise((resolve, reject) => {
71
const req = indexedDB.open(DB_NAME, DB_VERSION);
72
+ let resolved = false;
73
+ let blockedTimer = null;
74
+ const fail = error => {
75
+ if (resolved) return;
76
+ resolved = true;
77
+ if (blockedTimer !== null) clearTimeout(blockedTimer);
78
+ this._opening = null;
79
+ reject(error);
80
+ };
81
82
req.onupgradeneeded = (e) => {
83
const db = e.target.result;
@@ -83,10 +93,19 @@ class StorageServiceImpl {
93
};
94
95
req.onblocked = () => {
86
- console.warn('IndexedDB: ارتقای پایگاه داده منتظر بسته شدن پنجرههای دیگر است');
96
+ console.warn('IndexedDB: نسخه دیگری از پایگاه داده هنوز باز است');
97
+ if (blockedTimer !== null) return;
98
+ blockedTimer = setTimeout(() => {
99
+ fail(new Error('ارتقای پایگاه داده متوقف شده است؛ پنجرههای دیگر برنامه را ببندید و دوباره تلاش کنید'));
100
+ }, this.blockedTimeoutMs);
101
};
102
103
req.onsuccess = () => {
104
+ if (blockedTimer !== null) clearTimeout(blockedTimer);
105
+ // An older blocked request may complete after its timeout. Close it:
106
+ // only a fresh explicit retry may take ownership of that DB handle.
107
+ if (resolved) { req.result.close(); return; }
108
+ resolved = true;
109
this.db = req.result;
110
this.db.onversionchange = () => {
111
this.db.close();
@@ -97,10 +116,7 @@ class StorageServiceImpl {
116
resolve(this.db);
117
};
118
100
- req.onerror = () => {
101
- this._opening = null;
102
- reject(req.error);
103
- };
119
+ req.onerror = () => fail(req.error || new Error('باز کردن پایگاه داده ناموفق بود'));
120
});
121
122
return this._opening;