Skip to content

Commit 839c0a5

Browse files
authored
Tweak the consumer + Crosis both sides aborted check to allow Crosis to unilaterally abort. (#193)
* Eliminate the aborted check on both sides. * Restore the option to return aborted; add invariant check. * Types. * Clearer docs. * clarify type comment on Aborted * linty * v13.1.0. (#194)
1 parent 93e8534 commit 839c0a5

File tree

3 files changed

+15
-26
lines changed

3 files changed

+15
-26
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@replit/crosis",
3-
"version": "13.0.0",
3+
"version": "13.1.0",
44
"description": "Goval connection and channel manager",
55
"files": [
66
"/dist"

src/client.ts

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,36 +1103,24 @@ export class Client<Ctx = null> {
11031103
this.fetchTokenAbortController = null;
11041104

11051105
const connectionMetadata = connectionMetadataFetchResult;
1106-
const aborted = connectionMetadata.error === FetchConnectionMetadataError.Aborted;
1107-
1108-
if (abortController.signal.aborted !== aborted) {
1109-
// the aborted return value and the abort signal should be equivalent
1110-
if (abortController.signal.aborted) {
1111-
// In cases where our abort signal has been called means `client.close` was called
1112-
// that means we shouldn't be calling `handleConnectError` because chan0Cb is null!
1113-
this.onUnrecoverableError(
1114-
new CrosisError(
1115-
'Expected abort returned from fetchConnectionMetadata to be truthy when the controller aborts',
1116-
),
1117-
);
1118-
1119-
return;
1120-
}
11211106

1122-
// the user shouldn't return abort without the abort signal being called, if aborting is desired
1123-
// client.close should be called
1124-
this.onUnrecoverableError(
1125-
new CrosisError(
1126-
'Abort should only be truthy returned when the abort signal is triggered',
1127-
),
1128-
);
1107+
if (abortController.signal.aborted) {
1108+
// Just return. The user called `client.close` leading to a connectionMetadata abort
1109+
// chan0Cb will be called with with an error Channel close, no need to do anything here.
11291110

11301111
return;
11311112
}
11321113

11331114
if (connectionMetadata.error === FetchConnectionMetadataError.Aborted) {
1134-
// Just return. The user called `client.close` leading to a connectionMetadata abort
1135-
// chan0Cb will be called with with an error Channel close, no need to do anything here.
1115+
// A client cannot unilaterally choose to abort. If the abortController is not aborted
1116+
// the client must either return an error or valid metadata.
1117+
1118+
this.onUnrecoverableError(
1119+
new CrosisError(
1120+
'Client received abort from fetchConnectionMetadata, but the request was not aborted.',
1121+
),
1122+
);
1123+
11361124
return;
11371125
}
11381126

src/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ export enum ConnectionState {
1010

1111
export enum FetchConnectionMetadataError {
1212
/**
13-
* Fetch was aborted.
13+
* Fetch was aborted. A client may return this only if
14+
* the `AbortSignal` was already aborted.
1415
*/
1516
Aborted = 'Aborted',
1617

0 commit comments

Comments
 (0)