Skip to content

Commit

Permalink
Handle missing filter_chain_match differently, plus other fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
murgatroid99 committed Feb 20, 2025
1 parent 87f7034 commit 5cf1a87
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 11 deletions.
15 changes: 14 additions & 1 deletion packages/grpc-js-xds/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ class ListenerConfig {
handleConnection(socket: net.Socket) {
const matchingFilter = selectMostSpecificallyMatchingFilter(this.filterChainEntries, socket) ?? this.defaultFilterChain;
if (!matchingFilter) {
trace('Rejecting connection from ' + socket.remoteAddress + ': No filter matched');
socket.destroy();
return;
}
Expand Down Expand Up @@ -456,7 +457,19 @@ class BoundPortEntry {

function normalizeFilterChainMatch(filterChainMatch: FilterChainMatch__Output | null): NormalizedFilterChainMatch[] {
if (!filterChainMatch) {
return [];
filterChainMatch = {
address_suffix: '',
application_protocols: [],
destination_port: null,
direct_source_prefix_ranges: [],
prefix_ranges: [],
server_names: [],
source_ports: [],
source_prefix_ranges: [],
source_type: 'ANY',
suffix_len: null,
transport_protocol: 'raw_buffer'
};
}
if (filterChainMatch.destination_port) {
return [];
Expand Down
24 changes: 15 additions & 9 deletions packages/grpc-js-xds/src/xds-dependency-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ export class XdsDependencyManager {
onResourceChanged: (update: Listener__Output) => {
if (!update.api_listener) {
this.trace('Received Listener resource not usable on client');
this.handleListenerDoesNotExist();
return;
}
this.latestListener = update;
Expand Down Expand Up @@ -405,15 +406,7 @@ export class XdsDependencyManager {
},
onResourceDoesNotExist: () => {
this.trace('Resolution error: LDS resource does not exist');
if (this.latestRouteConfigName) {
this.trace('RDS.cancelWatch(' + this.latestRouteConfigName + '): LDS resource does not exist');
RouteConfigurationResourceType.cancelWatch(this.xdsClient, this.latestRouteConfigName, this.rdsWatcher);
this.latestRouteConfigName = null;
this.latestRouteConfiguration = null;
this.clusterRoots = [];
this.pruneOrphanClusters();
}
this.watcher.onResourceDoesNotExist(`Listener ${listenerResourceName}`);
this.handleListenerDoesNotExist();
}
});
this.rdsWatcher = new Watcher<RouteConfiguration__Output>({
Expand All @@ -439,6 +432,19 @@ export class XdsDependencyManager {
trace('[' + this.listenerResourceName + '] ' + text);
}

private handleListenerDoesNotExist() {
if (this.latestRouteConfigName) {
this.trace('RDS.cancelWatch(' + this.latestRouteConfigName + '): LDS resource does not exist');
RouteConfigurationResourceType.cancelWatch(this.xdsClient, this.latestRouteConfigName, this.rdsWatcher);
this.latestRouteConfigName = null;
this.latestRouteConfiguration = null;
this.clusterRoots = [];
this.pruneOrphanClusters();
}
this.watcher.onResourceDoesNotExist(`Listener ${this.listenerResourceName}`);

}

private maybeSendUpdate() {
if (!this.latestListener) {
this.trace('Not sending update: no Listener update received');
Expand Down
2 changes: 1 addition & 1 deletion packages/grpc-js/src/channel-credentials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ class CertificateProviderChannelCredentialsImpl extends ChannelCredentials {
constructor(private parent: CertificateProviderChannelCredentialsImpl, private channelTarget: GrpcUri, private options: ChannelOptions, private callCredentials: CallCredentials) {}

connect(socket: Socket): Promise<SecureConnectResult> {
return new Promise(async (resolve, reject) => {
return new Promise((resolve, reject) => {
const secureContext = this.parent.getLatestSecureContext();
if (!secureContext) {
reject(new Error('Failed to load credentials'));
Expand Down

0 comments on commit 5cf1a87

Please sign in to comment.