Skip to content

Commit 63d9f6a

Browse files
committed
Ensure ordering between received messages and status
1 parent 59a2cbc commit 63d9f6a

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

packages/grpc-js/src/load-balancing-call.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ export class LoadBalancingCall implements Call {
4444
private writeFilterPending = false;
4545
private pendingMessage: {context: MessageContext, message: Buffer} | null = null;
4646
private pendingHalfClose = false;
47+
private readFilterPending = false;
48+
private pendingChildStatus: StatusObject | null = null;
4749
private ended = false;
4850
private serviceUrl: string;
4951
private filterStack: FilterStack;
@@ -153,14 +155,23 @@ export class LoadBalancingCall implements Call {
153155
this.listener!.onReceiveMetadata(this.filterStack.receiveMetadata(metadata));
154156
},
155157
onReceiveMessage: message => {
158+
this.readFilterPending = true;
156159
this.filterStack.receiveMessage(message).then(filteredMesssage => {
160+
this.readFilterPending = false;
157161
this.listener!.onReceiveMessage(filteredMesssage);
162+
if (this.pendingChildStatus) {
163+
this.outputStatus(this.pendingChildStatus, 'PROCESSED');
164+
}
158165
}, (status: StatusObject) => {
159166
this.cancelWithStatus(status.code, status.details);
160167
});
161168
},
162169
onReceiveStatus: status => {
163-
this.outputStatus(status, 'PROCESSED');
170+
if (this.readFilterPending) {
171+
this.pendingChildStatus = status;
172+
} else {
173+
this.outputStatus(status, 'PROCESSED');
174+
}
164175
}
165176
});
166177
} catch (error) {

0 commit comments

Comments
 (0)