@hydranium/client-theia 1.0.0-next.17 → 1.0.0-next.173

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.
Files changed (86) hide show
  1. package/README.md +39 -6
  2. package/lib/browser/channel-logger.d.ts +4 -3
  3. package/lib/browser/channel-logger.d.ts.map +1 -1
  4. package/lib/browser/channel-logger.js +9 -4
  5. package/lib/browser/channel-logger.js.map +1 -1
  6. package/lib/browser/connection-diagnostics-contribution.d.ts +69 -0
  7. package/lib/browser/connection-diagnostics-contribution.d.ts.map +1 -0
  8. package/lib/browser/connection-diagnostics-contribution.js +153 -0
  9. package/lib/browser/connection-diagnostics-contribution.js.map +1 -0
  10. package/lib/browser/connection-reporter.d.ts +57 -0
  11. package/lib/browser/connection-reporter.d.ts.map +1 -0
  12. package/lib/browser/connection-reporter.js +104 -0
  13. package/lib/browser/connection-reporter.js.map +1 -0
  14. package/lib/browser/editor-disk-sync.d.ts +133 -0
  15. package/lib/browser/editor-disk-sync.d.ts.map +1 -0
  16. package/lib/browser/editor-disk-sync.js +232 -0
  17. package/lib/browser/editor-disk-sync.js.map +1 -0
  18. package/lib/browser/hydranium-file-service.d.ts +44 -0
  19. package/lib/browser/hydranium-file-service.d.ts.map +1 -0
  20. package/lib/browser/hydranium-file-service.js +61 -0
  21. package/lib/browser/hydranium-file-service.js.map +1 -0
  22. package/lib/browser/index.d.ts +5 -0
  23. package/lib/browser/index.d.ts.map +1 -1
  24. package/lib/browser/index.js +5 -0
  25. package/lib/browser/index.js.map +1 -1
  26. package/lib/browser/log-level-preference.d.ts.map +1 -1
  27. package/lib/browser/log-level-preference.js +11 -0
  28. package/lib/browser/log-level-preference.js.map +1 -1
  29. package/lib/browser/memory-diagnostics-contribution.d.ts +40 -4
  30. package/lib/browser/memory-diagnostics-contribution.d.ts.map +1 -1
  31. package/lib/browser/memory-diagnostics-contribution.js +161 -31
  32. package/lib/browser/memory-diagnostics-contribution.js.map +1 -1
  33. package/lib/browser/session-aware-connection-source.d.ts +98 -0
  34. package/lib/browser/session-aware-connection-source.d.ts.map +1 -0
  35. package/lib/browser/session-aware-connection-source.js +167 -0
  36. package/lib/browser/session-aware-connection-source.js.map +1 -0
  37. package/lib/common/clock.d.ts +19 -0
  38. package/lib/common/clock.d.ts.map +1 -0
  39. package/lib/common/clock.js +13 -0
  40. package/lib/common/clock.js.map +1 -0
  41. package/lib/common/connection-resilience-options.d.ts +24 -0
  42. package/lib/common/connection-resilience-options.d.ts.map +1 -0
  43. package/lib/common/connection-resilience-options.js +11 -0
  44. package/lib/common/connection-resilience-options.js.map +1 -0
  45. package/lib/common/framed-socket-write-buffer.d.ts +121 -0
  46. package/lib/common/framed-socket-write-buffer.d.ts.map +1 -0
  47. package/lib/common/framed-socket-write-buffer.js +190 -0
  48. package/lib/common/framed-socket-write-buffer.js.map +1 -0
  49. package/lib/common/index.d.ts +12 -0
  50. package/lib/common/index.d.ts.map +1 -0
  51. package/lib/common/index.js +31 -0
  52. package/lib/common/index.js.map +1 -0
  53. package/lib/node/abstract-socket-forwarding-connection-handler.d.ts +12 -8
  54. package/lib/node/abstract-socket-forwarding-connection-handler.d.ts.map +1 -1
  55. package/lib/node/abstract-socket-forwarding-connection-handler.js +70 -13
  56. package/lib/node/abstract-socket-forwarding-connection-handler.js.map +1 -1
  57. package/lib/node/index.d.ts +2 -0
  58. package/lib/node/index.d.ts.map +1 -1
  59. package/lib/node/index.js +2 -0
  60. package/lib/node/index.js.map +1 -1
  61. package/lib/node/session-bound-frontend-connection-service.d.ts +77 -0
  62. package/lib/node/session-bound-frontend-connection-service.d.ts.map +1 -0
  63. package/lib/node/session-bound-frontend-connection-service.js +128 -0
  64. package/lib/node/session-bound-frontend-connection-service.js.map +1 -0
  65. package/lib/node/socket-channel-forwarder.d.ts +54 -0
  66. package/lib/node/socket-channel-forwarder.d.ts.map +1 -0
  67. package/lib/node/socket-channel-forwarder.js +93 -0
  68. package/lib/node/socket-channel-forwarder.js.map +1 -0
  69. package/package.json +20 -5
  70. package/src/browser/channel-logger.ts +9 -4
  71. package/src/browser/connection-diagnostics-contribution.ts +142 -0
  72. package/src/browser/connection-reporter.ts +121 -0
  73. package/src/browser/editor-disk-sync.ts +236 -0
  74. package/src/browser/hydranium-file-service.ts +56 -0
  75. package/src/browser/index.ts +5 -0
  76. package/src/browser/log-level-preference.ts +11 -0
  77. package/src/browser/memory-diagnostics-contribution.ts +268 -45
  78. package/src/browser/session-aware-connection-source.ts +179 -0
  79. package/src/common/clock.ts +20 -0
  80. package/src/common/connection-resilience-options.ts +24 -0
  81. package/src/common/framed-socket-write-buffer.ts +227 -0
  82. package/src/common/index.ts +15 -0
  83. package/src/node/abstract-socket-forwarding-connection-handler.ts +61 -15
  84. package/src/node/index.ts +2 -0
  85. package/src/node/session-bound-frontend-connection-service.ts +155 -0
  86. package/src/node/socket-channel-forwarder.ts +99 -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 single per-head variation — *which* byte forwarder bridges the channel and
72
- * the socket — is the abstract {@link forwardToSocketConnection} hook: the GLSP
73
- * head plugs in `@eclipse-glsp/theia-integration`'s `SocketConnectionForwarder`,
74
- * the data-server head its own `SocketChannelForwarder`. Keeping the forwarder
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.messageService.error(`Could not connect to ${this.serverName}: ` + message);
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
- async findPort() {
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
- setTimeout(async () => {
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
- if (port) {
139
- pendingContent.resolve(port);
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
- socket.connect({ port });
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;A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AAY,cAAc,QAAQ,CAAC,MAAM,6EAA6E,CACjI,CAAC;YACF,OAAO;QACV,CAAC;QACD,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,YAAY,eAAe,QAAQ,CAAC,MAAM,yDAAyD,CAAC,CAAC;QAC/H,KAAK,MAAM,QAAQ,IAAI,QAAQ,EAAE,CAAC;YAC/B,SAAS,CAAC,gBAAgB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC7C,CAAC;IACJ,CAAC;CACH,CAAA;AAlJqB,8FAAyC;AAC1B;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;oDANlC,yCAAyC;IAD9D,IAAA,sBAAU,GAAE;;GACS,yCAAyC,CAkJ9D"}
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,8CAAgC;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,GAAU,IAAI,sBAAW,EAAE,CAAC;IAEtE,IAAI,CAAS;IAEH,WAAW,CAAS;IACpB,YAAY,CAAS;IACrB,UAAU,CAAS;IACnB,eAAe,CAAS;IACxB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A8D,CAAC,CAAC;YACnI,OAAO;QACV,CAAC;QACD,MAAM,SAAS,GAAG,OAAsF,CAAC;QACzG,IAAI,CAAC,SAAS,CAAC,gBAAgB,EAAE,CAAC;YAC/B,IAAI,CAAC,MAAM,CAAC,IAAI,CACb,IAAI,IAAI,CAAC,YAAY,cAAc,QAAQ,CAAC,MAAM,6EAA6E,CACjI,CAAC;YACF,OAAO;QACV,CAAC;QACD,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,YAAY,eAAe,QAAQ,CAAC,MAAM,yDAAyD,CAAC,CAAC;QAC/H,KAAK,MAAM,QAAQ,IAAI,QAAQ,EAAE,CAAC;YAC/B,SAAS,CAAC,gBAAgB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC7C,CAAC;IACJ,CAAC;CACH,CAAA;AA/LqB,8FAAyC;AAC1B;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,CA+L9D"}
@@ -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
@@ -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
@@ -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,77 @@
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 { WebsocketFrontendConnectionService } from '@theia/core/lib/node/messaging/websocket-frontend-connection-service';
10
+ import { type interfaces } from '@theia/core/shared/inversify';
11
+ import { type ConnectionResilienceOptions } from '../common/connection-resilience-options';
12
+ /**
13
+ * Socket Theia hands the disconnect handler, read off the base signature rather
14
+ * than imported, which spares a direct `socket.io` dependency carried purely
15
+ * for a parameter type.
16
+ */
17
+ export type FrontendSocket = Parameters<WebsocketFrontendConnectionService['handleSocketDisconnect']>[0];
18
+ /**
19
+ * Channel Theia hands the disconnect handler, read off the base signature so
20
+ * this package's emitted declarations name only
21
+ * `WebsocketFrontendConnectionService`.
22
+ *
23
+ * `ReconnectableSocketChannel` is not exported by every Theia release in the
24
+ * supported range, so importing it would make those declarations unresolvable
25
+ * for an adopter on one of them — a compile error for a feature they may not
26
+ * even be using.
27
+ */
28
+ export type FrontendChannel = Parameters<WebsocketFrontendConnectionService['handleSocketDisconnect']>[1];
29
+ /**
30
+ * Ignores a disconnect from a socket that no longer belongs to the frontend.
31
+ *
32
+ * A frontend that loses its network reconnects on a new socket within seconds;
33
+ * the server only notices the old one is gone when its next heartbeat write
34
+ * fails, which is a whole ping interval later. For that stretch both sockets are
35
+ * registered against the same session, and Theia's disconnect handler tears the
36
+ * session off its socket without checking which one just died. The late
37
+ * notification from the abandoned socket therefore cuts the healthy one loose.
38
+ * The frontend sees a connected socket and never retries, so the session is dead
39
+ * until the page is reloaded.
40
+ *
41
+ * Changed here: only the socket the session is currently using may act on a
42
+ * disconnect. The handler is rewritten rather than wrapped because the problem
43
+ * sits inside the listener Theia installs; the rest of the body is Theia's.
44
+ *
45
+ * Re-diff against Theia when the supported range moves: `override` catches a changed signature,
46
+ * not a changed body, so this copy can go stale in silence.
47
+ */
48
+ export declare class SessionBoundFrontendConnectionService extends WebsocketFrontendConnectionService {
49
+ /** Socket each frontend's channel is currently bound to, with the time it was bound. */
50
+ protected readonly bindings: Map<string, {
51
+ socketId: string;
52
+ boundAt: number;
53
+ }>;
54
+ /** When a frontend's live socket went away, so the reconnect gap can be reported. */
55
+ protected readonly offlineSince: Map<string, number>;
56
+ handleSocketDisconnect(socket: FrontendSocket, channel: FrontendChannel, frontEndId: string): void;
57
+ protected closeConnection(frontEndId: string, reason: string): void;
58
+ /** Mirrors Theia's private `frontendConnectionTimeout`, including `Number('')` resolving to 0.
59
+ * Private there, so the copy is forced; re-diff it with the handler above. */
60
+ protected connectionTimeout(): number;
61
+ }
62
+ /**
63
+ * Replaces the server pieces that decide how a session survives a reconnect.
64
+ *
65
+ * `FrontendConnectionService` is bound `toService(WebsocketFrontendConnectionService)`,
66
+ * so rebinding the concrete class is enough. The buffer stays transient (one per
67
+ * connection), matching Theia's `bind(SocketWriteBuffer).toSelf()`; the frontend
68
+ * counterpart is bound by `bindConnectionResilience` in a `frontendPreload`
69
+ * module, which is the only point early enough on that side.
70
+ *
71
+ * Does nothing but warn on a Theia too old to expose the buffer binding, so the
72
+ * package keeps one supported range rather than splitting its floor for this
73
+ * feature. Returns whether the hardening was installed, for an adopter that
74
+ * wants to branch on it.
75
+ */
76
+ export declare function bindConnectionResilience(bind: interfaces.Bind, isBound: interfaces.IsBound, rebind: interfaces.Rebind, options?: ConnectionResilienceOptions): boolean;
77
+ //# 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;AAIlF,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;AAQ3F;;;;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,CAAC;AAE1G;;;;;;;;;;;;;;;;;;GAkBG;AACH,qBACa,qCAAsC,SAAQ,kCAAkC;IAC1F,wFAAwF;IACxF,SAAS,CAAC,QAAQ,CAAC,QAAQ;kBAA+B,MAAM;iBAAW,MAAM;OAAM;IACvF,qFAAqF;IACrF,SAAS,CAAC,QAAQ,CAAC,YAAY,sBAA6B;IAEnD,sBAAsB,CAAC,MAAM,EAAE,cAAc,EAAE,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,GAAG,IAAI;cA0CxF,eAAe,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI;IAO5E;mFAC+E;IAC/E,SAAS,CAAC,iBAAiB,IAAI,MAAM;CAOvC;AAED;;;;;;;;;;;;;GAaG;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,128 @@
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 = void 0;
18
+ exports.bindConnectionResilience = bindConnectionResilience;
19
+ const backend_application_config_provider_1 = require("@theia/core/lib/node/backend-application-config-provider");
20
+ const socket_write_buffer_1 = require("@theia/core/lib/common/messaging/socket-write-buffer");
21
+ const websocket_frontend_connection_service_1 = require("@theia/core/lib/node/messaging/websocket-frontend-connection-service");
22
+ const inversify_1 = require("@theia/core/shared/inversify");
23
+ const framed_socket_write_buffer_1 = require("../common/framed-socket-write-buffer");
24
+ /**
25
+ * Ignores a disconnect from a socket that no longer belongs to the frontend.
26
+ *
27
+ * A frontend that loses its network reconnects on a new socket within seconds;
28
+ * the server only notices the old one is gone when its next heartbeat write
29
+ * fails, which is a whole ping interval later. For that stretch both sockets are
30
+ * registered against the same session, and Theia's disconnect handler tears the
31
+ * session off its socket without checking which one just died. The late
32
+ * notification from the abandoned socket therefore cuts the healthy one loose.
33
+ * The frontend sees a connected socket and never retries, so the session is dead
34
+ * until the page is reloaded.
35
+ *
36
+ * Changed here: only the socket the session is currently using may act on a
37
+ * disconnect. The handler is rewritten rather than wrapped because the problem
38
+ * sits inside the listener Theia installs; the rest of the body is Theia's.
39
+ *
40
+ * Re-diff against Theia when the supported range moves: `override` catches a changed signature,
41
+ * not a changed body, so this copy can go stale in silence.
42
+ */
43
+ let SessionBoundFrontendConnectionService = class SessionBoundFrontendConnectionService extends websocket_frontend_connection_service_1.WebsocketFrontendConnectionService {
44
+ /** Socket each frontend's channel is currently bound to, with the time it was bound. */
45
+ bindings = new Map();
46
+ /** When a frontend's live socket went away, so the reconnect gap can be reported. */
47
+ offlineSince = new Map();
48
+ handleSocketDisconnect(socket, channel, frontEndId) {
49
+ const previous = this.bindings.get(frontEndId);
50
+ this.bindings.set(frontEndId, { socketId: socket.id, boundAt: Date.now() });
51
+ const wentOfflineAt = this.offlineSince.get(frontEndId);
52
+ this.offlineSince.delete(frontEndId);
53
+ const replacing = previous ? `, replacing socket ${previous.socketId}` : '';
54
+ const gap = wentOfflineAt === undefined ? '' : `, after ${Date.now() - wentOfflineAt} ms offline`;
55
+ console.info(`${framed_socket_write_buffer_1.CONNECTION_LOG_PREFIX} frontend ${frontEndId} channel bound to socket ${socket.id}${replacing}${gap}`);
56
+ socket.on('disconnect', reason => {
57
+ const bound = this.bindings.get(frontEndId);
58
+ if (bound?.socketId !== socket.id) {
59
+ // Either a superseded socket being reaped late, or one outliving `closeConnection`, which
60
+ // deletes the binding. Neither owns the channel, so neither may disconnect it, arm a close
61
+ // timeout, or close a connection that is no longer in `connectionsByFrontend`.
62
+ const owner = bound
63
+ ? `socket ${bound.socketId} owns it (bound ${Date.now() - bound.boundAt} ms ago)`
64
+ : 'the connection is already closed';
65
+ console.info(`${framed_socket_write_buffer_1.CONNECTION_LOG_PREFIX} ignoring disconnect of stale socket ${socket.id} (frontend ${frontEndId}, ${reason}); ${owner}`);
66
+ return;
67
+ }
68
+ // From here on: Theia's own handler body, unchanged apart from naming the socket.
69
+ this.offlineSince.set(frontEndId, Date.now());
70
+ console.info(`${framed_socket_write_buffer_1.CONNECTION_LOG_PREFIX} socket ${socket.id} (frontend ${frontEndId}) disconnected: ${reason}`);
71
+ channel.disconnect();
72
+ const timeout = this.connectionTimeout();
73
+ const isMarkedForClose = this.channelsMarkedForClose.delete(frontEndId);
74
+ if (timeout === 0 || isMarkedForClose) {
75
+ this.closeConnection(frontEndId, reason);
76
+ }
77
+ else if (timeout > 0) {
78
+ console.info(`${framed_socket_write_buffer_1.CONNECTION_LOG_PREFIX} close timeout for frontend ${frontEndId} set to ${timeout} ms`);
79
+ this.closeTimeouts.set(frontEndId, setTimeout(() => this.closeConnection(frontEndId, reason), timeout));
80
+ }
81
+ // timeout < 0: never close the back end.
82
+ });
83
+ }
84
+ closeConnection(frontEndId, reason) {
85
+ console.info(`${framed_socket_write_buffer_1.CONNECTION_LOG_PREFIX} closing frontend ${frontEndId}: ${reason}`);
86
+ this.bindings.delete(frontEndId);
87
+ this.offlineSince.delete(frontEndId);
88
+ super.closeConnection(frontEndId, reason);
89
+ }
90
+ /** Mirrors Theia's private `frontendConnectionTimeout`, including `Number('')` resolving to 0.
91
+ * Private there, so the copy is forced; re-diff it with the handler above. */
92
+ connectionTimeout() {
93
+ const envValue = Number(process.env['FRONTEND_CONNECTION_TIMEOUT']);
94
+ if (!isNaN(envValue)) {
95
+ return envValue;
96
+ }
97
+ return backend_application_config_provider_1.BackendApplicationConfigProvider.get().frontendConnectionTimeout;
98
+ }
99
+ };
100
+ exports.SessionBoundFrontendConnectionService = SessionBoundFrontendConnectionService;
101
+ exports.SessionBoundFrontendConnectionService = SessionBoundFrontendConnectionService = __decorate([
102
+ (0, inversify_1.injectable)()
103
+ ], SessionBoundFrontendConnectionService);
104
+ /**
105
+ * Replaces the server pieces that decide how a session survives a reconnect.
106
+ *
107
+ * `FrontendConnectionService` is bound `toService(WebsocketFrontendConnectionService)`,
108
+ * so rebinding the concrete class is enough. The buffer stays transient (one per
109
+ * connection), matching Theia's `bind(SocketWriteBuffer).toSelf()`; the frontend
110
+ * counterpart is bound by `bindConnectionResilience` in a `frontendPreload`
111
+ * module, which is the only point early enough on that side.
112
+ *
113
+ * Does nothing but warn on a Theia too old to expose the buffer binding, so the
114
+ * package keeps one supported range rather than splitting its floor for this
115
+ * feature. Returns whether the hardening was installed, for an adopter that
116
+ * wants to branch on it.
117
+ */
118
+ function bindConnectionResilience(bind, isBound, rebind, options = {}) {
119
+ if (!(0, framed_socket_write_buffer_1.supportsConnectionResilience)(isBound)) {
120
+ (0, framed_socket_write_buffer_1.warnConnectionResilienceUnavailable)('backend');
121
+ return false;
122
+ }
123
+ bind(SessionBoundFrontendConnectionService).toSelf().inSingletonScope();
124
+ rebind(websocket_frontend_connection_service_1.WebsocketFrontendConnectionService).toService(SessionBoundFrontendConnectionService);
125
+ rebind(socket_write_buffer_1.SocketWriteBuffer).toDynamicValue(() => (0, framed_socket_write_buffer_1.createFramedSocketWriteBuffer)(options.bufferBytes));
126
+ return true;
127
+ }
128
+ //# 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;;;;;;;;;AAqIlF,4DAcC;AAjJD,kHAA4G;AAC5G,8FAAyF;AACzF,gIAA0H;AAC1H,4DAA2E;AAE3E,qFAK8C;AAqB9C;;;;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AAI,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,EAAE,OAAO,CAAC,IAAI,CAAC,CAAqB;IACvD;;;;OAIG;IACH,SAAS,CAAC,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAU;gBAG7B,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,GAAG,CAAC,MAAM;IACrC,oCAAoC;IACjB,KAAK,GAAE,KAAyB;IAyBtD;;;;;OAKG;cACa,SAAS,CAAC,UAAU,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;IAKvE,SAAS,CAAC,oBAAoB,CAAC,QAAQ,EAAE,eAAe,GAAG,OAAO;IAKlE,SAAS,CAAC,cAAc,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI;IAMhD,OAAO,IAAI,IAAI;CAGjB"}
@@ -0,0 +1,93 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.SocketChannelForwarder = void 0;
12
+ const protocol_1 = require("@hydranium/protocol");
13
+ const core_1 = require("@theia/core");
14
+ const node_1 = require("vscode-jsonrpc/node");
15
+ /**
16
+ * Relays JSON-RPC messages between a Theia browser-frontend {@link Channel} and
17
+ * a server's TCP socket — the backend half of a head's transport. The server
18
+ * speaks vscode-jsonrpc (Content-Length framed) on the socket; the frontend
19
+ * speaks the same protocol over the channel. This forwarder decodes each side
20
+ * and re-emits on the other.
21
+ *
22
+ * Behaves as `@eclipse-glsp/theia-integration`'s `SocketConnectionForwarder`
23
+ * does, and both heads use it, except that when the channel closes, the writes
24
+ * still queued go out before the socket ends. A page going away sends its last
25
+ * messages and closes its channel in the same tick, and the writer takes
26
+ * several turns per message, so destroying the socket on the close loses them.
27
+ */
28
+ class SocketChannelForwarder {
29
+ channel;
30
+ socket;
31
+ clock;
32
+ toDispose = new core_1.DisposableCollection();
33
+ /** The last write to the socket; the writer runs its writes one at a time, so this settles last. */
34
+ lastWrite = Promise.resolve();
35
+ /**
36
+ * How long {@link endSocket} waits for the queued writes before it destroys
37
+ * the socket anyway. Without a bound, a server that stops reading holds the
38
+ * socket open for good, and with it the server's end of the connection.
39
+ */
40
+ flushTimeoutMs = 10_000;
41
+ constructor(channel, socket,
42
+ /** Times {@link flushTimeoutMs}. */
43
+ clock = new protocol_1.SystemClock()) {
44
+ this.channel = channel;
45
+ this.socket = socket;
46
+ this.clock = clock;
47
+ const reader = new node_1.SocketMessageReader(socket);
48
+ const writer = new node_1.SocketMessageWriter(socket);
49
+ const connection = (0, node_1.createMessageConnection)(reader, writer);
50
+ // Nothing here destroys the socket directly. `SocketMessageWriter.dispose()`
51
+ // destroys it itself, which covers both `dispose` and `endSocket`; and
52
+ // `connection.onClose` fires only from the reader's or writer's own close,
53
+ // which for a socket means the socket has already gone — so a destroy
54
+ // handler there is downstream of the effect it would be trying to cause.
55
+ this.toDispose.pushAll([
56
+ reader.listen(message => this.writeToChannel(message)),
57
+ channel.onMessage(provider => {
58
+ // A failed write means the socket is gone, which its own close reports.
59
+ this.lastWrite = writer.write(this.decodeChannelMessage(provider)).catch(() => undefined);
60
+ }),
61
+ channel.onClose(() => void this.endSocket(connection)),
62
+ connection.onClose(() => channel.close()),
63
+ core_1.Disposable.create(() => {
64
+ channel.close();
65
+ connection.dispose();
66
+ })
67
+ ]);
68
+ }
69
+ /**
70
+ * Dispose `connection`, which destroys the socket, once the writes queued
71
+ * before the channel closed are out, or {@link flushTimeoutMs} has passed. A
72
+ * write has settled once the socket handed its bytes to the OS, and
73
+ * destroying the socket then loses nothing.
74
+ */
75
+ async endSocket(connection) {
76
+ await this.clock.raceTimer(this.lastWrite, this.flushTimeoutMs);
77
+ connection.dispose();
78
+ }
79
+ decodeChannelMessage(provider) {
80
+ const buffer = provider().readBytes();
81
+ return JSON.parse(new TextDecoder().decode(buffer));
82
+ }
83
+ writeToChannel(message) {
84
+ const writeBuffer = this.channel.getWriteBuffer();
85
+ writeBuffer.writeBytes(new TextEncoder().encode(JSON.stringify(message)));
86
+ writeBuffer.commit();
87
+ }
88
+ dispose() {
89
+ this.toDispose.dispose();
90
+ }
91
+ }
92
+ exports.SocketChannelForwarder = SocketChannelForwarder;
93
+ //# sourceMappingURL=socket-channel-forwarder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"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