From 4755e9c2fe9bf6a921bb4a57e4dcf1ab8df0a6aa Mon Sep 17 00:00:00 2001 From: Connor Peet Date: Mon, 12 Dec 2022 10:37:37 -0800 Subject: [PATCH] fix: add ipv4->6 fallback Fixes https://github.com/microsoft/vscode/issues/167353 --- CHANGELOG.md | 1 + .../resourceProvider/basicResourceProvider.ts | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 83b41b637..095d65b85 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ This changelog records changes to stable releases since 1.50.2. "TBA" changes he - fix: custom object `toString()` previews being too short ([vscode#155142](https://github.com/microsoft/vscode/issues/155142)) - fix: show warning if console output length is hit ([vscode#154479](https://github.com/microsoft/vscode/issues/154479)) - fix: improve variable and repl performance in large projects ([#1433](https://github.com/microsoft/vscode-js-debug/issues/1433)) +- fix: add ipv4->6 fallback ([vscode#167353](https://github.com/microsoft/vscode/issues/167353)) ## v1.74 (November 2022) diff --git a/src/adapter/resourceProvider/basicResourceProvider.ts b/src/adapter/resourceProvider/basicResourceProvider.ts index 318f9b136..189df5626 100644 --- a/src/adapter/resourceProvider/basicResourceProvider.ts +++ b/src/adapter/resourceProvider/basicResourceProvider.ts @@ -3,6 +3,7 @@ *--------------------------------------------------------*/ import dataUriToBuffer from 'data-uri-to-buffer'; +import { LookupAddress, promises as dns } from 'dns'; import got, { Headers, OptionsOfTextResponseBody, RequestError } from 'got'; import { inject, injectable, optional } from 'inversify'; import { CancellationToken } from 'vscode'; @@ -91,10 +92,18 @@ export class BasicResourceProvider implements IResourceProvider { const response = await this.requestHttp(url, options, cancellationToken); - // Try 127.0.0.1 if localhost fails, see https://github.com/microsoft/vscode/issues/140536#issuecomment-1011281962 - // The statusCode will be 503 on ECONNREFUSED - if (response.statusCode === 503 && parsed.hostname === 'localhost') { - parsed.hostname = '127.0.0.1'; + // Try the other net family if localhost fails, + // see https://github.com/microsoft/vscode/issues/140536#issuecomment-1011281962 + // and later https://github.com/microsoft/vscode/issues/167353 + if (response.statusCode === 503 && parsed.hostname === 'localost') { + let resolved: LookupAddress; + try { + resolved = await dns.lookup(parsed.hostname); + } catch { + return response; + } + + parsed.hostname = resolved.family === 6 ? '127.0.0.1' : '::1'; return this.requestHttp(parsed.toString(), options, cancellationToken); }