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