Skip to content

Commit

Permalink
Change connection handler to prependListener, add more trace logging
Browse files Browse the repository at this point in the history
  • Loading branch information
murgatroid99 committed Feb 13, 2025
1 parent 6e901c1 commit bb6fff7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 4 additions & 1 deletion packages/grpc-js/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -576,9 +576,11 @@ export class Server {
enableTrace: this.options['grpc-node.tls_enable_trace'] === 1
};
let areCredentialsValid = credentialsSettings !== null;
this.trace('Initial credentials valid: ' + areCredentialsValid);
http2Server = http2.createSecureServer(secureServerOptions);
http2Server.on('connection', (socket: Socket) => {
http2Server.prependListener('connection', (socket: Socket) => {
if (!areCredentialsValid) {
this.trace('Dropped connection from ' + JSON.stringify(socket.address()) + ' due to unloaded credentials');
socket.destroy();
}
});
Expand All @@ -596,6 +598,7 @@ export class Server {
(http2Server as http2.Http2SecureServer).setSecureContext(options);
}
areCredentialsValid = options !== null;
this.trace('Post-update credentials valid: ' + areCredentialsValid);
}
credentials._addWatcher(credsWatcher);
http2Server.on('close', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/grpc-js/src/transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,7 @@ export class Http2SubchannelConnector implements SubchannelConnector {
}
let tcpConnection: net.Socket | null = null;
let secureConnectResult: SecureConnectResult | null = null;
const addressString = this.trace(subchannelAddressToString(address));
const addressString = subchannelAddressToString(address);
try {
tcpConnection = await this.tcpConnect(address, options);
this.trace(addressString + ' ' + 'Established TCP connection');
Expand Down

0 comments on commit bb6fff7

Please sign in to comment.