edge-core-js 2.46.1 → 2.47.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/util/nym.js
CHANGED
|
@@ -22,6 +22,16 @@ export const mixFetchOptions = {
|
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
+
/**
|
|
26
|
+
* Budget for `createMixFetch` itself (client start + gateway handshake).
|
|
27
|
+
*
|
|
28
|
+
* A healthy setup with the pinned gateway completes in under 10s measured.
|
|
29
|
+
* Without a bound here the whole app blocks on the first mixnet request for
|
|
30
|
+
* as long as a dead gateway keeps us waiting, which reads to the user as a
|
|
31
|
+
* freeze.
|
|
32
|
+
*/
|
|
33
|
+
const SETUP_TIMEOUT_MS = 60000
|
|
34
|
+
|
|
25
35
|
// MixFetch initialization state
|
|
26
36
|
let mixFetchInitPromise = null
|
|
27
37
|
|
|
@@ -32,7 +42,23 @@ let mixFetchInitPromise = null
|
|
|
32
42
|
export async function initMixFetch(log) {
|
|
33
43
|
if (mixFetchInitPromise == null) {
|
|
34
44
|
log('Initializing mixFetch...')
|
|
35
|
-
|
|
45
|
+
const pending = createMixFetch(mixFetchOptions)
|
|
46
|
+
// The timeout below can abandon this setup while it is still in flight.
|
|
47
|
+
// Deliberately do NOT tear it down on late completion: `createMixFetch`
|
|
48
|
+
// resolves to a healthy global singleton, and disconnecting it (a
|
|
49
|
+
// process-wide operation) would race a newer init that has taken over.
|
|
50
|
+
// A late completion just repopulates `__mixFetchGlobal`, which the next
|
|
51
|
+
// init reuses. Swallow a late rejection so it is not unhandled.
|
|
52
|
+
pending.catch(() => {})
|
|
53
|
+
let timer
|
|
54
|
+
const timeout = new Promise((resolve, reject) => {
|
|
55
|
+
timer = setTimeout(() => {
|
|
56
|
+
reject(
|
|
57
|
+
new Error(`mixFetch setup timed out after ${SETUP_TIMEOUT_MS}ms`)
|
|
58
|
+
)
|
|
59
|
+
}, SETUP_TIMEOUT_MS)
|
|
60
|
+
})
|
|
61
|
+
mixFetchInitPromise = Promise.race([pending, timeout])
|
|
36
62
|
.then(mixFetchModule => {
|
|
37
63
|
log('mixFetch initialized successfully')
|
|
38
64
|
return mixFetchModule
|
|
@@ -50,6 +76,9 @@ export async function initMixFetch(log) {
|
|
|
50
76
|
log.error('mixFetch initialization failed:', error)
|
|
51
77
|
throw error
|
|
52
78
|
})
|
|
79
|
+
.finally(() => {
|
|
80
|
+
clearTimeout(timer)
|
|
81
|
+
})
|
|
53
82
|
}
|
|
54
83
|
const mixFetchModule = await mixFetchInitPromise
|
|
55
84
|
return mixFetchModule.mixFetch
|