nappup 1.5.5 → 1.5.6
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/package.json +1 -1
- package/src/index.js +24 -8
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -218,23 +218,38 @@ async function throttledSendEvent (event, relays, {
|
|
|
218
218
|
return { pause }
|
|
219
219
|
}
|
|
220
220
|
|
|
221
|
-
const [rateLimitErrors, unretryableErrors] =
|
|
221
|
+
const [rateLimitErrors, maybeUnretryableErrors, unretryableErrors] =
|
|
222
222
|
errors.reduce((r, v) => {
|
|
223
|
-
|
|
224
|
-
|
|
223
|
+
const message = v.reason?.message ?? ''
|
|
224
|
+
if (message.startsWith('rate-limited:')) r[0].push(v)
|
|
225
|
+
// https://github.com/nbd-wtf/nostr-tools/blob/28f7553187d201088c8a1009365db4ecbe03e568/abstract-relay.ts#L311
|
|
226
|
+
else if (message === 'publish timed out') r[1].push(v)
|
|
227
|
+
else r[2].push(v)
|
|
225
228
|
return r
|
|
226
|
-
}, [[], []])
|
|
229
|
+
}, [[], [], []])
|
|
230
|
+
|
|
231
|
+
// One-time special retry
|
|
232
|
+
if (maybeUnretryableErrors.length > 0) {
|
|
233
|
+
const timedOutRelays = maybeUnretryableErrors.map(v => v.relay)
|
|
234
|
+
log(`${maybeUnretryableErrors.length} timeout errors, retrying once after ${pause}ms:\n${maybeUnretryableErrors.map(v => `${v.relay}: ${v.reason.message}`).join('; ')}`)
|
|
235
|
+
if (pause) await new Promise(resolve => setTimeout(resolve, pause))
|
|
236
|
+
const { errors: timeoutRetryErrors } = await nostrRelays.sendEvent(event, timedOutRelays, 15000)
|
|
237
|
+
unretryableErrors.push(...timeoutRetryErrors)
|
|
238
|
+
}
|
|
239
|
+
|
|
227
240
|
if (unretryableErrors.length > 0) {
|
|
228
241
|
log(`${unretryableErrors.length} unretryable errors:\n${unretryableErrors.map(v => `${v.relay}: ${v.reason.message}`).join('; ')}`)
|
|
229
242
|
console.log('Erroed event:', stringifyEvent(event))
|
|
230
243
|
}
|
|
231
|
-
const
|
|
232
|
-
const maybeSuccessfulRelays = relays.length - unretryableErrorsLength
|
|
244
|
+
const maybeSuccessfulRelays = relays.length - unretryableErrors.length
|
|
233
245
|
const hasReachedMaxRetries = retries > maxRetries
|
|
234
246
|
if (
|
|
235
247
|
hasReachedMaxRetries ||
|
|
236
248
|
maybeSuccessfulRelays < minSuccessfulRelays
|
|
237
|
-
)
|
|
249
|
+
) {
|
|
250
|
+
const finalErrors = [...rateLimitErrors, ...unretryableErrors]
|
|
251
|
+
throw new Error(finalErrors.map(v => `\n${v.relay}: ${v.reason}`).join('\n'))
|
|
252
|
+
}
|
|
238
253
|
|
|
239
254
|
if (rateLimitErrors.length === 0) {
|
|
240
255
|
if (pause && trailingPause) await new Promise(resolve => setTimeout(resolve, pause))
|
|
@@ -245,7 +260,8 @@ async function throttledSendEvent (event, relays, {
|
|
|
245
260
|
log(`Rate limited by ${erroedRelays.length} relays, pausing for ${pause + 2000} ms`)
|
|
246
261
|
await new Promise(resolve => setTimeout(resolve, (pause += 2000)))
|
|
247
262
|
|
|
248
|
-
|
|
263
|
+
// Subtracts the successful publishes from the original minSuccessfulRelays goal
|
|
264
|
+
minSuccessfulRelays = Math.max(0, minSuccessfulRelays - (relays.length - erroedRelays.length - unretryableErrors.length))
|
|
249
265
|
return await throttledSendEvent(event, erroedRelays, {
|
|
250
266
|
pause, log, retries: ++retries, maxRetries, minSuccessfulRelays, leadingPause: false, trailingPause
|
|
251
267
|
})
|