@replit/river 0.23.10 → 0.23.12

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.
Files changed (52) hide show
  1. package/dist/{chunk-FRICSBDW.js → chunk-7RUKEUKE.js} +2 -2
  2. package/dist/{chunk-FRICSBDW.js.map → chunk-7RUKEUKE.js.map} +1 -1
  3. package/dist/{chunk-UXQMGZKP.js → chunk-H6KTH6W6.js} +2 -2
  4. package/dist/{chunk-Z4G27Y2I.js → chunk-HDBVL7EF.js} +2 -2
  5. package/dist/{chunk-KBAZ5TWE.js → chunk-VRU4IKRT.js} +62 -50
  6. package/dist/chunk-VRU4IKRT.js.map +1 -0
  7. package/dist/{chunk-B323CECK.js → chunk-XZ6IOBM5.js} +9 -9
  8. package/dist/chunk-XZ6IOBM5.js.map +1 -0
  9. package/dist/{connection-efcd4e1a.d.ts → connection-581558f8.d.ts} +1 -1
  10. package/dist/{connection-700340c4.d.ts → connection-8debd45f.d.ts} +1 -1
  11. package/dist/router/index.cjs +8 -8
  12. package/dist/router/index.cjs.map +1 -1
  13. package/dist/router/index.d.cts +11 -7
  14. package/dist/router/index.d.ts +11 -7
  15. package/dist/router/index.js +2 -2
  16. package/dist/{services-409c5545.d.ts → services-ca72c9f8.d.ts} +1 -1
  17. package/dist/transport/impls/uds/client.cjs +59 -47
  18. package/dist/transport/impls/uds/client.cjs.map +1 -1
  19. package/dist/transport/impls/uds/client.d.cts +2 -2
  20. package/dist/transport/impls/uds/client.d.ts +2 -2
  21. package/dist/transport/impls/uds/client.js +3 -3
  22. package/dist/transport/impls/uds/server.cjs +20 -38
  23. package/dist/transport/impls/uds/server.cjs.map +1 -1
  24. package/dist/transport/impls/uds/server.d.cts +2 -2
  25. package/dist/transport/impls/uds/server.d.ts +2 -2
  26. package/dist/transport/impls/uds/server.js +3 -3
  27. package/dist/transport/impls/ws/client.cjs +59 -47
  28. package/dist/transport/impls/ws/client.cjs.map +1 -1
  29. package/dist/transport/impls/ws/client.d.cts +2 -2
  30. package/dist/transport/impls/ws/client.d.ts +2 -2
  31. package/dist/transport/impls/ws/client.js +3 -3
  32. package/dist/transport/impls/ws/server.cjs +20 -38
  33. package/dist/transport/impls/ws/server.cjs.map +1 -1
  34. package/dist/transport/impls/ws/server.d.cts +2 -2
  35. package/dist/transport/impls/ws/server.d.ts +2 -2
  36. package/dist/transport/impls/ws/server.js +3 -3
  37. package/dist/transport/index.cjs +61 -49
  38. package/dist/transport/index.cjs.map +1 -1
  39. package/dist/transport/index.d.cts +1 -1
  40. package/dist/transport/index.d.ts +1 -1
  41. package/dist/transport/index.js +2 -2
  42. package/dist/{transport-cf856c41.d.ts → transport-47af1c81.d.ts} +4 -5
  43. package/dist/util/testHelpers.cjs +8 -23
  44. package/dist/util/testHelpers.cjs.map +1 -1
  45. package/dist/util/testHelpers.d.cts +2 -2
  46. package/dist/util/testHelpers.d.ts +2 -2
  47. package/dist/util/testHelpers.js +3 -3
  48. package/package.json +1 -1
  49. package/dist/chunk-B323CECK.js.map +0 -1
  50. package/dist/chunk-KBAZ5TWE.js.map +0 -1
  51. /package/dist/{chunk-UXQMGZKP.js.map → chunk-H6KTH6W6.js.map} +0 -0
  52. /package/dist/{chunk-Z4G27Y2I.js.map → chunk-HDBVL7EF.js.map} +0 -0
@@ -202,7 +202,7 @@ var import_nanoid2 = require("nanoid");
202
202
  var import_api = require("@opentelemetry/api");
203
203
 
204
204
  // package.json
205
- var version = "0.23.10";
205
+ var version = "0.23.12";
206
206
 
207
207
  // tracing/index.ts
208
208
  function getPropagationContext(ctx) {
@@ -461,10 +461,12 @@ var Session = class {
461
461
  this.connection.close();
462
462
  this.connection = void 0;
463
463
  }
464
- replaceWithNewConnection(newConn) {
464
+ replaceWithNewConnection(newConn, isTransparentReconnect) {
465
465
  this.closeStaleConnection(newConn);
466
466
  this.cancelGrace();
467
- this.sendBufferedMessages(newConn);
467
+ if (isTransparentReconnect) {
468
+ this.sendBufferedMessages(newConn);
469
+ }
468
470
  this.connection = newConn;
469
471
  this.handshakingConnection = void 0;
470
472
  }
@@ -476,19 +478,8 @@ var Session = class {
476
478
  `starting ${this.options.sessionDisconnectGraceMs}ms grace period until session to ${this.to} is closed`,
477
479
  this.loggingMetadata
478
480
  );
479
- this.cancelGrace({ keepHeartbeatMisses: true });
481
+ this.cancelGrace();
480
482
  this.disconnectionGrace = setTimeout(() => {
481
- if (this.connection !== void 0) {
482
- this.log?.warn(
483
- `grace period for ${this.to} elapsed while connected. not calling callback`,
484
- {
485
- ...this.loggingMetadata,
486
- connId: this.connection.id,
487
- tags: ["invariant-violation"]
488
- }
489
- );
490
- return;
491
- }
492
483
  this.log?.info(
493
484
  `grace period for ${this.to} elapsed`,
494
485
  this.loggingMetadata
@@ -497,14 +488,8 @@ var Session = class {
497
488
  }, this.options.sessionDisconnectGraceMs);
498
489
  }
499
490
  // called on reconnect of the underlying session
500
- cancelGrace({ keepHeartbeatMisses } = {
501
- keepHeartbeatMisses: false
502
- }) {
503
- if (!keepHeartbeatMisses) {
504
- this.heartbeatMisses = 0;
505
- }
506
- if (this.disconnectionGrace === void 0)
507
- return;
491
+ cancelGrace() {
492
+ this.heartbeatMisses = 0;
508
493
  clearTimeout(this.disconnectionGrace);
509
494
  this.disconnectionGrace = void 0;
510
495
  }
@@ -765,21 +750,17 @@ var Transport = class {
765
750
  * and we know the identity of the connected client.
766
751
  * @param conn The connection object.
767
752
  */
768
- onConnect(conn, connectedTo, session, isReconnect) {
753
+ onConnect(conn, session, isTransparentReconnect) {
769
754
  this.eventDispatcher.dispatchEvent("connectionStatus", {
770
755
  status: "connect",
771
756
  conn
772
757
  });
773
758
  conn.telemetry = createConnectionTelemetryInfo(conn, session.telemetry);
774
- if (isReconnect) {
775
- session.replaceWithNewConnection(conn);
776
- this.log?.info(`reconnected to ${connectedTo}`, {
777
- ...conn.loggingMetadata,
778
- ...session.loggingMetadata,
779
- clientId: this.clientId,
780
- connectedTo
781
- });
782
- }
759
+ session.replaceWithNewConnection(conn, isTransparentReconnect);
760
+ this.log?.info(`connected to ${session.to}`, {
761
+ ...conn.loggingMetadata,
762
+ ...session.loggingMetadata
763
+ });
783
764
  }
784
765
  createSession(to, conn, propagationCtx) {
785
766
  const session = new Session(
@@ -807,7 +788,8 @@ var Transport = class {
807
788
  propagationCtx
808
789
  }) {
809
790
  let session = this.sessions.get(to);
810
- let isReconnect = session !== void 0;
791
+ const isReconnect = session !== void 0;
792
+ let isTransparentReconnect = isReconnect;
811
793
  if (session?.advertisedSessionId !== void 0 && sessionId !== void 0 && session.advertisedSessionId !== sessionId) {
812
794
  this.log?.info(
813
795
  `session for ${to} already exists but has a different session id (expected: ${session.advertisedSessionId}, got: ${sessionId}), creating a new one`,
@@ -818,7 +800,7 @@ var Transport = class {
818
800
  closeHandshakingConnection: handshakingConn !== void 0,
819
801
  handshakingConn
820
802
  });
821
- isReconnect = false;
803
+ isTransparentReconnect = false;
822
804
  session = void 0;
823
805
  }
824
806
  if (!session) {
@@ -834,7 +816,7 @@ var Transport = class {
834
816
  if (handshakingConn !== void 0) {
835
817
  session.replaceWithNewHandshakingConnection(handshakingConn);
836
818
  }
837
- return { session, isReconnect };
819
+ return { session, isReconnect, isTransparentReconnect };
838
820
  }
839
821
  deleteSession({
840
822
  session,
@@ -1110,12 +1092,16 @@ var ClientTransport = class extends Transport {
1110
1092
  if (session) {
1111
1093
  this.onDisconnect(conn, session);
1112
1094
  }
1113
- this.log?.info(`connection to ${to} disconnected`, {
1114
- ...conn.loggingMetadata,
1115
- ...session?.loggingMetadata,
1116
- clientId: this.clientId,
1117
- connectedTo: to
1118
- });
1095
+ const willReconnect = this.reconnectOnConnectionDrop && this.getStatus() === "open";
1096
+ this.log?.info(
1097
+ `connection to ${to} disconnected` + (willReconnect ? ", reconnecting" : ""),
1098
+ {
1099
+ ...conn.loggingMetadata,
1100
+ ...session?.loggingMetadata,
1101
+ clientId: this.clientId,
1102
+ connectedTo: to
1103
+ }
1104
+ );
1119
1105
  this.inflightConnectionPromises.delete(to);
1120
1106
  if (this.reconnectOnConnectionDrop) {
1121
1107
  void this.connect(to);
@@ -1190,19 +1176,38 @@ var ClientTransport = class extends Transport {
1190
1176
  );
1191
1177
  return false;
1192
1178
  }
1179
+ const previousSession = this.sessions.get(parsed.from);
1180
+ if (previousSession?.advertisedSessionId && previousSession.advertisedSessionId !== parsed.payload.status.sessionId) {
1181
+ this.deleteSession({
1182
+ session: previousSession,
1183
+ closeHandshakingConnection: true
1184
+ });
1185
+ conn.telemetry?.span.setStatus({
1186
+ code: import_api3.SpanStatusCode.ERROR,
1187
+ message: "session id mismatch"
1188
+ });
1189
+ this.log?.warn(`handshake from ${parsed.from} session id mismatch`, {
1190
+ ...conn.loggingMetadata,
1191
+ clientId: this.clientId,
1192
+ connectedTo: parsed.from,
1193
+ transportMessage: parsed
1194
+ });
1195
+ this.protocolError(ProtocolError.HandshakeFailed, "session id mismatch");
1196
+ return false;
1197
+ }
1193
1198
  this.log?.debug(`handshake from ${parsed.from} ok`, {
1194
1199
  ...conn.loggingMetadata,
1195
1200
  clientId: this.clientId,
1196
1201
  connectedTo: parsed.from,
1197
1202
  transportMessage: parsed
1198
1203
  });
1199
- const { session, isReconnect } = this.getOrCreateSession({
1204
+ const { session, isTransparentReconnect } = this.getOrCreateSession({
1200
1205
  to: parsed.from,
1201
1206
  conn,
1202
1207
  sessionId: parsed.payload.status.sessionId
1203
1208
  });
1204
- this.onConnect(conn, parsed.from, session, isReconnect);
1205
- this.retryBudget.startRestoringBudget(parsed.from);
1209
+ this.onConnect(conn, session, isTransparentReconnect);
1210
+ this.retryBudget.startRestoringBudget(session.to);
1206
1211
  return session;
1207
1212
  }
1208
1213
  /**
@@ -1210,6 +1215,13 @@ var ClientTransport = class extends Transport {
1210
1215
  * @param to The client ID of the node to connect to.
1211
1216
  */
1212
1217
  async connect(to) {
1218
+ if (this.connections.has(to)) {
1219
+ this.log?.info(`already connected to ${to}, skipping connect attempt`, {
1220
+ clientId: this.clientId,
1221
+ connectedTo: to
1222
+ });
1223
+ return;
1224
+ }
1213
1225
  const canProceedWithConnection = () => this.getStatus() === "open";
1214
1226
  if (!canProceedWithConnection()) {
1215
1227
  this.log?.info(
@@ -1220,8 +1232,8 @@ var ClientTransport = class extends Transport {
1220
1232
  }
1221
1233
  let reconnectPromise = this.inflightConnectionPromises.get(to);
1222
1234
  if (!reconnectPromise) {
1223
- const budgetConsumed = this.retryBudget.getBudgetConsumed(to);
1224
1235
  if (!this.retryBudget.hasBudget(to)) {
1236
+ const budgetConsumed = this.retryBudget.getBudgetConsumed(to);
1225
1237
  const errMsg = `tried to connect to ${to} but retry budget exceeded (more than ${budgetConsumed} attempts in the last ${this.retryBudget.totalBudgetRestoreTime}ms)`;
1226
1238
  this.log?.error(errMsg, { clientId: this.clientId, connectedTo: to });
1227
1239
  this.protocolError(ProtocolError.RetriesExceeded, errMsg);
@@ -1302,7 +1314,7 @@ var ClientTransport = class extends Transport {
1302
1314
  clientId: this.clientId,
1303
1315
  connectedTo: to
1304
1316
  });
1305
- return this.connect(to);
1317
+ await this.connect(to);
1306
1318
  }
1307
1319
  }
1308
1320
  }