Skip to content

Commit e8b7ba1

Browse files
authored
Harden repo polling logic (#285)
We're seeing a few users hitting the status endpoint a ton. I suspect this is caused by our polling logic
1 parent 39f6d1b commit e8b7ba1

File tree

1 file changed

+32
-12
lines changed

1 file changed

+32
-12
lines changed

src/platform/remoteCodeSearch/node/codeSearchRepoTracker.ts

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -913,23 +913,43 @@ export class CodeSearchRepoTracker extends Disposable {
913913
}
914914

915915
if (currentRepoEntry.status === RepoStatus.BuildingIndex) {
916-
this._logService.logger.trace(`CodeSearchRepoTracker.startPollingForRepoIndexingComplete(${repo.rootUri}). Checking endpoint for status.`);
917-
const polledState = await this.getRepoIndexStatusFromEndpoint(currentRepoEntry.repo, currentRepoEntry.remoteInfo, CancellationToken.None);
918-
this._logService.logger.trace(`CodeSearchRepoTracker.startPollingForRepoIndexingComplete(${repo.rootUri}). Got back new status from endpoint: ${polledState.status}.`);
919-
920-
if (polledState.status === RepoStatus.Ready) {
921-
this._logService.logger.trace(`CodeSearchRepoTracker.startPollingForRepoIndexingComplete(${repo.rootUri}). Repo indexed successfully.`);
916+
const attemptNumber = pollEntry.attemptNumber++;
917+
if (attemptNumber > this.maxPollingAttempts) {
918+
this._logService.logger.trace(`CodeSearchRepoTracker.startPollingForRepoIndexingComplete(${repo.rootUri}). Max attempts reached. Stopping polling.`);
922919
if (!this._isDisposed) {
923-
this.updateRepoEntry(repo, polledState);
920+
this.updateRepoEntry(repo, { status: RepoStatus.CouldNotCheckIndexStatus, repo: currentRepoEntry.repo, remoteInfo: currentRepoEntry.remoteInfo });
924921
}
925922
return onComplete();
926923
}
927924

928-
if (pollEntry.attemptNumber++ > this.maxPollingAttempts) {
929-
this._logService.logger.trace(`CodeSearchRepoTracker.startPollingForRepoIndexingComplete(${repo.rootUri}). Max attempts reached. Stopping polling.`);
930-
onComplete();
931-
this.updateRepoEntry(repo, polledState);
932-
return;
925+
this._logService.logger.trace(`CodeSearchRepoTracker.startPollingForRepoIndexingComplete(${repo.rootUri}). Checking endpoint for status.`);
926+
let polledState: RepoEntry | undefined;
927+
try {
928+
polledState = await this.getRepoIndexStatusFromEndpoint(currentRepoEntry.repo, currentRepoEntry.remoteInfo, CancellationToken.None);
929+
} catch {
930+
// noop
931+
}
932+
this._logService.logger.trace(`CodeSearchRepoTracker.startPollingForRepoIndexingComplete(${repo.rootUri}). Got back new status from endpoint: ${polledState?.status}.`);
933+
934+
switch (polledState?.status) {
935+
case RepoStatus.Ready: {
936+
this._logService.logger.trace(`CodeSearchRepoTracker.startPollingForRepoIndexingComplete(${repo.rootUri}). Repo indexed successfully.`);
937+
if (!this._isDisposed) {
938+
this.updateRepoEntry(repo, polledState);
939+
}
940+
return onComplete();
941+
}
942+
case RepoStatus.BuildingIndex: {
943+
// Poll again
944+
return;
945+
}
946+
default: {
947+
// We got some other state, so stop polling
948+
if (!this._isDisposed) {
949+
this.updateRepoEntry(repo, polledState ?? { status: RepoStatus.CouldNotCheckIndexStatus, repo: currentRepoEntry.repo, remoteInfo: currentRepoEntry.remoteInfo });
950+
}
951+
return onComplete();
952+
}
933953
}
934954
} else {
935955
this._logService.logger.trace(`CodeSearchRepoTracker.startPollingForRepoIndexingComplete(${repo.rootUri}). Found unknown repo state: ${currentRepoEntry.status}. Stopping polling`);

0 commit comments

Comments
 (0)