Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

grpc-js: Fix a couple of things that came up while investigating a memory leak #2456

Merged
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
2 changes: 1 addition & 1 deletion packages/grpc-js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@grpc/grpc-js",
"version": "1.8.14",
"version": "1.8.15",
"description": "gRPC Library for Node - pure JS implementation",
"homepage": "https://grpc.io/",
"repository": "https://github.com/grpc/grpc-node/tree/master/packages/grpc-js",
Expand Down
36 changes: 24 additions & 12 deletions packages/grpc-js/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ export class Client {
emitter.call = call;
let responseMessage: ResponseType | null = null;
let receivedStatus = false;
const callerStackError = new Error();
let callerStackError: Error | null = new Error();
call.start(callProperties.metadata, {
onReceiveMetadata: (metadata) => {
emitter.emit('metadata', metadata);
Expand All @@ -342,19 +342,22 @@ export class Client {
receivedStatus = true;
if (status.code === Status.OK) {
if (responseMessage === null) {
const callerStack = getErrorStackString(callerStackError);
const callerStack = getErrorStackString(callerStackError!);
callProperties.callback!(callErrorFromStatus({
code: Status.INTERNAL,
details: 'No message received',
metadata: status.metadata
}, callerStack));
}, /*callerStack*/''));
} else {
callProperties.callback!(null, responseMessage);
}
} else {
const callerStack = getErrorStackString(callerStackError);
callProperties.callback!(callErrorFromStatus(status, callerStack));
const callerStack = getErrorStackString(callerStackError!);
callProperties.callback!(callErrorFromStatus(status, /*callerStack*/''));
}
/* Avoid retaining the callerStackError object in the call context of
* the status event handler. */
callerStackError = null;
emitter.emit('status', status);
},
});
Expand Down Expand Up @@ -448,7 +451,7 @@ export class Client {
emitter.call = call;
let responseMessage: ResponseType | null = null;
let receivedStatus = false;
const callerStackError = new Error();
let callerStackError: Error | null = new Error();
call.start(callProperties.metadata, {
onReceiveMetadata: (metadata) => {
emitter.emit('metadata', metadata);
Expand All @@ -467,7 +470,7 @@ export class Client {
receivedStatus = true;
if (status.code === Status.OK) {
if (responseMessage === null) {
const callerStack = getErrorStackString(callerStackError);
const callerStack = getErrorStackString(callerStackError!);
callProperties.callback!(callErrorFromStatus({
code: Status.INTERNAL,
details: 'No message received',
Expand All @@ -477,9 +480,12 @@ export class Client {
callProperties.callback!(null, responseMessage);
}
} else {
const callerStack = getErrorStackString(callerStackError);
const callerStack = getErrorStackString(callerStackError!);
callProperties.callback!(callErrorFromStatus(status, callerStack));
}
/* Avoid retaining the callerStackError object in the call context of
* the status event handler. */
callerStackError = null;
emitter.emit('status', status);
},
});
Expand Down Expand Up @@ -577,7 +583,7 @@ export class Client {
* call after that. */
stream.call = call;
let receivedStatus = false;
const callerStackError = new Error();
let callerStackError: Error | null = new Error();
call.start(callProperties.metadata, {
onReceiveMetadata(metadata: Metadata) {
stream.emit('metadata', metadata);
Expand All @@ -593,9 +599,12 @@ export class Client {
receivedStatus = true;
stream.push(null);
if (status.code !== Status.OK) {
const callerStack = getErrorStackString(callerStackError);
const callerStack = getErrorStackString(callerStackError!);
stream.emit('error', callErrorFromStatus(status, callerStack));
}
/* Avoid retaining the callerStackError object in the call context of
* the status event handler. */
callerStackError = null;
stream.emit('status', status);
},
});
Expand Down Expand Up @@ -673,7 +682,7 @@ export class Client {
* call after that. */
stream.call = call;
let receivedStatus = false;
const callerStackError = new Error();
let callerStackError: Error | null = new Error();
call.start(callProperties.metadata, {
onReceiveMetadata(metadata: Metadata) {
stream.emit('metadata', metadata);
Expand All @@ -688,9 +697,12 @@ export class Client {
receivedStatus = true;
stream.push(null);
if (status.code !== Status.OK) {
const callerStack = getErrorStackString(callerStackError);
const callerStack = getErrorStackString(callerStackError!);
stream.emit('error', callErrorFromStatus(status, callerStack));
}
/* Avoid retaining the callerStackError object in the call context of
* the status event handler. */
callerStackError = null;
stream.emit('status', status);
},
});
Expand Down
8 changes: 6 additions & 2 deletions packages/grpc-js/src/load-balancing-call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,14 +216,18 @@ export class LoadBalancingCall implements Call {
break;
case PickResultType.DROP:
const {code, details} = restrictControlPlaneStatusCode(pickResult.status!.code, pickResult.status!.details);
this.outputStatus({code, details, metadata: pickResult.status!.metadata}, 'DROP');
setImmediate(() => {
this.outputStatus({code, details, metadata: pickResult.status!.metadata}, 'DROP');
});
break;
case PickResultType.TRANSIENT_FAILURE:
if (this.metadata.getOptions().waitForReady) {
this.channel.queueCallForPick(this);
} else {
const {code, details} = restrictControlPlaneStatusCode(pickResult.status!.code, pickResult.status!.details);
this.outputStatus({code, details, metadata: pickResult.status!.metadata}, 'PROCESSED');
setImmediate(() => {
this.outputStatus({code, details, metadata: pickResult.status!.metadata}, 'PROCESSED');
});
}
break;
case PickResultType.QUEUE:
Expand Down