src/vs/platform/agentHost/node/networkDiagnosticsService.ts

194 LOC · 155 covered · 39 uncovered · 18 ranges · 11 concepts · 2 introducers · 6 tests

File neighbourhood

The centred file is linked to every concept that introduces one of its ranges, every test that runs code from the file, and the gray connector concepts standing between those tests and the file's own introducer concepts. Undirected links join concepts to every file where they introduce source and concepts to the tests they introduce; arrows show specialization between the displayed concepts and bridge only concepts omitted from this view. Concept colors match the source ranges below; connector concepts have no source color and are shown in gray.

Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the file

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the related-file, concept, and source links on this page.

Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the filesrc/vs/platform/agentHost/common/agentHostClientProxyChannel.ts · 83 LOCcommon/agentHostClientPr…src/vs/platform/agentHost/node/agentHostRequestService.ts · 197 LOCnode/agentHostRequestSer…agentHostRequestService.ts ×2 · 7 introduced LOCagentHostRequestService.…agentHostRequestService.ts ×4 · 10 introduced LOCagentHostRequestService.…agentHostRequestService.ts ×6 · 32 introduced LOCagentHostRequestService.…agentHostRequestService.ts ×2 · 4 introduced LOCagentHostRequestService.…agentHostRequestService.ts ×1 · 2 introduced LOCagentHostRequestService.…agentHostRequestService.ts ×1 · 2 introduced LOCagentHostRequestService.…agentHostRequestService.ts ×5 · 8 introduced LOCagentHostRequestService.…agentHostRequestService.ts ×12 · 46 introduced LOCagentHostRequestService.…networkDiagnosticsService.ts ×11 · 83 introduced LOCnetworkDiagnosticsServic…agentHostClientProxyChannel.ts ×4 · 26 introduced LOCagentHostClientProxyChan…agentHostRequestService.ts ×11 · 179 introduced LOCagentHostRequestService.…agentHostRequestService.test|title=AgentHostRequestService does not retry non-idempotent requests|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/platform/agentHost/test/node/agentHostRequestService.test|title=AgentHostRequestService does not retry non-idempotent requests|occurrence=1agentHostRequestService.…agentHostRequestService.test|title=AgentHostRequestService forwards cancellation to resolver fetch|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/platform/agentHost/test/node/agentHostRequestService.test|title=AgentHostRequestService forwards cancellation to resolver fetch|occurrence=1agentHostRequestService.…agentHostRequestService.test|title=AgentHostRequestService forwards proxy and authorization lookups through the client channel|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/platform/agentHost/test/node/agentHostRequestService.test|title=AgentHostRequestService forwards proxy and authorization lookups through the client channel|occurrence=1agentHostRequestService.…agentHostRequestService.test|title=AgentHostRequestService retries idempotent requests on transient errors|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/platform/agentHost/test/node/agentHostRequestService.test|title=AgentHostRequestService retries idempotent requests on transient errors|occurrence=1agentHostRequestService.…agentHostRequestService.test|title=AgentHostRequestService uses resolver fetch and streams the response|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/platform/agentHost/test/node/agentHostRequestService.test|title=AgentHostRequestService uses resolver fetch and streams the response|occurrence=1agentHostRequestService.…agentHostRequestService.test|title=NetworkDiagnosticsService includes nested proxy response errors|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/platform/agentHost/test/node/agentHostRequestService.test|title=NetworkDiagnosticsService includes nested proxy response errors|occurrence=1agentHostRequestService.…Focused file · src/vs/platform/agentHost/node/networkDiagnosticsService.ts · 194 LOCnode/networkDiagnosticsS…

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the related-file, concept, and source links on this page while the interactive map is unavailable.

1 > /*--------------------------------------------------------------------------------------------- agentHostRequestService.ts ×11
2 > * Copyright (c) Microsoft Corporation. All rights reserved.
3 > * Licensed under the MIT License. See License.txt in the project root for license information.
4 > *--------------------------------------------------------------------------------------------*/
5 >
6 > import { lookup } from 'dns';
7 > import { streamToBuffer } from '../../../base/common/buffer.js';
8 > import { CancellationToken } from '../../../base/common/cancellation.js';
9 > import { IConfigurationService } from '../../configuration/common/configuration.js';
10 > import { createDecorator } from '../../instantiation/common/instantiation.js';
11 > import { ILogService } from '../../log/common/log.js';
12 > import { IProductService } from '../../product/common/productService.js';
13 > import { IRequestService, NO_FETCH_TELEMETRY } from '../../request/common/request.js';
14 > import { IAgentHostDnsResult, IAgentHostNetworkDiagnosticsInfo, IAgentHostNetworkEndpoint, IAgentHostNetworkFetchResult } from '../common/agentService.js';
15 > import { IAgentHostProxyResolver } from './agentHostProxyResolver.js';
16 >
17 > export const INetworkDiagnosticsService = createDecorator<INetworkDiagnosticsService>('networkDiagnosticsService');
18 >
19 > /**
20 > * Owns agent-host network connectivity diagnostics: host-level network context
21 > * ({@link getInfo}) and the per-URL reachability probe ({@link fetch}). Split
22 > * out from {@link IAgentService} so the network stack dependencies
23 > * ({@link IRequestService}, {@link IAgentHostProxyResolver}) are injected here
24 > * rather than threaded through the session orchestrator.
25 > */
26 > export interface INetworkDiagnosticsService {
27 > readonly _serviceBrand: undefined;
28 >
29 > /** Host-level network context: version, OS/arch, account, proxy settings/env, and endpoints worth probing. */
30 > getInfo(endpoints: readonly IAgentHostNetworkEndpoint[], account?: string): Promise<IAgentHostNetworkDiagnosticsInfo>;
31 >
32 > /** Probe connectivity from the agent host process to a single `url`. */
33 > fetch(url: string): Promise<IAgentHostNetworkFetchResult>;
34 > }
35 >
36 > /** Per-probe timeout: DNS lookup and the reachability request each get this long. */
37 > const PROBE_TIMEOUT_MS = 10_000;
38 >
39 > /** Cap on the response body returned to callers (for expected-content checks), to bound the IPC payload. */
40 > const MAX_BODY_CHARS = 64 * 1024;
41 >
42 > /**
43 > * Proxy-related environment variables surfaced in the diagnostics report so a
44 > * mismatch between the OS/config proxy and an explicit env override is visible.
45 > */
46 > const PROXY_ENV_KEYS = ['HTTPS_PROXY', 'https_proxy', 'HTTP_PROXY', 'http_proxy', 'ALL_PROXY', 'all_proxy', 'NO_PROXY', 'no_proxy'] as const;
47 >
48 > /** VS Code `http.*` proxy settings surfaced alongside the env vars. */
49 > const PROXY_CONFIG_KEYS = ['http.proxy', 'http.proxyStrictSSL', 'http.proxySupport', 'http.noProxy'] as const;
50 >
51 > export class NetworkDiagnosticsService implements INetworkDiagnosticsService {
52 >
53 > declare readonly _serviceBrand: undefined;
54 >
55 > constructor(
56 > @IRequestService private readonly _requestService: IRequestService, networkDiagnosticsService.ts ×11
57 > @IAgentHostProxyResolver private readonly _proxyResolver: IAgentHostProxyResolver,
58 > @IConfigurationService private readonly _configurationService: IConfigurationService,
59 > @IProductService private readonly _productService: IProductService,
60 > @ILogService private readonly _logService: ILogService,
61 > ) { }
63 > async getInfo(endpoints: readonly IAgentHostNetworkEndpoint[], account?: string): Promise<IAgentHostNetworkDiagnosticsInfo> {
64 const proxyEnv: Record<string, string> = {};
65 for (const key of PROXY_ENV_KEYS) {
66 const value = process.env[key];
67 if (value) {
68 proxyEnv[key] = value;
69 }
70 }
71
72 const proxySettings: Record<string, string> = {};
73 for (const key of PROXY_CONFIG_KEYS) {
74 const value = this._configurationService.getValue(key);
75 if (value === undefined || value === '' || (Array.isArray(value) && value.length === 0)) {
76 continue;
77 }
78 proxySettings[key] = Array.isArray(value) ? value.join(', ') : String(value);
79 }
80
81 return {
82 version: this._productService.version,
83 os: process.platform,
84 arch: process.arch,
85 account,
86 proxySettings,
87 proxyEnv,
88 endpoints,
89 };
90 }
92 > /**
93 > * Probe connectivity from the agent host process to a single `url`. Resolves
94 > * the proxy (for reporting), performs an IPv4 DNS lookup, and then a
95 > * reachability request through {@link IRequestService} — so the probe
96 > * traverses the same proxy / TLS / certificate stack the rest of VS Code
97 > * uses. Each step is individually timed and never throws; failures are
98 > * captured on the result.
99 > */
100 > async fetch(url: string): Promise<IAgentHostNetworkFetchResult> {
101 > const target = new URL(url); networkDiagnosticsService.ts ×11
102 > const host = target.hostname;
103 >
104 > // DNS: resolve both address families so a host that only answers on one is visible.
105 > const [dnsIpv4, dnsIpv6] = await Promise.all([
106 > resolveDns(host, 4),
107 > resolveDns(host, 6),
108 > ]);
109 >
110 > // Proxy resolution (for reporting; IRequestService resolves its own proxy internally).
111 > let proxyUrl: string | undefined;
112 > try {
113 > proxyUrl = await this._proxyResolver.resolveProxy(url);
114 > } catch (err) {
115 this._logService.debug(`[AgentHost] Network diagnostics: proxy resolution for ${url} failed: ${errorMessage(err)}`);
116 }
118 > const base = {
119 > url,
120 > proxyUrl,
121 > dnsIpv4, dnsIpv6,
122 > };
123 >
124 > // Reachability: a GET through IRequestService, which applies VS Code's proxy,
125 > // strictSSL, and certificate handling — the path the rest of VS Code uses.
126 > const probeStart = Date.now();
127 > try {
128 > const context = await this._requestService.request({
129 > url,
130 > type: 'GET',
131 > timeout: PROBE_TIMEOUT_MS,
132 > callSite: NO_FETCH_TELEMETRY,
133 > }, CancellationToken.None);
134 const body = (await streamToBuffer(context.stream)).toString();
135 return {
136 ...base,
137 statusCode: context.res.statusCode,
138 > body: body.length > MAX_BODY_CHARS ? body.slice(0, MAX_BODY_CHARS) : body, networkDiagnosticsService.ts ×11
139 > durationMs: Date.now() - probeStart,
140 > };
141 > } catch (err) {
142 > return {
143 > ...base,
144 > error: errorMessage(err),
145 > durationMs: Date.now() - probeStart,
146 > };
147 > }
148 > }
150 >
151 > function dnsLookup(host: string, family: 4 | 6): Promise<string> { networkDiagnosticsService.ts ×11
152 > return new Promise((resolve, reject) => {
153 > lookup(host, { family }, (err, address) => err ? reject(err) : resolve(address));
154 > });
155 > }
157 > async function resolveDns(host: string, family: 4 | 6): Promise<IAgentHostDnsResult> { networkDiagnosticsService.ts ×11
158 > const start = Date.now();
159 > try {
160 > const address = await withTimeout(dnsLookup(host, family), PROBE_TIMEOUT_MS);
161 > return { address, durationMs: Date.now() - start };
162 > } catch (err) {
163 return { durationMs: Date.now() - start, error: errorMessage(err) };
164 }
167 > function withTimeout<T>(promise: Promise<T>, ms: number): Promise<T> { networkDiagnosticsService.ts ×11
168 > return new Promise<T>((resolve, reject) => {
169 > const timer = setTimeout(() => reject(new Error(`Timed out after ${ms / 1000}s`)), ms);
170 > promise.then(
171 > value => { clearTimeout(timer); resolve(value); },
172 > err => { clearTimeout(timer); reject(err); },
173 > );
174 > });
175 > }
177 > function errorMessage(error: unknown): string { networkDiagnosticsService.ts ×11
178 > const seen = new Set<unknown>();
179 > function collect(error: unknown): string {
180 > if (seen.has(error)) {
181 return '';
182 }
183 > seen.add(error); networkDiagnosticsService.ts ×11
184 > if (!(error instanceof Error)) {
185 return String(error);
186 }
187 > const details = [ networkDiagnosticsService.ts ×11
188 > error.cause ? collect(error.cause) : '',
189 > ...(error instanceof AggregateError ? error.errors.map(collect) : []),
190 > ].filter(Boolean).join(', ');
191 > return details ? `${error.message}: ${details}` : error.message;
192 > }
193 > return collect(error);
194 > }