Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 17 additions & 10 deletions packages/grpc-js/src/internal-channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ export class InternalChannel {
* first time the resolver returns a result, which includes the ConfigSelector.
*/
private configSelectionQueue: ResolvingCall[] = [];
private pickQueue: LoadBalancingCall[] = [];
private pickQueue: Set<LoadBalancingCall> = new Set();
private connectivityStateWatchers: ConnectivityStateWatcher[] = [];
private readonly defaultAuthority: string;
private readonly filterStackFactory: FilterStackFactory;
Expand Down Expand Up @@ -342,9 +342,9 @@ export class InternalChannel {
},
updateState: (connectivityState: ConnectivityState, picker: Picker) => {
this.currentPicker = picker;
const queueCopy = this.pickQueue.slice();
this.pickQueue = [];
if (queueCopy.length > 0) {
const queueCopy = this.pickQueue;
this.pickQueue = new Set();
if (queueCopy.size > 0) {
this.callRefTimerUnref();
}
for (const call of queueCopy) {
Expand Down Expand Up @@ -479,8 +479,8 @@ export class InternalChannel {
this.trace(
'callRefTimer.ref | configSelectionQueue.length=' +
this.configSelectionQueue.length +
' pickQueue.length=' +
this.pickQueue.length
' pickQueue.size=' +
this.pickQueue.size
);
this.callRefTimer.ref?.();
}
Expand All @@ -492,8 +492,8 @@ export class InternalChannel {
this.trace(
'callRefTimer.unref | configSelectionQueue.length=' +
this.configSelectionQueue.length +
' pickQueue.length=' +
this.pickQueue.length
' pickQueue.size=' +
this.pickQueue.size
);
this.callRefTimer?.unref?.();
}
Expand Down Expand Up @@ -571,10 +571,17 @@ export class InternalChannel {
}

queueCallForPick(call: LoadBalancingCall) {
this.pickQueue.push(call);
this.pickQueue.add(call);
this.callRefTimerRef();
}

removeCallFromPickQueue(call: LoadBalancingCall) {
this.pickQueue.delete(call);
if (this.pickQueue.size === 0) {
this.callRefTimerUnref();
}
}

getConfig(method: string, metadata: Metadata): GetConfigResult {
if (this.connectivityState !== ConnectivityState.SHUTDOWN) {
this.resolvingLoadBalancer.exitIdle();
Expand Down Expand Up @@ -771,7 +778,7 @@ export class InternalChannel {
for (const call of this.pickQueue) {
call.cancelWithStatus(Status.UNAVAILABLE, 'Channel closed before call started');
}
this.pickQueue = [];
this.pickQueue.clear();
if (this.callRefTimer) {
clearInterval(this.callRefTimer);
}
Expand Down
1 change: 1 addition & 0 deletions packages/grpc-js/src/load-balancing-call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ export class LoadBalancingCall implements Call, DeadlineInfoProvider {
const finalStatus = { ...status, progress };
this.listener?.onReceiveStatus(finalStatus);
this.onCallEnded?.(finalStatus.code, finalStatus.details, finalStatus.metadata);
this.channel.removeCallFromPickQueue(this);
}
}

Expand Down