Skip to content

Commit

Permalink
Don't unregister the xds server's channelz ref when destroying the co…
Browse files Browse the repository at this point in the history
…nnection injector
  • Loading branch information
murgatroid99 committed Feb 27, 2025
1 parent 510d681 commit 0ebb571
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
5 changes: 4 additions & 1 deletion packages/grpc-js-xds/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ interface ConfigParameters {
createConnectionInjector: (credentials: ServerCredentials) => ConnectionInjector;
drainGraceTimeMs: number;
listenerResourceNameTemplate: string;
unregisterChannelzRef: () => void;
}

class FilterChainEntry {
Expand Down Expand Up @@ -452,6 +453,7 @@ class BoundPortEntry {
this.tcpServer.close();
const resourceName = formatTemplateString(this.configParameters.listenerResourceNameTemplate, this.boundAddress);
ListenerResourceType.cancelWatch(this.configParameters.xdsClient, resourceName, this.listenerWatcher);
this.configParameters.unregisterChannelzRef();
}
}

Expand Down Expand Up @@ -633,7 +635,8 @@ export class XdsServer extends Server {
createConnectionInjector: (credentials) => this.experimentalCreateConnectionInjectorWithChannelzRef(credentials, channelzRef),
drainGraceTimeMs: this.drainGraceTimeMs,
listenerResourceNameTemplate: this.listenerResourceNameTemplate,
xdsClient: this.xdsClient
xdsClient: this.xdsClient,
unregisterChannelzRef: () => this.experimentalUnregisterListenerFromChannelz(channelzRef)
};
const portEntry = new BoundPortEntry(configParameters, port, creds);
const servingStatusListener: ServingStatusListener = statusObject => {
Expand Down
15 changes: 11 additions & 4 deletions packages/grpc-js/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ interface BoundPort {
interface Http2ServerInfo {
channelzRef: SocketRef;
sessions: Set<http2.ServerHttp2Session>;
ownsChannelzRef: boolean;
}

interface SessionIdleTimeoutTracker {
Expand Down Expand Up @@ -571,6 +572,10 @@ export class Server {
);
}

protected experimentalUnregisterListenerFromChannelz(channelzRef: SocketRef) {
unregisterChannelzRef(channelzRef);
}

private createHttp2Server(credentials: ServerCredentials) {
let http2Server: http2.Http2Server | http2.Http2SecureServer;
if (credentials._isSecure()) {
Expand Down Expand Up @@ -670,6 +675,7 @@ export class Server {
this.http2Servers.set(http2Server, {
channelzRef: channelzRef,
sessions: new Set(),
ownsChannelzRef: true
});
boundPortObject.listeningServers.add(http2Server);
this.trace(
Expand Down Expand Up @@ -964,7 +970,7 @@ export class Server {
* @param channelzRef
* @returns
*/
protected experimentalCreateConnectionInjectorWithChannelzRef(credentials: ServerCredentials, channelzRef: SocketRef) {
protected experimentalCreateConnectionInjectorWithChannelzRef(credentials: ServerCredentials, channelzRef: SocketRef, ownsChannelzRef=false) {
if (credentials === null || !(credentials instanceof ServerCredentials)) {
throw new TypeError('creds must be a ServerCredentials object');
}
Expand All @@ -975,7 +981,8 @@ export class Server {
const sessionsSet: Set<http2.ServerHttp2Session> = new Set();
this.http2Servers.set(server, {
channelzRef: channelzRef,
sessions: sessionsSet
sessions: sessionsSet,
ownsChannelzRef
});
return {
injectConnection: (connection: Duplex) => {
Expand Down Expand Up @@ -1005,7 +1012,7 @@ export class Server {
throw new TypeError('creds must be a ServerCredentials object');
}
const channelzRef = this.registerInjectorToChannelz();
return this.experimentalCreateConnectionInjectorWithChannelzRef(credentials, channelzRef);
return this.experimentalCreateConnectionInjectorWithChannelzRef(credentials, channelzRef, true);
}

private closeServer(server: AnyHttp2Server, callback?: () => void) {
Expand All @@ -1014,7 +1021,7 @@ export class Server {
);
const serverInfo = this.http2Servers.get(server);
server.close(() => {
if (serverInfo) {
if (serverInfo && serverInfo.ownsChannelzRef) {
this.listenerChildrenTracker.unrefChild(serverInfo.channelzRef);
unregisterChannelzRef(serverInfo.channelzRef);
}
Expand Down

0 comments on commit 0ebb571

Please sign in to comment.