Skip to content

Commit 55b9852

Browse files
authored
Merge pull request #2683 from murgatroid99/grpc-js_server_event_order
grpc-js: Rearrange some function calls to revert event order changes
2 parents cb966df + 07ee52a commit 55b9852

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

packages/grpc-js/src/server-call.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -200,11 +200,11 @@ export class ServerWritableStreamImpl<RequestType, ResponseType>
200200
}
201201

202202
_final(callback: Function): void {
203+
callback(null);
203204
this.call.sendStatus({
204205
...this.pendingStatus,
205206
metadata: this.pendingStatus.metadata ?? this.trailingMetadata,
206207
});
207-
callback(null);
208208
}
209209

210210
// eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -273,11 +273,11 @@ export class ServerDuplexStreamImpl<RequestType, ResponseType>
273273
}
274274

275275
_final(callback: Function): void {
276+
callback(null);
276277
this.call.sendStatus({
277278
...this.pendingStatus,
278279
metadata: this.pendingStatus.metadata ?? this.trailingMetadata,
279280
});
280-
callback(null);
281281
}
282282

283283
// eslint-disable-next-line @typescript-eslint/no-explicit-any

packages/grpc-js/src/server-interceptors.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -842,7 +842,6 @@ export class BaseServerInterceptingCall
842842
if (this.checkCancelled()) {
843843
return;
844844
}
845-
this.notifyOnCancel();
846845

847846
trace(
848847
'Request to method ' +
@@ -869,8 +868,11 @@ export class BaseServerInterceptingCall
869868
};
870869

871870
this.stream.sendTrailers(trailersToSend);
871+
this.notifyOnCancel();
872872
});
873873
this.stream.end();
874+
} else {
875+
this.notifyOnCancel();
874876
}
875877
} else {
876878
if (this.callEventTracker && !this.streamEnded) {
@@ -886,6 +888,7 @@ export class BaseServerInterceptingCall
886888
...status.metadata?.toHttp2Headers(),
887889
};
888890
this.stream.respond(trailersToSend, { endStream: true });
891+
this.notifyOnCancel();
889892
}
890893
}
891894
startRead(): void {

0 commit comments

Comments
 (0)