@hydranium/client-theia 1.0.0-next.38 → 1.0.0-next.380
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 +53 -81
- 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 +11 -19
- package/lib/browser/channel-logger.js.map +1 -1
- package/lib/browser/connection-diagnostics-contribution.d.ts +73 -0
- package/lib/browser/connection-diagnostics-contribution.d.ts.map +1 -0
- package/lib/browser/connection-diagnostics-contribution.js +162 -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 +1 -1
- package/lib/browser/memory-diagnostics-contribution.d.ts.map +1 -1
- package/lib/browser/memory-diagnostics-contribution.js +1 -1
- package/lib/browser/memory-diagnostics-contribution.js.map +1 -1
- package/lib/browser/session-aware-connection-source.d.ts +104 -0
- package/lib/browser/session-aware-connection-source.d.ts.map +1 -0
- package/lib/browser/session-aware-connection-source.js +193 -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 +16 -12
- package/lib/node/abstract-socket-forwarding-connection-handler.d.ts.map +1 -1
- package/lib/node/abstract-socket-forwarding-connection-handler.js +94 -31
- 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 +122 -0
- package/lib/node/session-bound-frontend-connection-service.d.ts.map +1 -0
- package/lib/node/session-bound-frontend-connection-service.js +236 -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 +33 -34
- package/src/browser/browser-capture.ts +1 -1
- package/src/browser/channel-logger.ts +11 -19
- package/src/browser/connection-diagnostics-contribution.ts +146 -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 +4 -3
- package/src/browser/session-aware-connection-source.ts +205 -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 +85 -36
- package/src/node/index.ts +2 -0
- package/src/node/session-bound-frontend-connection-service.ts +264 -0
- package/src/node/socket-channel-forwarder.ts +101 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/common/index.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;AAKlF,cAAc,8BAA8B,CAAC;AAC7C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,iCAAiC,CAAC;AAChD,cAAc,SAAS,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
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 __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
13
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
14
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
15
|
+
}
|
|
16
|
+
Object.defineProperty(o, k2, desc);
|
|
17
|
+
}) : (function(o, m, k, k2) {
|
|
18
|
+
if (k2 === undefined) k2 = k;
|
|
19
|
+
o[k2] = m[k];
|
|
20
|
+
}));
|
|
21
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
22
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
23
|
+
};
|
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
// Environment-neutral primitives that the browser and the server tiers each
|
|
26
|
+
// bind for their own side, such as the buffer for each half of the socket.
|
|
27
|
+
// Kept out of both tier barrels for that reason.
|
|
28
|
+
__exportStar(require("./framed-socket-write-buffer"), exports);
|
|
29
|
+
__exportStar(require("./inbound-message-sequence"), exports);
|
|
30
|
+
__exportStar(require("./connection-resilience-options"), exports);
|
|
31
|
+
__exportStar(require("./clock"), exports);
|
|
32
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/common/index.ts"],"names":[],"mappings":";AAAA;;;;;;;kFAOkF;;;;;;;;;;;;;;;;AAElF,4EAA4E;AAC5E,2EAA2E;AAC3E,iDAAiD;AACjD,+DAA6C;AAC7C,6DAA2C;AAC3C,kEAAgD;AAChD,0CAAwB"}
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
********************************************************************************/
|
|
9
9
|
import { type Channel, CommandService, type ConnectionHandler, type Disposable, ILogger, type MessageProvider, MessageService } from '@theia/core';
|
|
10
10
|
import * as net from 'node:net';
|
|
11
|
+
import { Clock } from '../common/clock';
|
|
11
12
|
/** Resolved configuration for a {@link AbstractSocketForwardingConnectionHandler}.
|
|
12
13
|
* A head-specific subclass derives these from its own (adopter-facing) options
|
|
13
14
|
* and passes them to `super(...)`. */
|
|
@@ -47,17 +48,17 @@ export interface SocketForwardingConnectionHandlerOptions {
|
|
|
47
48
|
* the same wire protocol the server speaks, so the backend performs no semantic
|
|
48
49
|
* re-proxy — it relays bytes only and stays oblivious to the server's method set.
|
|
49
50
|
*
|
|
50
|
-
* The
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
* behind the hook is what lets the data head stay GLSP-free while sharing the
|
|
55
|
-
* port-discovery + buffer-and-replay race fix + connect orchestration here.
|
|
51
|
+
* The byte forwarder that bridges the channel and the socket is
|
|
52
|
+
* {@link forwardToSocketConnection}; both heads use {@link SocketChannelForwarder},
|
|
53
|
+
* and the port discovery, buffer-and-replay race fix and connect orchestration
|
|
54
|
+
* here are shared.
|
|
56
55
|
*/
|
|
57
56
|
export declare abstract class AbstractSocketForwardingConnectionHandler implements ConnectionHandler {
|
|
58
57
|
protected messageService: MessageService;
|
|
59
58
|
protected commandService: CommandService;
|
|
60
59
|
protected readonly logger: ILogger;
|
|
60
|
+
/** The clock each {@link SocketChannelForwarder} bounds its flush on: the container's {@link Clock}, or a `SystemClock`. */
|
|
61
|
+
protected readonly clock: Clock;
|
|
61
62
|
readonly path: string;
|
|
62
63
|
protected readonly portCommand: string;
|
|
63
64
|
protected readonly logComponent: string;
|
|
@@ -69,7 +70,10 @@ export declare abstract class AbstractSocketForwardingConnectionHandler implemen
|
|
|
69
70
|
constructor(options: SocketForwardingConnectionHandlerOptions);
|
|
70
71
|
onConnection(connection: Channel): void;
|
|
71
72
|
protected initializeServerConnection(channel: Channel): Promise<void>;
|
|
72
|
-
|
|
73
|
+
/** Tell the user this handler gave up; `message` is the reason it logged. */
|
|
74
|
+
protected reportConnectFailure(message: string): void;
|
|
75
|
+
/** Poll the port command until it answers, its attempts run out, or `signal` aborts. */
|
|
76
|
+
protected findPort(signal?: AbortSignal): Promise<number>;
|
|
73
77
|
protected connectToServer(channel: Channel, port: number, preForwardBuffer?: {
|
|
74
78
|
bufferSub: Disposable;
|
|
75
79
|
buffered: MessageProvider[];
|
|
@@ -79,17 +83,17 @@ export declare abstract class AbstractSocketForwardingConnectionHandler implemen
|
|
|
79
83
|
* relay both ways. Called once, after the socket is created and the
|
|
80
84
|
* pre-forward buffer is about to be replayed.
|
|
81
85
|
*/
|
|
82
|
-
protected
|
|
86
|
+
protected forwardToSocketConnection(clientChannel: Channel, socket: net.Socket): Disposable;
|
|
83
87
|
/**
|
|
84
|
-
* Re-fire pre-forward buffered `MessageProvider`s on the channel's
|
|
88
|
+
* Re-fire pre-forward buffered `MessageProvider`s on the channel's
|
|
85
89
|
* `onMessageEmitter` so the now-subscribed forwarder picks them up in arrival
|
|
86
90
|
* order. `MessageProvider` is a thunk (`() => ReadBuffer`) — buffering does
|
|
87
91
|
* not consume the read position, so replay produces the same bytes the
|
|
88
92
|
* forwarder would have seen if wired earlier.
|
|
89
93
|
*
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
*
|
|
94
|
+
* The emitter is public on `AbstractChannel`; the `Channel` interface
|
|
95
|
+
* carries just its `Event`, so any other channel has its messages logged as
|
|
96
|
+
* dropped. A Theia rename of the emitter fails to compile here.
|
|
93
97
|
*/
|
|
94
98
|
protected replayBufferedMessages(channel: Channel, buffered: MessageProvider[]): void;
|
|
95
99
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"abstract-socket-forwarding-connection-handler.d.ts","sourceRoot":"","sources":["../../src/node/abstract-socket-forwarding-connection-handler.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;
|
|
1
|
+
{"version":3,"file":"abstract-socket-forwarding-connection-handler.d.ts","sourceRoot":"","sources":["../../src/node/abstract-socket-forwarding-connection-handler.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;AAGlF,OAAO,EACJ,KAAK,OAAO,EACZ,cAAc,EACd,KAAK,iBAAiB,EACtB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,CAAC,eAAe,EAAE,MAAM,CAAC;IAC3C,SAAS,CAAC,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;IAC5C,SAAS,CAAC,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;IAC5C,SAAS,CAAC,QAAQ,CAAC,eAAe,CAAC,EAAE,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,KAAK,IAAI,CAAC;IAElE,YAAY,OAAO,EAAE,wCAAwC,EAS5D;IAED,YAAY,CAAC,UAAU,EAAE,OAAO,GAAG,IAAI,CAEtC;IAED,UAAgB,0BAA0B,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAkC1E;IAED,6EAA6E;IAC7E,SAAS,CAAC,oBAAoB,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAEpD;IAED,wFAAwF;IACxF,UAAgB,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC,CAwC9D;IAED,UAAgB,eAAe,CAC5B,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,MAAM,EACZ,gBAAgB,CAAC,EAAE;QAAE,SAAS,EAAE,UAAU,CAAC;QAAC,QAAQ,EAAE,eAAe,EAAE,CAAA;KAAE,GACzE,OAAO,CAAC,IAAI,CAAC,CAuCf;IAED;;;;OAIG;IACH,SAAS,CAAC,yBAAyB,CAAC,aAAa,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,GAAG,UAAU,CAE1F;IAED;;;;;;;;;;OAUG;IACH,SAAS,CAAC,sBAAsB,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,GAAG,IAAI,CASpF;CACH"}
|
|
@@ -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,67 @@ 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();
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
132
|
+
if (closed.signal.aborted) {
|
|
133
|
+
this.logger.debug(`[${this.logComponent}] Stopped connecting to ${this.serverName}: the frontend closed the channel.`);
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
this.logger.error(`[${this.logComponent}] Could not connect to ${this.serverName}: ${(0, protocol_1.describeErrorWithStack)(error)}`);
|
|
137
|
+
this.reportConnectFailure((0, protocol_1.describeError)(error));
|
|
138
|
+
// Closed so the frontend learns of it: left open, the channel has no
|
|
139
|
+
// server behind it, and every request on it waits for good.
|
|
140
|
+
channel.close();
|
|
129
141
|
}
|
|
142
|
+
finally {
|
|
143
|
+
closeSub.dispose();
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
/** Tell the user this handler gave up; `message` is the reason it logged. */
|
|
147
|
+
reportConnectFailure(message) {
|
|
148
|
+
this.messageService.error(`Could not connect to ${this.serverName}: ` + message);
|
|
130
149
|
}
|
|
131
|
-
|
|
150
|
+
/** Poll the port command until it answers, its attempts run out, or `signal` aborts. */
|
|
151
|
+
async findPort(signal) {
|
|
132
152
|
const pendingContent = new promise_util_1.Deferred();
|
|
133
153
|
let counter = 0;
|
|
154
|
+
let timer;
|
|
155
|
+
const stop = () => {
|
|
156
|
+
clearTimeout(timer);
|
|
157
|
+
pendingContent.reject(signal?.reason);
|
|
158
|
+
};
|
|
159
|
+
if (signal?.aborted) {
|
|
160
|
+
stop();
|
|
161
|
+
}
|
|
162
|
+
signal?.addEventListener('abort', stop, { once: true });
|
|
134
163
|
const tryQueryingPort = () => {
|
|
135
|
-
|
|
164
|
+
if (signal?.aborted) {
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
timer = setTimeout(async () => {
|
|
136
168
|
try {
|
|
137
169
|
const port = await this.commandService.executeCommand(this.portCommand);
|
|
138
|
-
|
|
139
|
-
|
|
170
|
+
// An empty answer fails the attempt like a throw does: left
|
|
171
|
+
// unanswered, it neither resolves nor re-queues, and the lookup
|
|
172
|
+
// stays pending with nothing logged.
|
|
173
|
+
if (!port) {
|
|
174
|
+
throw new Error(`Port command '${this.portCommand}' answered without a port.`);
|
|
140
175
|
}
|
|
176
|
+
pendingContent.resolve(port);
|
|
141
177
|
}
|
|
142
178
|
catch (error) {
|
|
143
179
|
counter++;
|
|
180
|
+
const message = (0, protocol_1.describeError)(error);
|
|
181
|
+
this.logger.debug(`[${this.logComponent}] Port command '${this.portCommand}' attempt ${counter} failed: ${message}`);
|
|
144
182
|
if (this.findPortAttempts >= 0 && counter > this.findPortAttempts) {
|
|
145
183
|
pendingContent.reject(error);
|
|
146
184
|
}
|
|
@@ -157,9 +195,21 @@ let AbstractSocketForwardingConnectionHandler = class AbstractSocketForwardingCo
|
|
|
157
195
|
const connected = new promise_util_1.Deferred();
|
|
158
196
|
const socket = new net.Socket();
|
|
159
197
|
this.onSocketCreated?.(socket);
|
|
160
|
-
|
|
198
|
+
let ready = false;
|
|
199
|
+
socket.on('ready', () => {
|
|
200
|
+
ready = true;
|
|
201
|
+
connected.resolve();
|
|
202
|
+
});
|
|
161
203
|
socket.on('close', () => connected.reject(`Socket to ${this.serverName} was closed.`));
|
|
162
|
-
|
|
204
|
+
// Before `ready` the error fails the connect, whose caller logs it; the `close` that follows rejects too late to count.
|
|
205
|
+
socket.on('error', error => {
|
|
206
|
+
if (ready) {
|
|
207
|
+
this.logger.error(`Error occurred with the ${this.serverName} socket: ${(0, protocol_1.describeErrorWithStack)(error)}`);
|
|
208
|
+
}
|
|
209
|
+
else {
|
|
210
|
+
connected.reject(error);
|
|
211
|
+
}
|
|
212
|
+
});
|
|
163
213
|
// Synchronous hand-off: dispose the pre-forward buffer FIRST, then wire the
|
|
164
214
|
// forwarder, then replay buffered messages. The event loop cannot
|
|
165
215
|
// interleave between these synchronous statements, so no message is both
|
|
@@ -170,37 +220,45 @@ let AbstractSocketForwardingConnectionHandler = class AbstractSocketForwardingCo
|
|
|
170
220
|
if (preForwardBuffer && preForwardBuffer.buffered.length > 0) {
|
|
171
221
|
this.replayBufferedMessages(channel, preForwardBuffer.buffered);
|
|
172
222
|
}
|
|
173
|
-
if (channel instanceof channel_1.
|
|
223
|
+
if (channel instanceof channel_1.AbstractChannel) {
|
|
174
224
|
socket.on('error', error => channel.onErrorEmitter.fire(error));
|
|
175
225
|
}
|
|
176
|
-
|
|
226
|
+
// `127.0.0.1`, not the `localhost` Node dials when no host is given, and it
|
|
227
|
+
// has to match the head: the socket launchers bind `127.0.0.1` by default,
|
|
228
|
+
// so on a dual-stack machine where `localhost` resolves to `::1` first the
|
|
229
|
+
// dial fails as ECONNREFUSED with nothing in the message naming the address
|
|
230
|
+
// family as the cause.
|
|
231
|
+
socket.connect({ port, host: '127.0.0.1' });
|
|
177
232
|
setTimeout(() => connected.reject('Timeout reached.'), this.connectTimeoutMs);
|
|
178
233
|
return connected.promise;
|
|
179
234
|
}
|
|
180
235
|
/**
|
|
181
|
-
*
|
|
236
|
+
* Bridge the Theia frontend `clientChannel` and the server `socket` so bytes
|
|
237
|
+
* relay both ways. Called once, after the socket is created and the
|
|
238
|
+
* pre-forward buffer is about to be replayed.
|
|
239
|
+
*/
|
|
240
|
+
forwardToSocketConnection(clientChannel, socket) {
|
|
241
|
+
return new socket_channel_forwarder_1.SocketChannelForwarder(clientChannel, socket, this.clock);
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Re-fire pre-forward buffered `MessageProvider`s on the channel's
|
|
182
245
|
* `onMessageEmitter` so the now-subscribed forwarder picks them up in arrival
|
|
183
246
|
* order. `MessageProvider` is a thunk (`() => ReadBuffer`) — buffering does
|
|
184
247
|
* not consume the read position, so replay produces the same bytes the
|
|
185
248
|
* forwarder would have seen if wired earlier.
|
|
186
249
|
*
|
|
187
|
-
*
|
|
188
|
-
*
|
|
189
|
-
*
|
|
250
|
+
* The emitter is public on `AbstractChannel`; the `Channel` interface
|
|
251
|
+
* carries just its `Event`, so any other channel has its messages logged as
|
|
252
|
+
* dropped. A Theia rename of the emitter fails to compile here.
|
|
190
253
|
*/
|
|
191
254
|
replayBufferedMessages(channel, buffered) {
|
|
192
|
-
if (!(channel instanceof channel_1.
|
|
193
|
-
this.logger.
|
|
194
|
-
return;
|
|
195
|
-
}
|
|
196
|
-
const internals = channel;
|
|
197
|
-
if (!internals.onMessageEmitter) {
|
|
198
|
-
this.logger.warn(`[${this.logComponent}] dropping ${buffered.length} pre-forward message(s) — ForwardingChannel.onMessageEmitter not accessible`);
|
|
255
|
+
if (!(channel instanceof channel_1.AbstractChannel)) {
|
|
256
|
+
this.logger.error(`[${this.logComponent}] dropping ${buffered.length} pre-forward message(s) — channel is not an AbstractChannel`);
|
|
199
257
|
return;
|
|
200
258
|
}
|
|
201
|
-
this.logger.
|
|
259
|
+
this.logger.debug(`[${this.logComponent}] replaying ${buffered.length} pre-forward message(s) onto the wired socket forwarder`);
|
|
202
260
|
for (const provider of buffered) {
|
|
203
|
-
|
|
261
|
+
channel.onMessageEmitter.fire(provider);
|
|
204
262
|
}
|
|
205
263
|
}
|
|
206
264
|
};
|
|
@@ -217,6 +275,11 @@ __decorate([
|
|
|
217
275
|
(0, inversify_1.inject)(core_1.ILogger),
|
|
218
276
|
__metadata("design:type", Object)
|
|
219
277
|
], AbstractSocketForwardingConnectionHandler.prototype, "logger", void 0);
|
|
278
|
+
__decorate([
|
|
279
|
+
(0, inversify_1.inject)(clock_1.Clock),
|
|
280
|
+
(0, inversify_1.optional)(),
|
|
281
|
+
__metadata("design:type", Object)
|
|
282
|
+
], AbstractSocketForwardingConnectionHandler.prototype, "clock", void 0);
|
|
220
283
|
exports.AbstractSocketForwardingConnectionHandler = AbstractSocketForwardingConnectionHandler = __decorate([
|
|
221
284
|
(0, inversify_1.injectable)(),
|
|
222
285
|
__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,
|
|
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,kDAAyF;AACzF,sCAQqB;AACrB,wEAA6E;AAC7E,sEAA+D;AAC/D,4DAA4E;AAC5E,MAAY,GAAG,qCAAiB;AAChC,2CAAwC;AACxC,yEAAoE;AA8BpE;;;;;;;;;;;;;;;;GAgBG;AAEI,IAAe,yCAAyC,GAAxD,MAAe,yCAAyC;IAC1B,cAAc,CAAkB;IAChC,cAAc,CAAkB;IAClE,4EAA4E;IAC5E,wEAAwE;IACxE,sEAAsE;IAClC,MAAM,CAAW;IACrD,4HAA4H;IAC9E,KAAK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CAAC,CAAC,OAAO,YAAY,yBAAe,CAAC,EAAE,CAAC;YACzC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC,YAAY,cAAc,QAAQ,CAAC,MAAM,6DAA6D,CAAC,CAAC;YACnI,OAAO;QACV,CAAC;QACD,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC,YAAY,eAAe,QAAQ,CAAC,MAAM,yDAAyD,CAAC,CAAC;QAChI,KAAK,MAAM,QAAQ,IAAI,QAAQ,EAAE,CAAC;YAC/B,OAAO,CAAC,gBAAgB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC3C,CAAC;IACJ,CAAC;CACH,CAAA;;AAjMoC;IAAjC,IAAA,kBAAM,EAAC,qBAAc,CAAC;8BAA4B,qBAAc;iFAAC;AAChC;IAAjC,IAAA,kBAAM,EAAC,qBAAc,CAAC;;iFAA2C;AAI9B;IAAnC,IAAA,kBAAM,EAAC,cAAO,CAAC;;yEAAqC;AAEP;IAA7C,IAAA,kBAAM,EAAC,aAAK,CAAC;IAAE,IAAA,oBAAQ,GAAE;;wEAAqD;oDAR5D,yCAAyC;IAD9D,IAAA,sBAAU,GAAE;;GACS,yCAAyC,CAkM9D"}
|
package/lib/node/index.d.ts
CHANGED
|
@@ -7,4 +7,6 @@
|
|
|
7
7
|
* SPDX-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,122 @@
|
|
|
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 Stopwatch } from '@hydranium/protocol';
|
|
10
|
+
import { DisposableCollection } from '@theia/core/lib/common/disposable';
|
|
11
|
+
import { AbstractChannel } from '@theia/core/lib/common/message-rpc/channel';
|
|
12
|
+
import { type WriteBuffer } from '@theia/core/lib/common/message-rpc/message-buffer';
|
|
13
|
+
import { WebsocketFrontendConnectionService } from '@theia/core/lib/node/messaging/websocket-frontend-connection-service';
|
|
14
|
+
import { type interfaces } from '@theia/core/shared/inversify';
|
|
15
|
+
import { Clock } from '../common/clock';
|
|
16
|
+
import { type ConnectionResilienceOptions } from '../common/connection-resilience-options';
|
|
17
|
+
import { FramedSocketWriteBuffer } from '../common/framed-socket-write-buffer';
|
|
18
|
+
import { InboundMessageSequence } from '../common/inbound-message-sequence';
|
|
19
|
+
/**
|
|
20
|
+
* Socket Theia hands the disconnect handler, read off the base signature rather
|
|
21
|
+
* than imported, which spares a direct `socket.io` dependency carried purely
|
|
22
|
+
* for a parameter type.
|
|
23
|
+
*/
|
|
24
|
+
export type FrontendSocket = Parameters<WebsocketFrontendConnectionService['handleSocketDisconnect']>[0];
|
|
25
|
+
/**
|
|
26
|
+
* Channel Theia hands the disconnect handler, read off the base signature so
|
|
27
|
+
* this package's emitted declarations name only
|
|
28
|
+
* `WebsocketFrontendConnectionService`.
|
|
29
|
+
*
|
|
30
|
+
* `ReconnectableSocketChannel` is not exported by every Theia release in the
|
|
31
|
+
* supported range, so importing it would make those declarations unresolvable
|
|
32
|
+
* for an adopter on one of them — a compile error for a feature they may not
|
|
33
|
+
* even be using.
|
|
34
|
+
*/
|
|
35
|
+
export type FrontendChannel = Parameters<WebsocketFrontendConnectionService['handleSocketDisconnect']>[1];
|
|
36
|
+
/**
|
|
37
|
+
* The server end of one frontend's session, carried across the sockets the
|
|
38
|
+
* frontend reconnects on.
|
|
39
|
+
*
|
|
40
|
+
* Theia's own channel sends straight into any socket that reports itself
|
|
41
|
+
* connected. A socket whose far end died unnoticed still does, so whatever is
|
|
42
|
+
* sent until the server notices is lost. This one numbers and keeps every
|
|
43
|
+
* message through {@link FramedSocketWriteBuffer}, resends what is still
|
|
44
|
+
* unacknowledged when the frontend reconnects, and drops what it has received
|
|
45
|
+
* twice. Otherwise it behaves as Theia's.
|
|
46
|
+
*/
|
|
47
|
+
export declare class AcknowledgedSocketChannel extends AbstractChannel {
|
|
48
|
+
protected readonly socketBuffer: FramedSocketWriteBuffer;
|
|
49
|
+
protected socket: FrontendSocket | undefined;
|
|
50
|
+
protected socketDisposables: DisposableCollection;
|
|
51
|
+
protected readonly inbound: InboundMessageSequence;
|
|
52
|
+
constructor(socketBuffer: FramedSocketWriteBuffer);
|
|
53
|
+
/** Flushes in the same step that attaches the listeners, so nothing new can overtake the resend. */
|
|
54
|
+
connect(socket: FrontendSocket): void;
|
|
55
|
+
disconnect(): void;
|
|
56
|
+
drainBuffer(): void;
|
|
57
|
+
getWriteBuffer(): WriteBuffer;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Ignores a disconnect from a socket that no longer belongs to the frontend.
|
|
61
|
+
*
|
|
62
|
+
* A frontend that loses its network reconnects on a new socket within seconds;
|
|
63
|
+
* the server only notices the old one is gone when its next heartbeat write
|
|
64
|
+
* fails, which is a whole ping interval later. For that stretch both sockets are
|
|
65
|
+
* registered against the same session, and Theia's disconnect handler tears the
|
|
66
|
+
* session off its socket without checking which one just died. The late
|
|
67
|
+
* notification from the abandoned socket therefore cuts the healthy one loose.
|
|
68
|
+
* The frontend sees a connected socket and never retries, so the session is dead
|
|
69
|
+
* until the page is reloaded.
|
|
70
|
+
*
|
|
71
|
+
* Changed here: only the socket the session is currently using may act on a
|
|
72
|
+
* disconnect. The handler is rewritten rather than wrapped because the problem
|
|
73
|
+
* sits inside the listener Theia installs; the rest of the body is Theia's.
|
|
74
|
+
*
|
|
75
|
+
* Re-diff against Theia when the supported range moves: `override` catches a changed signature,
|
|
76
|
+
* not a changed body, so this copy can go stale in silence.
|
|
77
|
+
*/
|
|
78
|
+
export declare class SessionBoundFrontendConnectionService extends WebsocketFrontendConnectionService {
|
|
79
|
+
/** Times the gaps the log reports: the container's {@link Clock}, or a `SystemClock`. */
|
|
80
|
+
protected readonly clock: Clock;
|
|
81
|
+
/** Socket each frontend's channel is currently bound to, with how long it has been. */
|
|
82
|
+
protected readonly bindings: Map<string, {
|
|
83
|
+
socketId: string;
|
|
84
|
+
sinceBound: Stopwatch;
|
|
85
|
+
}>;
|
|
86
|
+
/** Running since a frontend's live socket went away, so the reconnect gap can be reported. */
|
|
87
|
+
protected readonly sinceOffline: Map<string, Stopwatch>;
|
|
88
|
+
handleSocketDisconnect(socket: FrontendSocket, channel: FrontendChannel, frontEndId: string): void;
|
|
89
|
+
/**
|
|
90
|
+
* Theia's body, building an {@link AcknowledgedSocketChannel} in place of its own channel.
|
|
91
|
+
*
|
|
92
|
+
* Handed over through a cast, because Theia types the slot as its own channel class. The cast
|
|
93
|
+
* also hides from the compiler what Theia calls on the channel, so a release that calls a member
|
|
94
|
+
* this one lacks fails at runtime: re-diff with the disconnect handler.
|
|
95
|
+
*/
|
|
96
|
+
protected createConnection(socket: FrontendSocket, frontEndId: string): FrontendChannel;
|
|
97
|
+
/**
|
|
98
|
+
* One buffer per session, from the container Theia resolves its own channel's buffer from.
|
|
99
|
+
* Reached through a structural view because Theia 1.70 does not declare `container`.
|
|
100
|
+
*/
|
|
101
|
+
protected createWriteBuffer(): FramedSocketWriteBuffer;
|
|
102
|
+
protected closeConnection(frontEndId: string, reason: string): void;
|
|
103
|
+
/** Mirrors Theia's private `frontendConnectionTimeout`, including `Number('')` resolving to 0.
|
|
104
|
+
* Private there, so the copy is forced; re-diff it with the handler above. */
|
|
105
|
+
protected connectionTimeout(): number;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Replaces the server pieces that decide how a session survives a reconnect.
|
|
109
|
+
*
|
|
110
|
+
* `FrontendConnectionService` is bound `toService(WebsocketFrontendConnectionService)`,
|
|
111
|
+
* so rebinding the concrete class is enough. The buffer stays transient (one per
|
|
112
|
+
* connection), matching Theia's `bind(SocketWriteBuffer).toSelf()`; the frontend
|
|
113
|
+
* counterpart is bound by `bindConnectionResilience` in a `frontendPreload`
|
|
114
|
+
* module, which is the only point early enough on that side.
|
|
115
|
+
*
|
|
116
|
+
* Does nothing but warn on a Theia too old to expose the buffer binding, so the
|
|
117
|
+
* package keeps one supported range rather than splitting its floor for this
|
|
118
|
+
* feature. Returns whether the hardening was installed, for an adopter that
|
|
119
|
+
* wants to branch on it.
|
|
120
|
+
*/
|
|
121
|
+
export declare function bindConnectionResilience(bind: interfaces.Bind, isBound: interfaces.IsBound, rebind: interfaces.Rebind, options?: ConnectionResilienceOptions): boolean;
|
|
122
|
+
//# 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,EAAE,KAAK,SAAS,EAAe,MAAM,qBAAqB,CAAC;AAClE,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,EAAgC,KAAK,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAC7F,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AACxC,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;AAEzG;;;;;;;;;GASG;AACH,MAAM,MAAM,eAAe,GAAG,UAAU,CAAC,kCAAkC,CAAC,wBAAwB,CAAC,CAAC,CAAC,CAAC,CAAC,C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