@actuallab/rpc 15.0.17 → 15.0.21

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 CHANGED
@@ -1014,6 +1014,14 @@ var RpcError = class extends Error {
1014
1014
  this.typeName = typeName;
1015
1015
  }
1016
1016
  };
1017
+ var CANCELLATION_TYPE_NAMES = /* @__PURE__ */ new Set([
1018
+ "System.OperationCanceledException",
1019
+ "System.Threading.Tasks.TaskCanceledException",
1020
+ "ActualLab.Rpc.RpcRerouteException"
1021
+ ]);
1022
+ function isCancellationTypeName(typeName) {
1023
+ return typeName !== void 0 && CANCELLATION_TYPE_NAMES.has(typeName);
1024
+ }
1017
1025
  var REMOTE_EXCEPTION_TYPE_REF = "ActualLab.Serialization.RemoteException, ActualLab.Core";
1018
1026
  var genericErrorFilter = () => ({
1019
1027
  TypeRef: REMOTE_EXCEPTION_TYPE_REF,
@@ -1173,15 +1181,21 @@ var RpcSystemCallHandler = class {
1173
1181
  const call = peer.outboundCalls.get(relatedId);
1174
1182
  if (call !== void 0) {
1175
1183
  call.completedStage |= RpcCallStage.ResultReady;
1176
- if (call.removeOnOk) {
1184
+ const errorInfo = args[0];
1185
+ const typeName = extractTypeName(errorInfo?.TypeRef ?? errorInfo?.typeRef);
1186
+ const isCancelled = !call.removeOnOk && isCancellationTypeName(typeName);
1187
+ if (call.removeOnOk || isCancelled) {
1177
1188
  peer.outboundCalls.remove(relatedId);
1178
1189
  }
1179
- const errorInfo = args[0];
1180
1190
  const msg = errorInfo?.Message ?? errorInfo?.message ?? "RPC error";
1181
- const typeName = extractTypeName(errorInfo?.TypeRef ?? errorInfo?.typeRef);
1182
1191
  if (typeName === "ActualLab.Rpc.RpcRerouteException")
1183
1192
  warnLog4?.log("Got RpcRerouteException from remote peer:", msg);
1184
- call.result.reject(new RpcError(msg, typeName));
1193
+ const error = new RpcError(msg, typeName);
1194
+ if (isCancelled)
1195
+ error.name = "AbortError";
1196
+ call.result.reject(error);
1197
+ if (isCancelled)
1198
+ call.onDisconnect();
1185
1199
  }
1186
1200
  break;
1187
1201
  }
@@ -3607,8 +3621,10 @@ var RpcClientPeer = class extends RpcPeer {
3607
3621
  call.sentAt = Date.now();
3608
3622
  }
3609
3623
  let unknownIds = null;
3624
+ let isReconciled = false;
3610
3625
  if (!isPeerChanged && eligible.length > 0) {
3611
3626
  unknownIds = await this._reconcileReconnect(eligible, closedSignal);
3627
+ isReconciled = unknownIds !== null;
3612
3628
  }
3613
3629
  const YIELD_BATCH = 20;
3614
3630
  let resentSinceYield = 0;
@@ -3621,6 +3637,17 @@ var RpcClientPeer = class extends RpcPeer {
3621
3637
  if (unknownIds !== null && !unknownIds.has(call.callId)) {
3622
3638
  continue;
3623
3639
  }
3640
+ if (!(call.remoteExecutionMode & 4)) {
3641
+ if (!isReconciled)
3642
+ continue;
3643
+ if (!call.result.isCompleted)
3644
+ call.result.reject(new Error(
3645
+ "Outbound call failed: the peer does not know the call after reconnect and AllowResend is not set."
3646
+ ));
3647
+ call.onDisconnect();
3648
+ this.outboundCalls.remove(call.callId);
3649
+ continue;
3650
+ }
3624
3651
  call.sentAt = Date.now();
3625
3652
  this._sendWireData(call.serializedWireData);
3626
3653
  resentSinceYield++;
@@ -3633,7 +3660,8 @@ var RpcClientPeer = class extends RpcPeer {
3633
3660
  /**
3634
3661
  * Ask the server which call IDs in `eligible` it no longer recognizes
3635
3662
  * via `$sys.Reconnect:3`. Returns the set of call IDs that need to be
3636
- * resent. On any failure, falls back to "resend everything".
3663
+ * resent, or `null` if the reconciliation failed: the caller then
3664
+ * resends everything that allows it.
3637
3665
  *
3638
3666
  * Wire format of the `completedStages` argument is chosen per wire format:
3639
3667
  * - JSON (json5np): plain object `{"<stage>": "<base64-of-bytes>"}` —
@@ -3657,7 +3685,7 @@ var RpcClientPeer = class extends RpcPeer {
3657
3685
  arr.push(call.callId);
3658
3686
  }
3659
3687
  if (byStage.size === 0) {
3660
- return new Set(eligible.map((c) => c.callId));
3688
+ return null;
3661
3689
  }
3662
3690
  const isBinary = this.serializationFormat.isBinary;
3663
3691
  const stagesArg = isBinary ? /* @__PURE__ */ new Map() : {};
@@ -3681,10 +3709,10 @@ var RpcClientPeer = class extends RpcPeer {
3681
3709
  );
3682
3710
  const result = await reconnectCall.result;
3683
3711
  const bytes = _toBytes2(result);
3684
- if (bytes === null) return new Set(eligible.map((c) => c.callId));
3712
+ if (bytes === null) return null;
3685
3713
  return new Set(IncreasingSeqCompressor.deserialize(bytes));
3686
3714
  } catch {
3687
- return new Set(eligible.map((c) => c.callId));
3715
+ return null;
3688
3716
  }
3689
3717
  }
3690
3718
  /** Detects a server-peer identity change by comparing the incoming