Skip to content

Commit

Permalink
Add timeout to extension gallery requests, expose as config param
Browse files Browse the repository at this point in the history
New vscode config option is `extensionsGallery.requestTimeout`, defaults
to 60 seconds.
  • Loading branch information
randomir committed Aug 12, 2022
1 parent 7175cd3 commit 555c575
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
3 changes: 2 additions & 1 deletion product.json
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,8 @@
"itemUrl": "https://open-vsx.org/vscode/item",
"resourceUrlTemplate": "",
"controlUrl": "",
"recommendationsUrl": ""
"recommendationsUrl": "",
"requestTimeout": 60000
},
"linkProtectionTrustedDomains": [
"https://open-vsx.org",
Expand Down
1 change: 1 addition & 0 deletions src/vs/base/common/product.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export interface IProductConfiguration {
readonly resourceUrlTemplate: string;
readonly controlUrl: string;
readonly recommendationsUrl: string;
readonly requestTimeout?: number;
};

readonly extensionTips?: { [id: string]: string; };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ export class ExtensionGalleryService implements IExtensionGalleryService {

private extensionsGalleryUrl: string | undefined;
private extensionsControlUrl: string | undefined;
private extensionsGalleryTimeout: number | undefined;

private readonly commonHeadersPromise: Promise<{ [key: string]: string; }>;

Expand All @@ -384,6 +385,7 @@ export class ExtensionGalleryService implements IExtensionGalleryService {
this.extensionsGalleryUrl = config && config.serviceUrl;
this.extensionsControlUrl = config && config.controlUrl;
this.commonHeadersPromise = resolveMarketplaceHeaders(productService.version, this.environmentService, this.fileService, storageService);
this.extensionsGalleryTimeout = config?.requestTimeout ?? 60000;
}

private api(path = ''): string {
Expand Down Expand Up @@ -556,6 +558,7 @@ export class ExtensionGalleryService implements IExtensionGalleryService {
context = await this.requestService.request({
type: 'POST',
url: this.api('/extensionquery'),
timeout: this.extensionsGalleryTimeout,
data,
headers
}, token);
Expand Down Expand Up @@ -605,6 +608,7 @@ export class ExtensionGalleryService implements IExtensionGalleryService {
await this.requestService.request({
type: 'POST',
url: this.api(`/publishers/${publisher}/extensions/${name}/${version}/stats?statType=${type}`),
timeout: this.extensionsGalleryTimeout,
headers
}, CancellationToken.None);
} catch (error) { /* Ignore */ }
Expand Down Expand Up @@ -706,7 +710,7 @@ export class ExtensionGalleryService implements IExtensionGalleryService {

private async getAsset(asset: IGalleryExtensionAsset, options: IRequestOptions = {}, token: CancellationToken = CancellationToken.None): Promise<IRequestContext> {
const commonHeaders = await this.commonHeadersPromise;
const baseOptions = { type: 'GET' };
const baseOptions = { type: 'GET', timeout: this.extensionsGalleryTimeout };
const headers = { ...commonHeaders, ...(options.headers || {}) };
options = { ...options, ...baseOptions, headers };

Expand Down Expand Up @@ -810,7 +814,11 @@ export class ExtensionGalleryService implements IExtensionGalleryService {
return [];
}

const context = await this.requestService.request({ type: 'GET', url: this.extensionsControlUrl }, CancellationToken.None);
const context = await this.requestService.request({
type: 'GET',
url: this.extensionsControlUrl,
timeout: this.extensionsGalleryTimeout
}, CancellationToken.None);
if (context.res.statusCode !== 200) {
throw new Error('Could not get extensions report.');
}
Expand Down

0 comments on commit 555c575

Please sign in to comment.