Skip to content

Commit

Permalink
V2: Ensure that a signal exists for a completed RPC (#1282)
Browse files Browse the repository at this point in the history
  • Loading branch information
timostamm authored Oct 18, 2024
1 parent f6c9fac commit 00004e3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
7 changes: 1 addition & 6 deletions packages/connect/src/implementation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,12 @@ describe("createHandlerContext()", function () {
expect(ctx.signal.aborted).toBeTrue();
expect(ctx.signal.reason).toBe("shutdown-signal");
});
it("should trigger on abort with reason", function () {
it("should trigger on abort", function () {
const ctx = createHandlerContext({ ...standardOptions });
ctx.abort("test-reason");
expect(ctx.signal.aborted).toBeTrue();
expect(ctx.signal.reason).toBe("test-reason");
});
it("should not trigger on abort without reason", function () {
const ctx = createHandlerContext({ ...standardOptions });
ctx.abort();
expect(ctx.signal.aborted).toBeFalse();
});
});

describe("timeout()", function () {
Expand Down
9 changes: 4 additions & 5 deletions packages/connect/src/implementation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@ export interface HandlerContext {
readonly service: DescService;

/**
* An AbortSignal that triggers when the deadline is reached, or when an
* error occurs that aborts processing of the request.
* An AbortSignal that triggers when the deadline is reached, or when an error
* occurs that aborts processing of the request, but also when the RPC is
* completed without error.
*
* The signal can be used to automatically cancel downstream calls.
*/
Expand Down Expand Up @@ -175,9 +176,7 @@ export function createHandlerContext(
responseTrailer: new Headers(init.responseTrailer),
abort(reason?: unknown) {
deadline.cleanup();
if (reason !== undefined) {
abortController.abort(reason);
}
abortController.abort(reason);
},
values: init.contextValues ?? createContextValues(),
};
Expand Down

0 comments on commit 00004e3

Please sign in to comment.