Skip to content

Commit

Permalink
Ensure ordering between received messages and status
Browse files Browse the repository at this point in the history
  • Loading branch information
murgatroid99 committed Oct 14, 2022
1 parent 59a2cbc commit 63d9f6a
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion packages/grpc-js/src/load-balancing-call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ export class LoadBalancingCall implements Call {
private writeFilterPending = false;
private pendingMessage: {context: MessageContext, message: Buffer} | null = null;
private pendingHalfClose = false;
private readFilterPending = false;
private pendingChildStatus: StatusObject | null = null;
private ended = false;
private serviceUrl: string;
private filterStack: FilterStack;
Expand Down Expand Up @@ -153,14 +155,23 @@ export class LoadBalancingCall implements Call {
this.listener!.onReceiveMetadata(this.filterStack.receiveMetadata(metadata));
},
onReceiveMessage: message => {
this.readFilterPending = true;
this.filterStack.receiveMessage(message).then(filteredMesssage => {
this.readFilterPending = false;
this.listener!.onReceiveMessage(filteredMesssage);
if (this.pendingChildStatus) {
this.outputStatus(this.pendingChildStatus, 'PROCESSED');
}
}, (status: StatusObject) => {
this.cancelWithStatus(status.code, status.details);
});
},
onReceiveStatus: status => {
this.outputStatus(status, 'PROCESSED');
if (this.readFilterPending) {
this.pendingChildStatus = status;
} else {
this.outputStatus(status, 'PROCESSED');
}
}
});
} catch (error) {
Expand Down

0 comments on commit 63d9f6a

Please sign in to comment.