Skip to content

Commit

Permalink
fix the infinite loop on getListOfKernelsWithCachedConnection (#15252)
Browse files Browse the repository at this point in the history
  • Loading branch information
andyscho authored Feb 28, 2024
1 parent b0b8b5e commit d331387
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions src/kernels/jupyter/finder/remoteKernelFinder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,32 +170,27 @@ export class RemoteKernelFinder extends DisposableBase implements IRemoteKernelF
await this.loadCache(true, true);
}

private numberOfFailures = 0;
private getListOfKernelsWithCachedConnection(
displayProgress: boolean,
ignoreCache: boolean = false
): Promise<RemoteKernelConnectionMetadata[]> {
const usingCache = !!this.cachedConnection;
this.cachedConnection = this.cachedConnection || this.getRemoteConnectionInfo(displayProgress);
if (!this.cachedConnection || ignoreCache) {
this.cachedConnection = this.getRemoteConnectionInfo(displayProgress);
}
return this.cachedConnection
.then((connInfo) => {
this.numberOfFailures = 0;
if (connInfo && !usingCache) {
if (connInfo) {
this.cachedConnection = Promise.resolve(connInfo);
return this.listKernelsFromConnection(connInfo);
}
return connInfo ? this.listKernelsFromConnection(connInfo) : Promise.resolve([]);
return Promise.resolve([]);
})
.catch((ex) => {
this.numberOfFailures += 1;
if (this.isDisposed) {
return Promise.reject(ex);
}
if (this.numberOfFailures > 9) {
traceWarning(`Remote Kernel Finder: ${this.id} has failed to connect 10 times in a row.`, ex);
return Promise.reject(ex);
}
if (usingCache) {
return this.getListOfKernelsWithCachedConnection(displayProgress, ignoreCache);
if (!ignoreCache) {
return this.getListOfKernelsWithCachedConnection(displayProgress, true);
}
this.cachedConnection = undefined;
return Promise.reject(ex);
Expand Down

0 comments on commit d331387

Please sign in to comment.