Merge remote-tracking branch 'upstream/@grpc/grpc-js@1.5.x' into v1.5.x_upmerge

This commit is contained in:
Michael Lumish 2022-03-24 15:18:39 -07:00
commit 6e804d741f
2 changed files with 95 additions and 54 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "@grpc/grpc-js", "name": "@grpc/grpc-js",
"version": "1.5.9", "version": "1.5.10",
"description": "gRPC Library for Node - pure JS implementation", "description": "gRPC Library for Node - pure JS implementation",
"homepage": "https://grpc.io/", "homepage": "https://grpc.io/",
"repository": "https://github.com/grpc/grpc-node/tree/master/packages/grpc-js", "repository": "https://github.com/grpc/grpc-node/tree/master/packages/grpc-js",

View File

@ -430,27 +430,36 @@ export class Server {
port: boundAddress.port port: boundAddress.port
} }
} }
const channelzRef = registerChannelzSocket(subchannelAddressToString(boundSubchannelAddress), () => { let channelzRef: SocketRef;
return { if (this.channelzEnabled) {
localAddress: boundSubchannelAddress, channelzRef = registerChannelzSocket(subchannelAddressToString(boundSubchannelAddress), () => {
remoteAddress: null, return {
security: null, localAddress: boundSubchannelAddress,
remoteName: null, remoteAddress: null,
streamsStarted: 0, security: null,
streamsSucceeded: 0, remoteName: null,
streamsFailed: 0, streamsStarted: 0,
messagesSent: 0, streamsSucceeded: 0,
messagesReceived: 0, streamsFailed: 0,
keepAlivesSent: 0, messagesSent: 0,
lastLocalStreamCreatedTimestamp: null, messagesReceived: 0,
lastRemoteStreamCreatedTimestamp: null, keepAlivesSent: 0,
lastMessageSentTimestamp: null, lastLocalStreamCreatedTimestamp: null,
lastMessageReceivedTimestamp: null, lastRemoteStreamCreatedTimestamp: null,
localFlowControlWindow: null, lastMessageSentTimestamp: null,
remoteFlowControlWindow: null lastMessageReceivedTimestamp: null,
localFlowControlWindow: null,
remoteFlowControlWindow: null
};
});
this.listenerChildrenTracker.refChild(channelzRef);
} else {
channelzRef = {
kind: 'socket',
id: -1,
name: ''
}; };
}); }
this.listenerChildrenTracker.refChild(channelzRef);
this.http2ServerList.push({server: http2Server, channelzRef: channelzRef}); this.http2ServerList.push({server: http2Server, channelzRef: channelzRef});
this.trace('Successfully bound ' + subchannelAddressToString(boundSubchannelAddress)); this.trace('Successfully bound ' + subchannelAddressToString(boundSubchannelAddress));
resolve('port' in boundSubchannelAddress ? boundSubchannelAddress.port : portNum); resolve('port' in boundSubchannelAddress ? boundSubchannelAddress.port : portNum);
@ -499,27 +508,36 @@ export class Server {
host: boundAddress.address, host: boundAddress.address,
port: boundAddress.port port: boundAddress.port
}; };
const channelzRef = registerChannelzSocket(subchannelAddressToString(boundSubchannelAddress), () => { let channelzRef: SocketRef;
return { if (this.channelzEnabled) {
localAddress: boundSubchannelAddress, channelzRef = registerChannelzSocket(subchannelAddressToString(boundSubchannelAddress), () => {
remoteAddress: null, return {
security: null, localAddress: boundSubchannelAddress,
remoteName: null, remoteAddress: null,
streamsStarted: 0, security: null,
streamsSucceeded: 0, remoteName: null,
streamsFailed: 0, streamsStarted: 0,
messagesSent: 0, streamsSucceeded: 0,
messagesReceived: 0, streamsFailed: 0,
keepAlivesSent: 0, messagesSent: 0,
lastLocalStreamCreatedTimestamp: null, messagesReceived: 0,
lastRemoteStreamCreatedTimestamp: null, keepAlivesSent: 0,
lastMessageSentTimestamp: null, lastLocalStreamCreatedTimestamp: null,
lastMessageReceivedTimestamp: null, lastRemoteStreamCreatedTimestamp: null,
localFlowControlWindow: null, lastMessageSentTimestamp: null,
remoteFlowControlWindow: null lastMessageReceivedTimestamp: null,
localFlowControlWindow: null,
remoteFlowControlWindow: null
};
});
this.listenerChildrenTracker.refChild(channelzRef);
} else {
channelzRef = {
kind: 'socket',
id: -1,
name: ''
}; };
}); }
this.listenerChildrenTracker.refChild(channelzRef);
this.http2ServerList.push({server: http2Server, channelzRef: channelzRef}); this.http2ServerList.push({server: http2Server, channelzRef: channelzRef});
this.trace('Successfully bound ' + subchannelAddressToString(boundSubchannelAddress)); this.trace('Successfully bound ' + subchannelAddressToString(boundSubchannelAddress));
resolve( resolve(
@ -599,8 +617,10 @@ export class Server {
for (const {server: http2Server, channelzRef: ref} of this.http2ServerList) { for (const {server: http2Server, channelzRef: ref} of this.http2ServerList) {
if (http2Server.listening) { if (http2Server.listening) {
http2Server.close(() => { http2Server.close(() => {
this.listenerChildrenTracker.unrefChild(ref); if (this.channelzEnabled) {
unregisterChannelzRef(ref); this.listenerChildrenTracker.unrefChild(ref);
unregisterChannelzRef(ref);
}
}); });
} }
} }
@ -616,7 +636,9 @@ export class Server {
session.destroy(http2.constants.NGHTTP2_CANCEL as any); session.destroy(http2.constants.NGHTTP2_CANCEL as any);
}); });
this.sessions.clear(); this.sessions.clear();
unregisterChannelzRef(this.channelzRef); if (this.channelzEnabled) {
unregisterChannelzRef(this.channelzRef);
}
} }
register<RequestType, ResponseType>( register<RequestType, ResponseType>(
@ -665,7 +687,9 @@ export class Server {
tryShutdown(callback: (error?: Error) => void): void { tryShutdown(callback: (error?: Error) => void): void {
const wrappedCallback = (error?: Error) => { const wrappedCallback = (error?: Error) => {
unregisterChannelzRef(this.channelzRef); if (this.channelzEnabled) {
unregisterChannelzRef(this.channelzRef);
}
callback(error); callback(error);
}; };
let pendingChecks = 0; let pendingChecks = 0;
@ -685,8 +709,10 @@ export class Server {
if (http2Server.listening) { if (http2Server.listening) {
pendingChecks++; pendingChecks++;
http2Server.close(() => { http2Server.close(() => {
this.listenerChildrenTracker.unrefChild(ref); if (this.channelzEnabled) {
unregisterChannelzRef(ref); this.listenerChildrenTracker.unrefChild(ref);
unregisterChannelzRef(ref);
}
maybeCallback(); maybeCallback();
}); });
} }
@ -727,8 +753,10 @@ export class Server {
'stream', 'stream',
(stream: http2.ServerHttp2Stream, headers: http2.IncomingHttpHeaders) => { (stream: http2.ServerHttp2Stream, headers: http2.IncomingHttpHeaders) => {
const channelzSessionInfo = this.sessions.get(stream.session as http2.ServerHttp2Session); const channelzSessionInfo = this.sessions.get(stream.session as http2.ServerHttp2Session);
this.callTracker.addCallStarted(); if (this.channelzEnabled) {
channelzSessionInfo?.streamTracker.addCallStarted(); this.callTracker.addCallStarted();
channelzSessionInfo?.streamTracker.addCallStarted();
}
const contentType = headers[http2.constants.HTTP2_HEADER_CONTENT_TYPE]; const contentType = headers[http2.constants.HTTP2_HEADER_CONTENT_TYPE];
if ( if (
@ -743,7 +771,9 @@ export class Server {
{ endStream: true } { endStream: true }
); );
this.callTracker.addCallFailed(); this.callTracker.addCallFailed();
channelzSessionInfo?.streamTracker.addCallFailed(); if (this.channelzEnabled) {
channelzSessionInfo?.streamTracker.addCallFailed();
}
return; return;
} }
@ -786,7 +816,7 @@ export class Server {
this.callTracker.addCallFailed(); this.callTracker.addCallFailed();
} }
}); });
if (channelzSessionInfo) { if (this.channelzEnabled && channelzSessionInfo) {
call.once('streamEnd', (success: boolean) => { call.once('streamEnd', (success: boolean) => {
if (success) { if (success) {
channelzSessionInfo.streamTracker.addCallSucceeded(); channelzSessionInfo.streamTracker.addCallSucceeded();
@ -841,8 +871,10 @@ export class Server {
} catch (err) { } catch (err) {
if (!call) { if (!call) {
call = new Http2ServerCallStream(stream, null!, this.options); call = new Http2ServerCallStream(stream, null!, this.options);
this.callTracker.addCallFailed(); if (this.channelzEnabled) {
channelzSessionInfo?.streamTracker.addCallFailed() this.callTracker.addCallFailed();
channelzSessionInfo?.streamTracker.addCallFailed()
}
} }
if (err.code === undefined) { if (err.code === undefined) {
@ -860,7 +892,16 @@ export class Server {
return; return;
} }
const channelzRef = registerChannelzSocket(session.socket.remoteAddress ?? 'unknown', this.getChannelzSessionInfoGetter(session)); let channelzRef: SocketRef;
if (this.channelzEnabled) {
channelzRef = registerChannelzSocket(session.socket.remoteAddress ?? 'unknown', this.getChannelzSessionInfoGetter(session));
} else {
channelzRef = {
kind: 'socket',
id: -1,
name: ''
}
}
const channelzSessionInfo: ChannelzSessionInfo = { const channelzSessionInfo: ChannelzSessionInfo = {
ref: channelzRef, ref: channelzRef,