loopbackProxyServer.ts ×8

Frontier kind: Code frontier

unlabeled · c_c2bca598d326

84 tests · 8083 LOC · 38 files · introduces 0 tests · 61 LOC · 1 file

Introduces — evidence that enters the hierarchy at this concept

Code
8 ranges61 lines · 1 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
1273 ranges8083 lines · 38 files · Browse complete extent
All tests (intent)
84 testsBrowse complete intent

Neighbourhood graph

The orange circle is the focus. Violet and green circles are every ancestor and descendant, broader and narrower, at any distance; blue squares and pink diamonds are the introduced files and exact introduced tests of every visible concept, not only the focus's. Arrows point from broader to narrower concepts and bridge only concepts omitted from this view. Undirected links show source or test introduction. Concept and file size follows LOC; exact test nodes use test-count units.

Introduced files, introduced tests, and structurally relevant concept specialization

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 native relationship evidence on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the native relationship evidence on this page while the interactive map is unavailable.

Native relationship evidence

Every exact file and test below is linked only from the concept that introduces it.

Introduced tests

Every collected test enters the hierarchy at exactly one concept.

No tests are introduced at this concept. Its intent tests are introduced by other concepts.

Introduced code

Every collected source range enters the hierarchy at exactly one concept.

1 file ranked by introduced lines: 61 introduced LOC across 8 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/platform/agentHost/node/shared/loopbackProxyServer.ts 61 introduced LOC · 8 ranges

Open complete file

71 * is available in Node 18+.
72 */
73 > function generateNonce(): string { loopbackProxyServer.ts
74 > const bytes = new Uint8Array(32);
75 > crypto.getRandomValues(bytes);
76 > let out = '';
77 > for (let i = 0; i < bytes.length; i++) {
78 > out += bytes[i].toString(16).padStart(2, '0');
79 > }
80 > return out;
81 > }
82
83 // #endregion
175 throw new Error(`${this.name} has been disposed`);
176 }
177 > const runtime = await this._ensureRuntime(seed); loopbackProxyServer.ts
178 // Re-check after the await: dispose() may have run while
179 // _ensureRuntime was awaiting the bind, in which case the runtime
215 */
216 private _ensureRuntime(seed: TSeed): Promise<IInternalRuntime<TState>> {
217 > if (this._runtime) { loopbackProxyServer.ts
218 return Promise.resolve(this._runtime);
219 }
220 > if (!this._starting) { loopbackProxyServer.ts
221 > this._starting = (async () => {
222 > try {
223 > const rt = await this._startServer(seed);
224 > if (this._disposed) {
225 // dispose() ran while we were binding — the teardown
226 // noop'd because _runtime was still undefined, so
232 this._runtime = rt;
233 return rt;
234 > } finally { loopbackProxyServer.ts
235 > this._starting = undefined;
236 > }
237 > })();
238 > }
239 > return this._starting;
240 > }
241
242 private _releaseHandle(runtime: IInternalRuntime<TState>): void {
273
274 private async _startServer(seed: TSeed): Promise<IInternalRuntime<TState>> {
275 > const nonce = generateNonce(); loopbackProxyServer.ts
276 > const inFlight = new Set<IProxyInFlight>();
277 > const httpModule = await import('http');
278 > const server = httpModule.createServer();
279 >
280 > await new Promise<void>((resolve, reject) => {
281 > const onError = (err: Error) => reject(err);
282 > server.once('error', onError);
283 > server.listen(0, '127.0.0.1', () => {
284 > server.removeListener('error', onError);
285 > resolve();
286 > });
287 > });
288 >
289 > const address = server.address();
290 > if (!address || typeof address === 'string') {
291 server.close();
292 throw new Error(`${this.name} failed to bind: unexpected address ${String(address)}`);
293 }
294 > const baseUrl = `http://127.0.0.1:${(address as AddressInfo).port}`; loopbackProxyServer.ts
295 > this._logService.info(`[${this.name}] listening on ${baseUrl}`);
296 >
297 > const runtime: IInternalRuntime<TState> = {
298 > server,
299 > baseUrl,
300 > nonce,
301 > inFlight,
302 > refcount: 0,
303 > state: this.createState(seed),
304 > };
305 >
306 > // Attach the request handler only after `runtime` is fully built.
307 > // Node's single-threaded event loop guarantees no `request` event can
308 > // be parsed and dispatched between `listen` resolving and this
309 > // synchronous registration, so the handler can safely close over
310 > // `runtime` as a `const`.
311 > server.on('request', (req, res) => {
312 this.handleRequest(req, res, runtime).catch(err => {
313 // Last-resort safety net. Concrete proxies are expected to