@thru/replay 0.2.3 → 0.2.5
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/dist/index.cjs +27 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +27 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -54,7 +54,11 @@ var ChainClient = class {
|
|
|
54
54
|
return connectNode.createGrpcTransport({
|
|
55
55
|
baseUrl: this.options.baseUrl,
|
|
56
56
|
useBinaryFormat: this.options.useBinaryFormat ?? true,
|
|
57
|
-
interceptors: mergedInterceptors.length ? mergedInterceptors : void 0
|
|
57
|
+
interceptors: mergedInterceptors.length ? mergedInterceptors : void 0,
|
|
58
|
+
pingIntervalMs: 3e4,
|
|
59
|
+
pingIdleConnection: true,
|
|
60
|
+
pingTimeoutMs: 1e4,
|
|
61
|
+
idleConnectionTimeoutMs: 0
|
|
58
62
|
});
|
|
59
63
|
}
|
|
60
64
|
createHeaderInterceptor() {
|
|
@@ -313,7 +317,7 @@ var LivePump = class {
|
|
|
313
317
|
var DEFAULT_RETRY_CONFIG = {
|
|
314
318
|
initialDelayMs: 1e3,
|
|
315
319
|
maxDelayMs: 3e4,
|
|
316
|
-
connectionTimeoutMs:
|
|
320
|
+
connectionTimeoutMs: 3e5
|
|
317
321
|
};
|
|
318
322
|
function calculateBackoff(attempt, config) {
|
|
319
323
|
const delay2 = config.initialDelayMs * Math.pow(2, attempt);
|
|
@@ -584,7 +588,10 @@ var ReplayStream = class {
|
|
|
584
588
|
};
|
|
585
589
|
async function safeClose(pump) {
|
|
586
590
|
try {
|
|
587
|
-
await
|
|
591
|
+
await Promise.race([
|
|
592
|
+
pump.close(),
|
|
593
|
+
new Promise((resolve) => setTimeout(resolve, 5e3))
|
|
594
|
+
]);
|
|
588
595
|
} catch {
|
|
589
596
|
}
|
|
590
597
|
}
|
|
@@ -1071,6 +1078,7 @@ async function* createAccountsByOwnerReplay(options) {
|
|
|
1071
1078
|
const streamBuffer = [];
|
|
1072
1079
|
let streamDone = false;
|
|
1073
1080
|
let streamError = null;
|
|
1081
|
+
let lastActivityTime = Date.now();
|
|
1074
1082
|
try {
|
|
1075
1083
|
cleanupTimer = setInterval(() => {
|
|
1076
1084
|
assembler.cleanup();
|
|
@@ -1080,6 +1088,7 @@ async function* createAccountsByOwnerReplay(options) {
|
|
|
1080
1088
|
const streamProcessor = (async () => {
|
|
1081
1089
|
try {
|
|
1082
1090
|
for await (const response of stream) {
|
|
1091
|
+
lastActivityTime = Date.now();
|
|
1083
1092
|
const event = processResponseMulti(response, assembler);
|
|
1084
1093
|
if (event) {
|
|
1085
1094
|
if (event.type === "account") {
|
|
@@ -1169,6 +1178,7 @@ async function* createAccountsByOwnerReplay(options) {
|
|
|
1169
1178
|
let retryAttempt = 0;
|
|
1170
1179
|
let currentStream = stream;
|
|
1171
1180
|
let currentStreamProcessor = streamProcessor;
|
|
1181
|
+
lastActivityTime = Date.now();
|
|
1172
1182
|
const createStreamProcessor = () => {
|
|
1173
1183
|
if (clientFactory) {
|
|
1174
1184
|
try {
|
|
@@ -1184,6 +1194,7 @@ async function* createAccountsByOwnerReplay(options) {
|
|
|
1184
1194
|
try {
|
|
1185
1195
|
for await (const response of newStream) {
|
|
1186
1196
|
retryAttempt = 0;
|
|
1197
|
+
lastActivityTime = Date.now();
|
|
1187
1198
|
const event = processResponseMulti(response, assembler);
|
|
1188
1199
|
if (event) {
|
|
1189
1200
|
if (event.type === "account") {
|
|
@@ -1204,7 +1215,18 @@ async function* createAccountsByOwnerReplay(options) {
|
|
|
1204
1215
|
return { stream: newStream, processor: newProcessor };
|
|
1205
1216
|
};
|
|
1206
1217
|
while (true) {
|
|
1218
|
+
const hadEvents = streamBuffer.length > 0;
|
|
1207
1219
|
yield* yieldStreamBuffer();
|
|
1220
|
+
if (hadEvents) {
|
|
1221
|
+
lastActivityTime = Date.now();
|
|
1222
|
+
}
|
|
1223
|
+
if (!streamDone && Date.now() - lastActivityTime > retryConfig.connectionTimeoutMs) {
|
|
1224
|
+
logger.warn(
|
|
1225
|
+
`[account-stream] no activity for ${retryConfig.connectionTimeoutMs}ms; forcing reconnection`
|
|
1226
|
+
);
|
|
1227
|
+
streamDone = true;
|
|
1228
|
+
streamError = new Error(`Operation timed out after ${retryConfig.connectionTimeoutMs}ms`);
|
|
1229
|
+
}
|
|
1208
1230
|
if (streamDone) {
|
|
1209
1231
|
if (streamError) {
|
|
1210
1232
|
const backoffMs = calculateBackoff(retryAttempt, retryConfig);
|
|
@@ -1216,6 +1238,7 @@ async function* createAccountsByOwnerReplay(options) {
|
|
|
1216
1238
|
streamDone = false;
|
|
1217
1239
|
streamError = null;
|
|
1218
1240
|
streamBuffer.length = 0;
|
|
1241
|
+
lastActivityTime = Date.now();
|
|
1219
1242
|
const { stream: newStream, processor: newProcessor } = createStreamProcessor();
|
|
1220
1243
|
currentStream = newStream;
|
|
1221
1244
|
currentStreamProcessor = newProcessor;
|
|
@@ -1223,6 +1246,7 @@ async function* createAccountsByOwnerReplay(options) {
|
|
|
1223
1246
|
} else {
|
|
1224
1247
|
logger.warn("[account-stream] stream ended unexpectedly; reconnecting...");
|
|
1225
1248
|
streamDone = false;
|
|
1249
|
+
lastActivityTime = Date.now();
|
|
1226
1250
|
const { stream: newStream, processor: newProcessor } = createStreamProcessor();
|
|
1227
1251
|
currentStream = newStream;
|
|
1228
1252
|
currentStreamProcessor = newProcessor;
|