src/vs/server/node/serverLifetimeService.ts

145 LOC · 109 covered · 36 uncovered · 18 ranges · 15 concepts · 4 introducers · 12 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 fileserverAgentHostManager.test|title=ServerAgentHostManager process exit resets both signals and clears token|occurrence=1 · 0 introduced LOCserverAgentHostManager.t…serverAgentHostManager.ts ×1 · 2 introduced LOCserverAgentHostManager.t…serverAgentHostManager.test|title=ServerAgentHostManager reports unexpected process exit|occurrence=1 · 0 introduced LOCserverAgentHostManager.t…serverAgentHostManager.ts ×2 · 19 introduced LOCserverAgentHostManager.t…serverAgentHostManager.ts ×1 · 2 introduced LOCserverAgentHostManager.t…serverAgentHostManager.ts ×1 · 4 introduced LOCserverAgentHostManager.t…serverAgentHostManager.ts ×2 · 4 introduced LOCserverAgentHostManager.t…serverAgentHostManager.ts ×3 · 19 introduced LOCserverAgentHostManager.t…agentHostProcessTelemetry.ts ×1 · 7 introduced LOCagentHostProcessTelemetr…serverAgentHostManager.ts ×7 · 138 introduced LOCserverAgentHostManager.t…serverLifetimeService.test|title=ServerLifetimeService dispose is idempotent|occurrence=1 · 0 introduced LOCserverLifetimeService.te…serverLifetimeService.ts ×1 · 2 introduced LOCserverLifetimeService.ts…serverLifetimeService.ts ×6 · 31 introduced LOCserverLifetimeService.ts…serverLifetimeService.ts ×3 · 9 introduced LOCserverLifetimeService.ts…serverLifetimeService.ts ×8 · 67 introduced LOCserverLifetimeService.ts…serverAgentHostManager.test|title=ServerAgentHostManager acquires token when sessions become active|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/server/test/node/serverAgentHostManager.test|title=ServerAgentHostManager acquires token when sessions become active|occurrence=1serverAgentHostManager.t…serverAgentHostManager.test|title=ServerAgentHostManager acquires token when standalone WebSocket clients connect|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/server/test/node/serverAgentHostManager.test|title=ServerAgentHostManager acquires token when standalone WebSocket clients connect|occurrence=1serverAgentHostManager.t…serverAgentHostManager.test|title=ServerAgentHostManager no lifetime token initially|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/server/test/node/serverAgentHostManager.test|title=ServerAgentHostManager no lifetime token initially|occurrence=1serverAgentHostManager.t…serverAgentHostManager.test|title=ServerAgentHostManager process exit resets both signals and clears token|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/server/test/node/serverAgentHostManager.test|title=ServerAgentHostManager process exit resets both signals and clears token|occurrence=1serverAgentHostManager.t…serverAgentHostManager.test|title=ServerAgentHostManager releases token only when both sessions and standalone WebSocket connections are zero|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/server/test/node/serverAgentHostManager.test|title=ServerAgentHostManager releases token only when both sessions and standalone WebSocket connections are zero|occurrence=1serverAgentHostManager.t…serverAgentHostManager.test|title=ServerAgentHostManager reports process start failure|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/server/test/node/serverAgentHostManager.test|title=ServerAgentHostManager reports process start failure|occurrence=1serverAgentHostManager.t…serverAgentHostManager.test|title=ServerAgentHostManager reports unexpected process exit|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/server/test/node/serverAgentHostManager.test|title=ServerAgentHostManager reports unexpected process exit|occurrence=1serverAgentHostManager.t…serverLifetimeService.test|title=ServerLifetimeService active() marks a consumer and dispose releases it|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/server/test/node/serverLifetimeService.test|title=ServerLifetimeService active() marks a consumer and dispose releases it|occurrence=1serverLifetimeService.te…serverLifetimeService.test|title=ServerLifetimeService dispose is idempotent|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/server/test/node/serverLifetimeService.test|title=ServerLifetimeService dispose is idempotent|occurrence=1serverLifetimeService.te…serverLifetimeService.test|title=ServerLifetimeService multiple active consumers require all to dispose|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/server/test/node/serverLifetimeService.test|title=ServerLifetimeService multiple active consumers require all to dispose|occurrence=1serverLifetimeService.te…serverLifetimeService.test|title=ServerLifetimeService same consumer name counted multiple times|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/server/test/node/serverLifetimeService.test|title=ServerLifetimeService same consumer name counted multiple times|occurrence=1serverLifetimeService.te…serverLifetimeService.test|title=ServerLifetimeService starts with no active consumers|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/server/test/node/serverLifetimeService.test|title=ServerLifetimeService starts with no active consumers|occurrence=1serverLifetimeService.te…Focused file · src/vs/server/node/serverLifetimeService.ts · 145 LOCnode/serverLifetimeServi…

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 > /*--------------------------------------------------------------------------------------------- serverLifetimeService.ts ×8
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 { Disposable, IDisposable, toDisposable } from '../../base/common/lifecycle.js';
7 > import { createDecorator } from '../../platform/instantiation/common/instantiation.js';
8 > import { ILogService } from '../../platform/log/common/log.js';
9 >
10 > export const IServerLifetimeService = createDecorator<IServerLifetimeService>('serverLifetimeService');
11 >
12 > export const SHUTDOWN_TIMEOUT = 5 * 60 * 1000;
13 >
14 > /** Options controlling the auto-shutdown behaviour. */
15 > export interface IServerLifetimeOptions {
16 > /** When `false` (default), the server never auto-shuts down. */
17 > readonly enableAutoShutdown?: boolean;
18 > /** When `true`, skip the 5-minute grace period on non-initial shutdowns. */
19 > readonly shutdownWithoutDelay?: boolean;
20 > }
21 >
22 > /**
23 > * Tracks active consumers (extension hosts, agent sessions, etc.) that keep
24 > * the server alive. When auto-shutdown is enabled, the service manages a
25 > * shutdown timer and fires {@link onDidShutdownRequested} when it is time for
26 > * the process to exit.
27 > */
28 > export interface IServerLifetimeService {
29 > readonly _serviceBrand: undefined;
30 >
31 > /**
32 > * Marks a consumer as active. The server will not auto-shutdown until the
33 > * returned {@link IDisposable} is disposed.
34 > */
35 > active(consumer: string): IDisposable;
36 >
37 > /**
38 > * Delays the auto-shutdown timer. If the server is currently in a shutdown
39 > * timeout (all consumers inactive), the timer is reset.
40 > */
41 > delay(): void;
42 >
43 > /** Whether any consumer is currently active. */
44 > readonly hasActiveConsumers: boolean;
45 > }
46 >
47 > export class ServerLifetimeService extends Disposable implements IServerLifetimeService {
48 > declare readonly _serviceBrand: undefined;
49 >
50 > private readonly _consumers = new Map<string, number>();
51 > private _totalCount = 0;
52 > private _shutdownTimer: ReturnType<typeof setTimeout> | undefined;
53 >
54 > constructor(
55 > private readonly _options: IServerLifetimeOptions, serverLifetimeService.ts ×3
56 > @ILogService private readonly _logService: ILogService,
57 > ) {
58 > super();
59 >
60 > if (this._options.enableAutoShutdown) {
61 // Start initial shutdown timer (no clients connected yet)
62 this._scheduleShutdown(true);
63 }
66 > get hasActiveConsumers(): boolean {
67 > return this._totalCount > 0; serverLifetimeService.ts ×3
68 > }
70 > active(consumer: string): IDisposable {
71 > const wasEmpty = this._totalCount === 0; serverLifetimeService.ts ×6
72 > const current = this._consumers.get(consumer) ?? 0;
73 > this._consumers.set(consumer, current + 1);
74 > this._totalCount++;
75 >
76 > this._logService.debug(`ServerLifetime: consumer '${consumer}' active (total: ${this._totalCount})`);
77 >
78 > if (wasEmpty) {
79 > this._cancelShutdown();
80 > }
81 >
82 > let disposed = false;
83 > return toDisposable(() => {
84 > if (disposed) {
85 return;
86 }
87 > disposed = true; serverLifetimeService.ts ×6
88 >
89 > const count = this._consumers.get(consumer);
90 > if (count !== undefined) {
91 > if (count <= 1) {
92 > this._consumers.delete(consumer);
93 > } else {
94 > this._consumers.set(consumer, count - 1); serverLifetimeService.ts ×1
95 > }
97 > this._totalCount--;
98 >
99 > this._logService.debug(`ServerLifetime: consumer '${consumer}' inactive (total: ${this._totalCount})`);
100 >
101 > if (this._totalCount === 0 && this._options.enableAutoShutdown) {
102 this._scheduleShutdown(false);
103 }
105 > }
107 > delay(): void {
108 if (this._shutdownTimer) {
109 this._logService.debug('ServerLifetime: delay requested, resetting shutdown timer');
110 this._cancelShutdown();
111 this._scheduleShutdown(false);
112 }
113 }
115 > private _scheduleShutdown(initial: boolean): void {
116 if (this._options.shutdownWithoutDelay && !initial) {
117 this._tryShutdown();
118 } else {
119 this._logService.debug('ServerLifetime: scheduling shutdown timer');
120 this._shutdownTimer = setTimeout(() => {
121 this._shutdownTimer = undefined;
122 this._tryShutdown();
123 }, SHUTDOWN_TIMEOUT);
124 }
125 }
127 > private _tryShutdown(): void {
128 if (this._totalCount > 0) {
129 this._logService.debug('ServerLifetime: consumer became active, aborting shutdown');
130 return;
131 }
132 console.log('All consumers inactive, shutting down');
133 this._logService.info('ServerLifetime: all consumers inactive, shutting down');
134 this.dispose();
135 process.exit(0);
136 }
138 > private _cancelShutdown(): void {
139 > if (this._shutdownTimer) { serverLifetimeService.ts ×6
140 this._logService.debug('ServerLifetime: cancelling shutdown timer');
141 clearTimeout(this._shutdownTimer);
142 this._shutdownTimer = undefined;
143 }