Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add timeout to extension download requests #23

Open
wants to merge 2 commits into
base: leapide-code-1.58.2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
3 changes: 2 additions & 1 deletion src/vs/gitpod/node/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,8 @@ async function downloadInitialExtension(url: string, requestService: IRequestSer
const context = await requestService.request({
type: 'GET', url, headers: {
'Content-Type': '*/*' // GCP requires that the content-type header match those used during the signing operation (*/* in our case)
}
},
timeout: 60000
}, CancellationToken.None);
if (context.res.statusCode !== 200) {
const message = await asText(context);
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