@hydranium/client-theia 1.0.0-next.23 → 1.0.0-next.232
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +54 -16
- package/lib/browser/browser-capture.js.map +1 -1
- package/lib/browser/channel-logger.d.ts +4 -3
- package/lib/browser/channel-logger.d.ts.map +1 -1
- package/lib/browser/channel-logger.js +10 -7
- package/lib/browser/channel-logger.js.map +1 -1
- package/lib/browser/connection-diagnostics-contribution.d.ts +69 -0
- package/lib/browser/connection-diagnostics-contribution.d.ts.map +1 -0
- package/lib/browser/connection-diagnostics-contribution.js +153 -0
- package/lib/browser/connection-diagnostics-contribution.js.map +1 -0
- package/lib/browser/connection-reporter.d.ts +57 -0
- package/lib/browser/connection-reporter.d.ts.map +1 -0
- package/lib/browser/connection-reporter.js +104 -0
- package/lib/browser/connection-reporter.js.map +1 -0
- package/lib/browser/editor-disk-sync.d.ts +142 -0
- package/lib/browser/editor-disk-sync.d.ts.map +1 -0
- package/lib/browser/editor-disk-sync.js +250 -0
- package/lib/browser/editor-disk-sync.js.map +1 -0
- package/lib/browser/hydranium-file-service.d.ts +44 -0
- package/lib/browser/hydranium-file-service.d.ts.map +1 -0
- package/lib/browser/hydranium-file-service.js +61 -0
- package/lib/browser/hydranium-file-service.js.map +1 -0
- package/lib/browser/index.d.ts +5 -0
- package/lib/browser/index.d.ts.map +1 -1
- package/lib/browser/index.js +5 -0
- package/lib/browser/index.js.map +1 -1
- package/lib/browser/log-level-preference.d.ts.map +1 -1
- package/lib/browser/log-level-preference.js +11 -0
- package/lib/browser/log-level-preference.js.map +1 -1
- package/lib/browser/memory-diagnostics-contribution.d.ts +40 -4
- package/lib/browser/memory-diagnostics-contribution.d.ts.map +1 -1
- package/lib/browser/memory-diagnostics-contribution.js +161 -31
- package/lib/browser/memory-diagnostics-contribution.js.map +1 -1
- package/lib/browser/session-aware-connection-source.d.ts +101 -0
- package/lib/browser/session-aware-connection-source.d.ts.map +1 -0
- package/lib/browser/session-aware-connection-source.js +184 -0
- package/lib/browser/session-aware-connection-source.js.map +1 -0
- package/lib/common/clock.d.ts +19 -0
- package/lib/common/clock.d.ts.map +1 -0
- package/lib/common/clock.js +13 -0
- package/lib/common/clock.js.map +1 -0
- package/lib/common/connection-resilience-options.d.ts +30 -0
- package/lib/common/connection-resilience-options.d.ts.map +1 -0
- package/lib/common/connection-resilience-options.js +11 -0
- package/lib/common/connection-resilience-options.js.map +1 -0
- package/lib/common/framed-socket-write-buffer.d.ts +173 -0
- package/lib/common/framed-socket-write-buffer.d.ts.map +1 -0
- package/lib/common/framed-socket-write-buffer.js +293 -0
- package/lib/common/framed-socket-write-buffer.js.map +1 -0
- package/lib/common/inbound-message-sequence.d.ts +56 -0
- package/lib/common/inbound-message-sequence.d.ts.map +1 -0
- package/lib/common/inbound-message-sequence.js +98 -0
- package/lib/common/inbound-message-sequence.js.map +1 -0
- package/lib/common/index.d.ts +13 -0
- package/lib/common/index.d.ts.map +1 -0
- package/lib/common/index.js +32 -0
- package/lib/common/index.js.map +1 -0
- package/lib/node/abstract-socket-forwarding-connection-handler.d.ts +12 -8
- package/lib/node/abstract-socket-forwarding-connection-handler.d.ts.map +1 -1
- package/lib/node/abstract-socket-forwarding-connection-handler.js +70 -13
- package/lib/node/abstract-socket-forwarding-connection-handler.js.map +1 -1
- package/lib/node/index.d.ts +2 -0
- package/lib/node/index.d.ts.map +1 -1
- package/lib/node/index.js +2 -0
- package/lib/node/index.js.map +1 -1
- package/lib/node/session-bound-frontend-connection-service.d.ts +118 -0
- package/lib/node/session-bound-frontend-connection-service.d.ts.map +1 -0
- package/lib/node/session-bound-frontend-connection-service.js +224 -0
- package/lib/node/session-bound-frontend-connection-service.js.map +1 -0
- package/lib/node/socket-channel-forwarder.d.ts +54 -0
- package/lib/node/socket-channel-forwarder.d.ts.map +1 -0
- package/lib/node/socket-channel-forwarder.js +95 -0
- package/lib/node/socket-channel-forwarder.js.map +1 -0
- package/lib/testing/stub-inversify-context.js.map +1 -1
- package/lib/testing/stub-output-channel.js.map +1 -1
- package/package.json +31 -32
- package/src/browser/channel-logger.ts +10 -7
- package/src/browser/connection-diagnostics-contribution.ts +142 -0
- package/src/browser/connection-reporter.ts +121 -0
- package/src/browser/editor-disk-sync.ts +253 -0
- package/src/browser/hydranium-file-service.ts +56 -0
- package/src/browser/index.ts +5 -0
- package/src/browser/log-level-preference.ts +11 -0
- package/src/browser/memory-diagnostics-contribution.ts +268 -45
- package/src/browser/session-aware-connection-source.ts +196 -0
- package/src/common/clock.ts +20 -0
- package/src/common/connection-resilience-options.ts +30 -0
- package/src/common/framed-socket-write-buffer.ts +345 -0
- package/src/common/inbound-message-sequence.ts +102 -0
- package/src/common/index.ts +16 -0
- package/src/node/abstract-socket-forwarding-connection-handler.ts +61 -15
- package/src/node/index.ts +2 -0
- package/src/node/session-bound-frontend-connection-service.ts +260 -0
- package/src/node/socket-channel-forwarder.ts +101 -0
|
@@ -51,11 +51,14 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
51
51
|
};
|
|
52
52
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
53
|
exports.AbstractSocketForwardingConnectionHandler = void 0;
|
|
54
|
+
const protocol_1 = require("@hydranium/protocol");
|
|
54
55
|
const core_1 = require("@theia/core");
|
|
55
56
|
const channel_1 = require("@theia/core/lib/common/message-rpc/channel");
|
|
56
57
|
const promise_util_1 = require("@theia/core/lib/common/promise-util");
|
|
57
58
|
const inversify_1 = require("@theia/core/shared/inversify");
|
|
58
59
|
const net = __importStar(require("node:net"));
|
|
60
|
+
const clock_1 = require("../common/clock");
|
|
61
|
+
const socket_channel_forwarder_1 = require("./socket-channel-forwarder");
|
|
59
62
|
/**
|
|
60
63
|
* Cross-head base for the Theia backend half of a protocol head's transport:
|
|
61
64
|
* it bridges a Theia browser-frontend {@link Channel} to a server's TCP socket
|
|
@@ -68,12 +71,10 @@ const net = __importStar(require("node:net"));
|
|
|
68
71
|
* the same wire protocol the server speaks, so the backend performs no semantic
|
|
69
72
|
* re-proxy — it relays bytes only and stays oblivious to the server's method set.
|
|
70
73
|
*
|
|
71
|
-
* The
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
* behind the hook is what lets the data head stay GLSP-free while sharing the
|
|
76
|
-
* port-discovery + buffer-and-replay race fix + connect orchestration here.
|
|
74
|
+
* The byte forwarder that bridges the channel and the socket is
|
|
75
|
+
* {@link forwardToSocketConnection}; both heads use {@link SocketChannelForwarder},
|
|
76
|
+
* and the port discovery, buffer-and-replay race fix and connect orchestration
|
|
77
|
+
* here are shared.
|
|
77
78
|
*/
|
|
78
79
|
let AbstractSocketForwardingConnectionHandler = class AbstractSocketForwardingConnectionHandler {
|
|
79
80
|
messageService;
|
|
@@ -82,6 +83,8 @@ let AbstractSocketForwardingConnectionHandler = class AbstractSocketForwardingCo
|
|
|
82
83
|
// not the spawned language-server process, so the framework `LspLogger`
|
|
83
84
|
// (which needs the Langium connection/services) is out of reach here.
|
|
84
85
|
logger;
|
|
86
|
+
/** The clock each {@link SocketChannelForwarder} bounds its flush on: the container's {@link Clock}, or a `SystemClock`. */
|
|
87
|
+
clock = new protocol_1.SystemClock();
|
|
85
88
|
path;
|
|
86
89
|
portCommand;
|
|
87
90
|
logComponent;
|
|
@@ -115,32 +118,68 @@ let AbstractSocketForwardingConnectionHandler = class AbstractSocketForwardingCo
|
|
|
115
118
|
// window.
|
|
116
119
|
const buffered = [];
|
|
117
120
|
const bufferSub = channel.onMessage(provider => buffered.push(provider));
|
|
121
|
+
const closed = new AbortController();
|
|
122
|
+
const closeSub = channel.onClose(() => closed.abort());
|
|
118
123
|
try {
|
|
119
|
-
const port = await this.findPort();
|
|
124
|
+
const port = await this.findPort(closed.signal);
|
|
125
|
+
closed.signal.throwIfAborted();
|
|
120
126
|
this.logger.info(`[${this.logComponent}] Connecting to ${this.serverName} on port ${port}...`);
|
|
121
127
|
await this.connectToServer(channel, port, { bufferSub, buffered });
|
|
122
128
|
this.logger.info(`[${this.logComponent}] Connected to ${this.serverName} on port ${port}.`);
|
|
123
129
|
}
|
|
124
130
|
catch (error) {
|
|
125
131
|
bufferSub.dispose();
|
|
132
|
+
if (closed.signal.aborted) {
|
|
133
|
+
this.logger.info(`[${this.logComponent}] Stopped connecting to ${this.serverName}: the frontend closed the channel.`);
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
126
136
|
const message = error && typeof error === 'object' && 'message' in error ? String(error.message) : String(error);
|
|
127
137
|
this.logger.error(`[${this.logComponent}] Could not connect to ${this.serverName}: ${message}`);
|
|
128
|
-
this.
|
|
138
|
+
this.reportConnectFailure(message);
|
|
139
|
+
// Closed so the frontend learns of it: left open, the channel has no
|
|
140
|
+
// server behind it, and every request on it waits for good.
|
|
141
|
+
channel.close();
|
|
129
142
|
}
|
|
143
|
+
finally {
|
|
144
|
+
closeSub.dispose();
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
/** Tell the user this handler gave up; `message` is the reason it logged. */
|
|
148
|
+
reportConnectFailure(message) {
|
|
149
|
+
this.messageService.error(`Could not connect to ${this.serverName}: ` + message);
|
|
130
150
|
}
|
|
131
|
-
|
|
151
|
+
/** Poll the port command until it answers, its attempts run out, or `signal` aborts. */
|
|
152
|
+
async findPort(signal) {
|
|
132
153
|
const pendingContent = new promise_util_1.Deferred();
|
|
133
154
|
let counter = 0;
|
|
155
|
+
let timer;
|
|
156
|
+
const stop = () => {
|
|
157
|
+
clearTimeout(timer);
|
|
158
|
+
pendingContent.reject(signal?.reason);
|
|
159
|
+
};
|
|
160
|
+
if (signal?.aborted) {
|
|
161
|
+
stop();
|
|
162
|
+
}
|
|
163
|
+
signal?.addEventListener('abort', stop, { once: true });
|
|
134
164
|
const tryQueryingPort = () => {
|
|
135
|
-
|
|
165
|
+
if (signal?.aborted) {
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
timer = setTimeout(async () => {
|
|
136
169
|
try {
|
|
137
170
|
const port = await this.commandService.executeCommand(this.portCommand);
|
|
138
|
-
|
|
139
|
-
|
|
171
|
+
// An empty answer fails the attempt like a throw does: left
|
|
172
|
+
// unanswered, it neither resolves nor re-queues, and the lookup
|
|
173
|
+
// stays pending with nothing logged.
|
|
174
|
+
if (!port) {
|
|
175
|
+
throw new Error(`Port command '${this.portCommand}' answered without a port.`);
|
|
140
176
|
}
|
|
177
|
+
pendingContent.resolve(port);
|
|
141
178
|
}
|
|
142
179
|
catch (error) {
|
|
143
180
|
counter++;
|
|
181
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
182
|
+
this.logger.debug(`[${this.logComponent}] Port command '${this.portCommand}' attempt ${counter} failed: ${message}`);
|
|
144
183
|
if (this.findPortAttempts >= 0 && counter > this.findPortAttempts) {
|
|
145
184
|
pendingContent.reject(error);
|
|
146
185
|
}
|
|
@@ -173,10 +212,23 @@ let AbstractSocketForwardingConnectionHandler = class AbstractSocketForwardingCo
|
|
|
173
212
|
if (channel instanceof channel_1.ForwardingChannel) {
|
|
174
213
|
socket.on('error', error => channel.onErrorEmitter.fire(error));
|
|
175
214
|
}
|
|
176
|
-
|
|
215
|
+
// `127.0.0.1`, not the `localhost` Node dials when no host is given, and it
|
|
216
|
+
// has to match the head: the socket launchers bind `127.0.0.1` by default,
|
|
217
|
+
// so on a dual-stack machine where `localhost` resolves to `::1` first the
|
|
218
|
+
// dial fails as ECONNREFUSED with nothing in the message naming the address
|
|
219
|
+
// family as the cause.
|
|
220
|
+
socket.connect({ port, host: '127.0.0.1' });
|
|
177
221
|
setTimeout(() => connected.reject('Timeout reached.'), this.connectTimeoutMs);
|
|
178
222
|
return connected.promise;
|
|
179
223
|
}
|
|
224
|
+
/**
|
|
225
|
+
* Bridge the Theia frontend `clientChannel` and the server `socket` so bytes
|
|
226
|
+
* relay both ways. Called once, after the socket is created and the
|
|
227
|
+
* pre-forward buffer is about to be replayed.
|
|
228
|
+
*/
|
|
229
|
+
forwardToSocketConnection(clientChannel, socket) {
|
|
230
|
+
return new socket_channel_forwarder_1.SocketChannelForwarder(clientChannel, socket, this.clock);
|
|
231
|
+
}
|
|
180
232
|
/**
|
|
181
233
|
* Re-fire pre-forward buffered `MessageProvider`s on the channel's internal
|
|
182
234
|
* `onMessageEmitter` so the now-subscribed forwarder picks them up in arrival
|
|
@@ -217,6 +269,11 @@ __decorate([
|
|
|
217
269
|
(0, inversify_1.inject)(core_1.ILogger),
|
|
218
270
|
__metadata("design:type", Object)
|
|
219
271
|
], AbstractSocketForwardingConnectionHandler.prototype, "logger", void 0);
|
|
272
|
+
__decorate([
|
|
273
|
+
(0, inversify_1.inject)(clock_1.Clock),
|
|
274
|
+
(0, inversify_1.optional)(),
|
|
275
|
+
__metadata("design:type", Object)
|
|
276
|
+
], AbstractSocketForwardingConnectionHandler.prototype, "clock", void 0);
|
|
220
277
|
exports.AbstractSocketForwardingConnectionHandler = AbstractSocketForwardingConnectionHandler = __decorate([
|
|
221
278
|
(0, inversify_1.injectable)(),
|
|
222
279
|
__metadata("design:paramtypes", [Object])
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"abstract-socket-forwarding-connection-handler.js","sourceRoot":"","sources":["../../src/node/abstract-socket-forwarding-connection-handler.ts"],"names":[],"mappings":";AAAA;;;;;;;kFAOkF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAElF,sCAQqB;AACrB,wEAA+E;AAC/E,sEAA+D;AAC/D,
|
|
1
|
+
{"version":3,"file":"abstract-socket-forwarding-connection-handler.js","sourceRoot":"","sources":["../../src/node/abstract-socket-forwarding-connection-handler.ts"],"names":[],"mappings":";AAAA;;;;;;;kFAOkF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAElF,kDAAkD;AAClD,sCAQqB;AACrB,wEAA+E;AAC/E,sEAA+D;AAC/D,4DAA4E;AAC5E,MAAY,GAAG,qCAAiB;AAChC,2CAAwC;AACxC,yEAAoE;AA8BpE;;;;;;;;;;;;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PDX-License-Identifier: MIT
|
|
8
8
|
********************************************************************************/
|
|
9
9
|
export * from './abstract-socket-forwarding-connection-handler';
|
|
10
|
+
export * from './session-bound-frontend-connection-service';
|
|
11
|
+
export * from './socket-channel-forwarder';
|
|
10
12
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/node/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/node/index.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;AAElF,cAAc,iDAAiD,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/node/index.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;AAElF,cAAc,iDAAiD,CAAC;AAChE,cAAc,6CAA6C,CAAC;AAC5D,cAAc,4BAA4B,CAAC"}
|
package/lib/node/index.js
CHANGED
|
@@ -23,4 +23,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
23
23
|
};
|
|
24
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
25
|
__exportStar(require("./abstract-socket-forwarding-connection-handler"), exports);
|
|
26
|
+
__exportStar(require("./session-bound-frontend-connection-service"), exports);
|
|
27
|
+
__exportStar(require("./socket-channel-forwarder"), exports);
|
|
26
28
|
//# sourceMappingURL=index.js.map
|
package/lib/node/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/node/index.ts"],"names":[],"mappings":";AAAA;;;;;;;kFAOkF;;;;;;;;;;;;;;;;AAElF,kFAAgE"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/node/index.ts"],"names":[],"mappings":";AAAA;;;;;;;kFAOkF;;;;;;;;;;;;;;;;AAElF,kFAAgE;AAChE,8EAA4D;AAC5D,6DAA2C"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/********************************************************************************
|
|
2
|
+
* Copyright (c) 2026 CrossBreeze, EclipseSource and others.
|
|
3
|
+
*
|
|
4
|
+
* This program and the accompanying materials are made available under the
|
|
5
|
+
* terms of the MIT License which is available in the project root.
|
|
6
|
+
*
|
|
7
|
+
* SPDX-License-Identifier: MIT
|
|
8
|
+
********************************************************************************/
|
|
9
|
+
import { DisposableCollection } from '@theia/core/lib/common/disposable';
|
|
10
|
+
import { AbstractChannel } from '@theia/core/lib/common/message-rpc/channel';
|
|
11
|
+
import { type WriteBuffer } from '@theia/core/lib/common/message-rpc/message-buffer';
|
|
12
|
+
import { WebsocketFrontendConnectionService } from '@theia/core/lib/node/messaging/websocket-frontend-connection-service';
|
|
13
|
+
import { type interfaces } from '@theia/core/shared/inversify';
|
|
14
|
+
import { type ConnectionResilienceOptions } from '../common/connection-resilience-options';
|
|
15
|
+
import { FramedSocketWriteBuffer } from '../common/framed-socket-write-buffer';
|
|
16
|
+
import { InboundMessageSequence } from '../common/inbound-message-sequence';
|
|
17
|
+
/**
|
|
18
|
+
* Socket Theia hands the disconnect handler, read off the base signature rather
|
|
19
|
+
* than imported, which spares a direct `socket.io` dependency carried purely
|
|
20
|
+
* for a parameter type.
|
|
21
|
+
*/
|
|
22
|
+
export type FrontendSocket = Parameters<WebsocketFrontendConnectionService['handleSocketDisconnect']>[0];
|
|
23
|
+
/**
|
|
24
|
+
* Channel Theia hands the disconnect handler, read off the base signature so
|
|
25
|
+
* this package's emitted declarations name only
|
|
26
|
+
* `WebsocketFrontendConnectionService`.
|
|
27
|
+
*
|
|
28
|
+
* `ReconnectableSocketChannel` is not exported by every Theia release in the
|
|
29
|
+
* supported range, so importing it would make those declarations unresolvable
|
|
30
|
+
* for an adopter on one of them — a compile error for a feature they may not
|
|
31
|
+
* even be using.
|
|
32
|
+
*/
|
|
33
|
+
export type FrontendChannel = Parameters<WebsocketFrontendConnectionService['handleSocketDisconnect']>[1];
|
|
34
|
+
/**
|
|
35
|
+
* The server end of one frontend's session, carried across the sockets the
|
|
36
|
+
* frontend reconnects on.
|
|
37
|
+
*
|
|
38
|
+
* Theia's own channel sends straight into any socket that reports itself
|
|
39
|
+
* connected. A socket whose far end died unnoticed still does, so whatever is
|
|
40
|
+
* sent until the server notices is lost. This one numbers and keeps every
|
|
41
|
+
* message through {@link FramedSocketWriteBuffer}, resends what is still
|
|
42
|
+
* unacknowledged when the frontend reconnects, and drops what it has received
|
|
43
|
+
* twice. Otherwise it behaves as Theia's.
|
|
44
|
+
*/
|
|
45
|
+
export declare class AcknowledgedSocketChannel extends AbstractChannel {
|
|
46
|
+
protected readonly socketBuffer: FramedSocketWriteBuffer;
|
|
47
|
+
protected socket: FrontendSocket | undefined;
|
|
48
|
+
protected socketDisposables: DisposableCollection;
|
|
49
|
+
protected readonly inbound: InboundMessageSequence;
|
|
50
|
+
constructor(socketBuffer: FramedSocketWriteBuffer);
|
|
51
|
+
/** Flushes in the same step that attaches the listeners, so nothing new can overtake the resend. */
|
|
52
|
+
connect(socket: FrontendSocket): void;
|
|
53
|
+
disconnect(): void;
|
|
54
|
+
drainBuffer(): void;
|
|
55
|
+
getWriteBuffer(): WriteBuffer;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Ignores a disconnect from a socket that no longer belongs to the frontend.
|
|
59
|
+
*
|
|
60
|
+
* A frontend that loses its network reconnects on a new socket within seconds;
|
|
61
|
+
* the server only notices the old one is gone when its next heartbeat write
|
|
62
|
+
* fails, which is a whole ping interval later. For that stretch both sockets are
|
|
63
|
+
* registered against the same session, and Theia's disconnect handler tears the
|
|
64
|
+
* session off its socket without checking which one just died. The late
|
|
65
|
+
* notification from the abandoned socket therefore cuts the healthy one loose.
|
|
66
|
+
* The frontend sees a connected socket and never retries, so the session is dead
|
|
67
|
+
* until the page is reloaded.
|
|
68
|
+
*
|
|
69
|
+
* Changed here: only the socket the session is currently using may act on a
|
|
70
|
+
* disconnect. The handler is rewritten rather than wrapped because the problem
|
|
71
|
+
* sits inside the listener Theia installs; the rest of the body is Theia's.
|
|
72
|
+
*
|
|
73
|
+
* Re-diff against Theia when the supported range moves: `override` catches a changed signature,
|
|
74
|
+
* not a changed body, so this copy can go stale in silence.
|
|
75
|
+
*/
|
|
76
|
+
export declare class SessionBoundFrontendConnectionService extends WebsocketFrontendConnectionService {
|
|
77
|
+
/** Socket each frontend's channel is currently bound to, with the time it was bound. */
|
|
78
|
+
protected readonly bindings: Map<string, {
|
|
79
|
+
socketId: string;
|
|
80
|
+
boundAt: number;
|
|
81
|
+
}>;
|
|
82
|
+
/** When a frontend's live socket went away, so the reconnect gap can be reported. */
|
|
83
|
+
protected readonly offlineSince: Map<string, number>;
|
|
84
|
+
handleSocketDisconnect(socket: FrontendSocket, channel: FrontendChannel, frontEndId: string): void;
|
|
85
|
+
/**
|
|
86
|
+
* Theia's body, building an {@link AcknowledgedSocketChannel} in place of its own channel.
|
|
87
|
+
*
|
|
88
|
+
* Handed over through a cast, because Theia types the slot as its own channel class. The cast
|
|
89
|
+
* also hides from the compiler what Theia calls on the channel, so a release that calls a member
|
|
90
|
+
* this one lacks fails at runtime: re-diff with the disconnect handler.
|
|
91
|
+
*/
|
|
92
|
+
protected createConnection(socket: FrontendSocket, frontEndId: string): FrontendChannel;
|
|
93
|
+
/**
|
|
94
|
+
* One buffer per session, from the container Theia resolves its own channel's buffer from.
|
|
95
|
+
* Reached through a structural view because Theia 1.70 does not declare `container`.
|
|
96
|
+
*/
|
|
97
|
+
protected createWriteBuffer(): FramedSocketWriteBuffer;
|
|
98
|
+
protected closeConnection(frontEndId: string, reason: string): void;
|
|
99
|
+
/** Mirrors Theia's private `frontendConnectionTimeout`, including `Number('')` resolving to 0.
|
|
100
|
+
* Private there, so the copy is forced; re-diff it with the handler above. */
|
|
101
|
+
protected connectionTimeout(): number;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Replaces the server pieces that decide how a session survives a reconnect.
|
|
105
|
+
*
|
|
106
|
+
* `FrontendConnectionService` is bound `toService(WebsocketFrontendConnectionService)`,
|
|
107
|
+
* so rebinding the concrete class is enough. The buffer stays transient (one per
|
|
108
|
+
* connection), matching Theia's `bind(SocketWriteBuffer).toSelf()`; the frontend
|
|
109
|
+
* counterpart is bound by `bindConnectionResilience` in a `frontendPreload`
|
|
110
|
+
* module, which is the only point early enough on that side.
|
|
111
|
+
*
|
|
112
|
+
* Does nothing but warn on a Theia too old to expose the buffer binding, so the
|
|
113
|
+
* package keeps one supported range rather than splitting its floor for this
|
|
114
|
+
* feature. Returns whether the hardening was installed, for an adopter that
|
|
115
|
+
* wants to branch on it.
|
|
116
|
+
*/
|
|
117
|
+
export declare function bindConnectionResilience(bind: interfaces.Bind, isBound: interfaces.IsBound, rebind: interfaces.Rebind, options?: ConnectionResilienceOptions): boolean;
|
|
118
|
+
//# sourceMappingURL=session-bound-frontend-connection-service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-bound-frontend-connection-service.d.ts","sourceRoot":"","sources":["../../src/node/session-bound-frontend-connection-service.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;AAElF,OAAO,EAAc,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AACrF,OAAO,EAAE,eAAe,EAAE,MAAM,4CAA4C,CAAC;AAC7E,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,mDAAmD,CAAC;AAIrF,OAAO,EAAE,kCAAkC,EAAE,MAAM,sEAAsE,CAAC;AAC1H,OAAO,EAAc,KAAK,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAC3E,OAAO,EAAE,KAAK,2BAA2B,EAAE,MAAM,yCAAyC,CAAC;AAC3F,OAAO,EAGJ,uBAAuB,EAGzB,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EAAyB,sBAAsB,EAAE,MAAM,oCAAoC,CAAC;AAEnG;;;;GAIG;AACH,MAAM,MAAM,cAAc,GAAG,UAAU,CAAC,kCAAkC,CAAC,wBAAwB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAEz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AACH,wBAAgB,wBAAwB,CACrC,IAAI,EAAE,UAAU,CAAC,IAAI,EACrB,OAAO,EAAE,UAAU,CAAC,OAAO,EAC3B,MAAM,EAAE,UAAU,CAAC,MAAM,EACzB,OAAO,GAAE,2BAAgC,GACzC,OAAO,CAST"}
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/********************************************************************************
|
|
3
|
+
* Copyright (c) 2026 CrossBreeze, EclipseSource and others.
|
|
4
|
+
*
|
|
5
|
+
* This program and the accompanying materials are made available under the
|
|
6
|
+
* terms of the MIT License which is available in the project root.
|
|
7
|
+
*
|
|
8
|
+
* SPDX-License-Identifier: MIT
|
|
9
|
+
********************************************************************************/
|
|
10
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
11
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
12
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
13
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
14
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.SessionBoundFrontendConnectionService = exports.AcknowledgedSocketChannel = void 0;
|
|
18
|
+
exports.bindConnectionResilience = bindConnectionResilience;
|
|
19
|
+
const disposable_1 = require("@theia/core/lib/common/disposable");
|
|
20
|
+
const channel_1 = require("@theia/core/lib/common/message-rpc/channel");
|
|
21
|
+
const uint8_array_message_buffer_1 = require("@theia/core/lib/common/message-rpc/uint8-array-message-buffer");
|
|
22
|
+
const backend_application_config_provider_1 = require("@theia/core/lib/node/backend-application-config-provider");
|
|
23
|
+
const socket_write_buffer_1 = require("@theia/core/lib/common/messaging/socket-write-buffer");
|
|
24
|
+
const websocket_frontend_connection_service_1 = require("@theia/core/lib/node/messaging/websocket-frontend-connection-service");
|
|
25
|
+
const inversify_1 = require("@theia/core/shared/inversify");
|
|
26
|
+
const framed_socket_write_buffer_1 = require("../common/framed-socket-write-buffer");
|
|
27
|
+
const inbound_message_sequence_1 = require("../common/inbound-message-sequence");
|
|
28
|
+
/**
|
|
29
|
+
* The server end of one frontend's session, carried across the sockets the
|
|
30
|
+
* frontend reconnects on.
|
|
31
|
+
*
|
|
32
|
+
* Theia's own channel sends straight into any socket that reports itself
|
|
33
|
+
* connected. A socket whose far end died unnoticed still does, so whatever is
|
|
34
|
+
* sent until the server notices is lost. This one numbers and keeps every
|
|
35
|
+
* message through {@link FramedSocketWriteBuffer}, resends what is still
|
|
36
|
+
* unacknowledged when the frontend reconnects, and drops what it has received
|
|
37
|
+
* twice. Otherwise it behaves as Theia's.
|
|
38
|
+
*/
|
|
39
|
+
class AcknowledgedSocketChannel extends channel_1.AbstractChannel {
|
|
40
|
+
socketBuffer;
|
|
41
|
+
socket;
|
|
42
|
+
socketDisposables = new disposable_1.DisposableCollection();
|
|
43
|
+
inbound = new inbound_message_sequence_1.InboundMessageSequence(sequence => this.socket?.emit(inbound_message_sequence_1.ACKNOWLEDGEMENT_EVENT, sequence));
|
|
44
|
+
constructor(socketBuffer) {
|
|
45
|
+
super();
|
|
46
|
+
this.socketBuffer = socketBuffer;
|
|
47
|
+
this.toDispose.push(this.inbound);
|
|
48
|
+
this.toDispose.push(disposable_1.Disposable.create(() => this.socketDisposables.dispose()));
|
|
49
|
+
}
|
|
50
|
+
/** Flushes in the same step that attaches the listeners, so nothing new can overtake the resend. */
|
|
51
|
+
connect(socket) {
|
|
52
|
+
this.socketDisposables.dispose();
|
|
53
|
+
this.socketDisposables = new disposable_1.DisposableCollection();
|
|
54
|
+
this.socket = socket;
|
|
55
|
+
const errorHandler = (error) => this.onErrorEmitter.fire(error);
|
|
56
|
+
const dataListener = (data, sequence) => {
|
|
57
|
+
if (typeof sequence === 'number') {
|
|
58
|
+
this.socketBuffer.markPeerDeduplicates();
|
|
59
|
+
}
|
|
60
|
+
if (!this.inbound.accept(sequence, data.byteLength)) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
const buffer = data instanceof ArrayBuffer ? new Uint8Array(data) : data;
|
|
64
|
+
this.onMessageEmitter.fire(() => new uint8_array_message_buffer_1.Uint8ArrayReadBuffer(buffer));
|
|
65
|
+
};
|
|
66
|
+
const acknowledgementListener = (sequence) => {
|
|
67
|
+
if (typeof sequence === 'number') {
|
|
68
|
+
this.socketBuffer.acknowledge(sequence);
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
socket.on('error', errorHandler);
|
|
72
|
+
socket.on('message', dataListener);
|
|
73
|
+
socket.on(inbound_message_sequence_1.ACKNOWLEDGEMENT_EVENT, acknowledgementListener);
|
|
74
|
+
this.socketDisposables.push(disposable_1.Disposable.create(() => {
|
|
75
|
+
socket.off('error', errorHandler);
|
|
76
|
+
socket.off('message', dataListener);
|
|
77
|
+
socket.off(inbound_message_sequence_1.ACKNOWLEDGEMENT_EVENT, acknowledgementListener);
|
|
78
|
+
}));
|
|
79
|
+
this.socketBuffer.flush(socket);
|
|
80
|
+
}
|
|
81
|
+
disconnect() {
|
|
82
|
+
this.socketDisposables.dispose();
|
|
83
|
+
this.socket = undefined;
|
|
84
|
+
}
|
|
85
|
+
drainBuffer() {
|
|
86
|
+
this.socketBuffer.drain();
|
|
87
|
+
}
|
|
88
|
+
getWriteBuffer() {
|
|
89
|
+
const writeBuffer = new uint8_array_message_buffer_1.Uint8ArrayWriteBuffer();
|
|
90
|
+
writeBuffer.onCommit(data => this.socketBuffer.sendOrQueue(this.socket?.connected ? this.socket : undefined, data));
|
|
91
|
+
return writeBuffer;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
exports.AcknowledgedSocketChannel = AcknowledgedSocketChannel;
|
|
95
|
+
/**
|
|
96
|
+
* Ignores a disconnect from a socket that no longer belongs to the frontend.
|
|
97
|
+
*
|
|
98
|
+
* A frontend that loses its network reconnects on a new socket within seconds;
|
|
99
|
+
* the server only notices the old one is gone when its next heartbeat write
|
|
100
|
+
* fails, which is a whole ping interval later. For that stretch both sockets are
|
|
101
|
+
* registered against the same session, and Theia's disconnect handler tears the
|
|
102
|
+
* session off its socket without checking which one just died. The late
|
|
103
|
+
* notification from the abandoned socket therefore cuts the healthy one loose.
|
|
104
|
+
* The frontend sees a connected socket and never retries, so the session is dead
|
|
105
|
+
* until the page is reloaded.
|
|
106
|
+
*
|
|
107
|
+
* Changed here: only the socket the session is currently using may act on a
|
|
108
|
+
* disconnect. The handler is rewritten rather than wrapped because the problem
|
|
109
|
+
* sits inside the listener Theia installs; the rest of the body is Theia's.
|
|
110
|
+
*
|
|
111
|
+
* Re-diff against Theia when the supported range moves: `override` catches a changed signature,
|
|
112
|
+
* not a changed body, so this copy can go stale in silence.
|
|
113
|
+
*/
|
|
114
|
+
let SessionBoundFrontendConnectionService = class SessionBoundFrontendConnectionService extends websocket_frontend_connection_service_1.WebsocketFrontendConnectionService {
|
|
115
|
+
/** Socket each frontend's channel is currently bound to, with the time it was bound. */
|
|
116
|
+
bindings = new Map();
|
|
117
|
+
/** When a frontend's live socket went away, so the reconnect gap can be reported. */
|
|
118
|
+
offlineSince = new Map();
|
|
119
|
+
handleSocketDisconnect(socket, channel, frontEndId) {
|
|
120
|
+
const previous = this.bindings.get(frontEndId);
|
|
121
|
+
this.bindings.set(frontEndId, { socketId: socket.id, boundAt: Date.now() });
|
|
122
|
+
const wentOfflineAt = this.offlineSince.get(frontEndId);
|
|
123
|
+
this.offlineSince.delete(frontEndId);
|
|
124
|
+
const replacing = previous ? `, replacing socket ${previous.socketId}` : '';
|
|
125
|
+
const gap = wentOfflineAt === undefined ? '' : `, after ${Date.now() - wentOfflineAt} ms offline`;
|
|
126
|
+
console.info(`${framed_socket_write_buffer_1.CONNECTION_LOG_PREFIX} frontend ${frontEndId} channel bound to socket ${socket.id}${replacing}${gap}`);
|
|
127
|
+
socket.on('disconnect', reason => {
|
|
128
|
+
const bound = this.bindings.get(frontEndId);
|
|
129
|
+
if (bound?.socketId !== socket.id) {
|
|
130
|
+
// Either a superseded socket being reaped late, or one outliving `closeConnection`, which
|
|
131
|
+
// deletes the binding. Neither owns the channel, so neither may disconnect it, arm a close
|
|
132
|
+
// timeout, or close a connection that is no longer in `connectionsByFrontend`.
|
|
133
|
+
const owner = bound
|
|
134
|
+
? `socket ${bound.socketId} owns it (bound ${Date.now() - bound.boundAt} ms ago)`
|
|
135
|
+
: 'the connection is already closed';
|
|
136
|
+
console.info(`${framed_socket_write_buffer_1.CONNECTION_LOG_PREFIX} ignoring disconnect of stale socket ${socket.id} (frontend ${frontEndId}, ${reason}); ${owner}`);
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
// From here on: Theia's own handler body, unchanged apart from naming the socket.
|
|
140
|
+
this.offlineSince.set(frontEndId, Date.now());
|
|
141
|
+
console.info(`${framed_socket_write_buffer_1.CONNECTION_LOG_PREFIX} socket ${socket.id} (frontend ${frontEndId}) disconnected: ${reason}`);
|
|
142
|
+
channel.disconnect();
|
|
143
|
+
const timeout = this.connectionTimeout();
|
|
144
|
+
const isMarkedForClose = this.channelsMarkedForClose.delete(frontEndId);
|
|
145
|
+
if (timeout === 0 || isMarkedForClose) {
|
|
146
|
+
this.closeConnection(frontEndId, reason);
|
|
147
|
+
}
|
|
148
|
+
else if (timeout > 0) {
|
|
149
|
+
console.info(`${framed_socket_write_buffer_1.CONNECTION_LOG_PREFIX} close timeout for frontend ${frontEndId} set to ${timeout} ms`);
|
|
150
|
+
this.closeTimeouts.set(frontEndId, setTimeout(() => this.closeConnection(frontEndId, reason), timeout));
|
|
151
|
+
}
|
|
152
|
+
// timeout < 0: never close the back end.
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Theia's body, building an {@link AcknowledgedSocketChannel} in place of its own channel.
|
|
157
|
+
*
|
|
158
|
+
* Handed over through a cast, because Theia types the slot as its own channel class. The cast
|
|
159
|
+
* also hides from the compiler what Theia calls on the channel, so a release that calls a member
|
|
160
|
+
* this one lacks fails at runtime: re-diff with the disconnect handler.
|
|
161
|
+
*/
|
|
162
|
+
createConnection(socket, frontEndId) {
|
|
163
|
+
const channel = new AcknowledgedSocketChannel(this.createWriteBuffer());
|
|
164
|
+
channel.connect(socket);
|
|
165
|
+
this.connectionsByFrontend.set(frontEndId, channel);
|
|
166
|
+
return channel;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* One buffer per session, from the container Theia resolves its own channel's buffer from.
|
|
170
|
+
* Reached through a structural view because Theia 1.70 does not declare `container`.
|
|
171
|
+
*/
|
|
172
|
+
createWriteBuffer() {
|
|
173
|
+
const container = this.container;
|
|
174
|
+
const buffer = container.get(socket_write_buffer_1.SocketWriteBuffer);
|
|
175
|
+
if (!(buffer instanceof framed_socket_write_buffer_1.FramedSocketWriteBuffer)) {
|
|
176
|
+
throw new Error('SessionBoundFrontendConnectionService requires FramedSocketWriteBuffer to be bound');
|
|
177
|
+
}
|
|
178
|
+
return buffer;
|
|
179
|
+
}
|
|
180
|
+
closeConnection(frontEndId, reason) {
|
|
181
|
+
console.info(`${framed_socket_write_buffer_1.CONNECTION_LOG_PREFIX} closing frontend ${frontEndId}: ${reason}`);
|
|
182
|
+
this.bindings.delete(frontEndId);
|
|
183
|
+
this.offlineSince.delete(frontEndId);
|
|
184
|
+
super.closeConnection(frontEndId, reason);
|
|
185
|
+
}
|
|
186
|
+
/** Mirrors Theia's private `frontendConnectionTimeout`, including `Number('')` resolving to 0.
|
|
187
|
+
* Private there, so the copy is forced; re-diff it with the handler above. */
|
|
188
|
+
connectionTimeout() {
|
|
189
|
+
const envValue = Number(process.env['FRONTEND_CONNECTION_TIMEOUT']);
|
|
190
|
+
if (!isNaN(envValue)) {
|
|
191
|
+
return envValue;
|
|
192
|
+
}
|
|
193
|
+
return backend_application_config_provider_1.BackendApplicationConfigProvider.get().frontendConnectionTimeout;
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
exports.SessionBoundFrontendConnectionService = SessionBoundFrontendConnectionService;
|
|
197
|
+
exports.SessionBoundFrontendConnectionService = SessionBoundFrontendConnectionService = __decorate([
|
|
198
|
+
(0, inversify_1.injectable)()
|
|
199
|
+
], SessionBoundFrontendConnectionService);
|
|
200
|
+
/**
|
|
201
|
+
* Replaces the server pieces that decide how a session survives a reconnect.
|
|
202
|
+
*
|
|
203
|
+
* `FrontendConnectionService` is bound `toService(WebsocketFrontendConnectionService)`,
|
|
204
|
+
* so rebinding the concrete class is enough. The buffer stays transient (one per
|
|
205
|
+
* connection), matching Theia's `bind(SocketWriteBuffer).toSelf()`; the frontend
|
|
206
|
+
* counterpart is bound by `bindConnectionResilience` in a `frontendPreload`
|
|
207
|
+
* module, which is the only point early enough on that side.
|
|
208
|
+
*
|
|
209
|
+
* Does nothing but warn on a Theia too old to expose the buffer binding, so the
|
|
210
|
+
* package keeps one supported range rather than splitting its floor for this
|
|
211
|
+
* feature. Returns whether the hardening was installed, for an adopter that
|
|
212
|
+
* wants to branch on it.
|
|
213
|
+
*/
|
|
214
|
+
function bindConnectionResilience(bind, isBound, rebind, options = {}) {
|
|
215
|
+
if (!(0, framed_socket_write_buffer_1.supportsConnectionResilience)(isBound)) {
|
|
216
|
+
(0, framed_socket_write_buffer_1.warnConnectionResilienceUnavailable)('backend');
|
|
217
|
+
return false;
|
|
218
|
+
}
|
|
219
|
+
bind(SessionBoundFrontendConnectionService).toSelf().inSingletonScope();
|
|
220
|
+
rebind(websocket_frontend_connection_service_1.WebsocketFrontendConnectionService).toService(SessionBoundFrontendConnectionService);
|
|
221
|
+
rebind(socket_write_buffer_1.SocketWriteBuffer).toDynamicValue(() => (0, framed_socket_write_buffer_1.createFramedSocketWriteBuffer)(options));
|
|
222
|
+
return true;
|
|
223
|
+
}
|
|
224
|
+
//# sourceMappingURL=session-bound-frontend-connection-service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-bound-frontend-connection-service.js","sourceRoot":"","sources":["../../src/node/session-bound-frontend-connection-service.ts"],"names":[],"mappings":";AAAA;;;;;;;kFAOkF;;;;;;;;;;AAElF,kEAAqF;AACrF,wEAA6E;AAE7E,8GAA4H;AAC5H,kHAA4G;AAC5G,8FAAyF;AACzF,gIAA0H;AAC1H,4DAA2E;AAE3E,qFAM8C;AAC9C,iFAAmG;AAqBnG;;;;;;;;;;GAUG;AACH,+BAAuC,SAAQ,yBAAe;IAK5B,YAAY;IAJjC,MAAM,CAA6B;IACnC,iBAAiB,GAAG,IAAI,iCAAoB,EAAE,CAAC;IACtC,OAAO,GAAG,IAAI,iDAAsB,CAAC,QAAQ,CAAC,EAAE,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,gDAAqB,EAAE,QAAQ,CAAC,CAAC,CAAC;IAExH,YAA+B,YAAqC;QACjE,KAAK,EAAE,CAAC;4BADoB,YAAY;QAExC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAClC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,uBAAU,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,iBAAiB,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;IAClF,CAAC;IAED,oGAAoG;IACpG,OAAO,CAAC,MAAsB;QAC3B,IAAI,CAAC,iBAAiB,CAAC,OAAO,EAAE,CAAC;QACjC,IAAI,CAAC,iBAAiB,GAAG,IAAI,iCAAoB,EAAE,CAAC;QACpD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,MAAM,YAAY,GAAG,CAAC,KAAc,EAAQ,EAAE,CAAC,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC/E,MAAM,YAAY,GAAG,CAAC,IAA8B,EAAE,QAAkB,EAAQ,EAAE;YAC/E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AE,CAAC,CAAC;QACpE,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;QACjC,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;QACrC,KAAK,CAAC,eAAe,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;IAC7C,CAAC;IAED;mFAC+E;IACrE,iBAAiB;QACxB,MAAM,QAAQ,GAAG,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,6BAA6B,CAAC,CAAC,CAAC;QACpE,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC;YACpB,OAAO,QAAQ,CAAC;QACnB,CAAC;QACD,OAAO,sEAAgC,CAAC,GAAG,EAAE,CAAC,yBAAyB,CAAC;IAC3E,CAAC;CACH,CAAA;;gDA3FY,qCAAqC;IADjD,IAAA,sBAAU,GAAE;GACA,qCAAqC,CA2FjD;AAED;;;;;;;;;;;;;GAaG;AACH,kCACG,IAAqB,EACrB,OAA2B,EAC3B,MAAyB,EACzB,OAAO,GAAgC,EAAE;IAEzC,IAAI,CAAC,IAAA,yDAA4B,EAAC,OAAO,CAAC,EAAE,CAAC;QAC1C,IAAA,gEAAmC,EAAC,SAAS,CAAC,CAAC;QAC/C,OAAO,KAAK,CAAC;IAChB,CAAC;IACD,IAAI,CAAC,qCAAqC,CAAC,CAAC,MAAM,EAAE,CAAC,gBAAgB,EAAE,CAAC;IACxE,MAAM,CAAC,0EAAkC,CAAC,CAAC,SAAS,CAAC,qCAAqC,CAAC,CAAC;IAC5F,MAAM,CAAC,uCAAiB,CAAC,CAAC,cAAc,CAAC,GAAG,EAAE,CAAC,IAAA,0DAA6B,EAAC,OAAO,CAAC,CAAC,CAAC;IACvF,OAAO,IAAI,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/********************************************************************************
|
|
2
|
+
* Copyright (c) 2026 CrossBreeze, EclipseSource and others.
|
|
3
|
+
*
|
|
4
|
+
* This program and the accompanying materials are made available under the
|
|
5
|
+
* terms of the MIT License which is available in the project root.
|
|
6
|
+
*
|
|
7
|
+
* SPDX-License-Identifier: MIT
|
|
8
|
+
********************************************************************************/
|
|
9
|
+
import { type Clock } from '@hydranium/protocol';
|
|
10
|
+
import { type Channel, Disposable, DisposableCollection, type MessageProvider } from '@theia/core';
|
|
11
|
+
import type * as net from 'node:net';
|
|
12
|
+
import { type Message, type MessageConnection } from 'vscode-jsonrpc/node';
|
|
13
|
+
/**
|
|
14
|
+
* Relays JSON-RPC messages between a Theia browser-frontend {@link Channel} and
|
|
15
|
+
* a server's TCP socket — the backend half of a head's transport. The server
|
|
16
|
+
* speaks vscode-jsonrpc (Content-Length framed) on the socket; the frontend
|
|
17
|
+
* speaks the same protocol over the channel. This forwarder decodes each side
|
|
18
|
+
* and re-emits on the other.
|
|
19
|
+
*
|
|
20
|
+
* Behaves as `@eclipse-glsp/theia-integration`'s `SocketConnectionForwarder`
|
|
21
|
+
* does, and both heads use it, except that when the channel closes, the writes
|
|
22
|
+
* still queued go out before the socket ends. A page going away sends its last
|
|
23
|
+
* messages and closes its channel in the same tick, and the writer takes
|
|
24
|
+
* several turns per message, so destroying the socket on the close loses them.
|
|
25
|
+
*/
|
|
26
|
+
export declare class SocketChannelForwarder implements Disposable {
|
|
27
|
+
protected readonly channel: Channel;
|
|
28
|
+
protected readonly socket: net.Socket;
|
|
29
|
+
/** Times {@link flushTimeoutMs}. */
|
|
30
|
+
protected readonly clock: Clock;
|
|
31
|
+
protected readonly toDispose: DisposableCollection;
|
|
32
|
+
/** The last write to the socket; the writer runs its writes one at a time, so this settles last. */
|
|
33
|
+
protected lastWrite: Promise<void>;
|
|
34
|
+
/**
|
|
35
|
+
* How long {@link endSocket} waits for the queued writes before it destroys
|
|
36
|
+
* the socket anyway. Without a bound, a server that stops reading holds the
|
|
37
|
+
* socket open for good, and with it the server's end of the connection.
|
|
38
|
+
*/
|
|
39
|
+
protected readonly flushTimeoutMs: number;
|
|
40
|
+
constructor(channel: Channel, socket: net.Socket,
|
|
41
|
+
/** Times {@link flushTimeoutMs}. */
|
|
42
|
+
clock?: Clock);
|
|
43
|
+
/**
|
|
44
|
+
* Dispose `connection`, which destroys the socket, once the writes queued
|
|
45
|
+
* before the channel closed are out, or {@link flushTimeoutMs} has passed. A
|
|
46
|
+
* write has settled once the socket handed its bytes to the OS, and
|
|
47
|
+
* destroying the socket then loses nothing.
|
|
48
|
+
*/
|
|
49
|
+
protected endSocket(connection: MessageConnection): Promise<void>;
|
|
50
|
+
protected decodeChannelMessage(provider: MessageProvider): Message;
|
|
51
|
+
protected writeToChannel(message: Message): void;
|
|
52
|
+
dispose(): void;
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=socket-channel-forwarder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"socket-channel-forwarder.d.ts","sourceRoot":"","sources":["../../src/node/socket-channel-forwarder.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;AAElF,OAAO,EAAE,KAAK,KAAK,EAAe,MAAM,qBAAqB,CAAC;AAC9D,OAAO,EAAE,KAAK,OAAO,EAAE,UAAU,EAAE,oBAAoB,EAAE,KAAK,eAAe,EAAE,MAAM,aAAa,CAAC;AACnG,OAAO,KAAK,KAAK,GAAG,MAAM,UAAU,CAAC;AACrC,OAAO,EAEJ,KAAK,OAAO,EACZ,KAAK,iBAAiB,EAGxB,MAAM,qBAAqB,CAAC;AAE7B;;;;;;;;;;;;GAYG;AACH,qBAAa,sBAAuB,YAAW,UAAU;IAYnD,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,OAAO;IACnC,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM;IACrC,oCAAoC;IACpC,SAAS,CAAC,QAAQ,CAAC,KAAK,EAAE,KAAK;IAdlC,SAAS,CAAC,QAAQ,CAAC,SAAS,uBAA8B;IAC1D,oGAAoG;IACpG,SAAS,CAAC,SAAS,EAA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