From 07ee52acb04625f08092da59ad823c8651f41bee Mon Sep 17 00:00:00 2001 From: Michael Lumish Date: Tue, 5 Mar 2024 10:26:39 -0800 Subject: [PATCH] grpc-js: Rearrange some function calls to revert event order changes --- packages/grpc-js/src/server-call.ts | 4 ++-- packages/grpc-js/src/server-interceptors.ts | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/grpc-js/src/server-call.ts b/packages/grpc-js/src/server-call.ts index 95393fba9..77fee7df2 100644 --- a/packages/grpc-js/src/server-call.ts +++ b/packages/grpc-js/src/server-call.ts @@ -200,11 +200,11 @@ export class ServerWritableStreamImpl } _final(callback: Function): void { + callback(null); this.call.sendStatus({ ...this.pendingStatus, metadata: this.pendingStatus.metadata ?? this.trailingMetadata, }); - callback(null); } // eslint-disable-next-line @typescript-eslint/no-explicit-any @@ -273,11 +273,11 @@ export class ServerDuplexStreamImpl } _final(callback: Function): void { + callback(null); this.call.sendStatus({ ...this.pendingStatus, metadata: this.pendingStatus.metadata ?? this.trailingMetadata, }); - callback(null); } // eslint-disable-next-line @typescript-eslint/no-explicit-any diff --git a/packages/grpc-js/src/server-interceptors.ts b/packages/grpc-js/src/server-interceptors.ts index 60c5c8865..9dfbbb2ff 100644 --- a/packages/grpc-js/src/server-interceptors.ts +++ b/packages/grpc-js/src/server-interceptors.ts @@ -842,7 +842,6 @@ export class BaseServerInterceptingCall if (this.checkCancelled()) { return; } - this.notifyOnCancel(); trace( 'Request to method ' + @@ -869,8 +868,11 @@ export class BaseServerInterceptingCall }; this.stream.sendTrailers(trailersToSend); + this.notifyOnCancel(); }); this.stream.end(); + } else { + this.notifyOnCancel(); } } else { if (this.callEventTracker && !this.streamEnded) { @@ -886,6 +888,7 @@ export class BaseServerInterceptingCall ...status.metadata?.toHttp2Headers(), }; this.stream.respond(trailersToSend, { endStream: true }); + this.notifyOnCancel(); } } startRead(): void {