@hydranium/client-theia 1.0.0-next.13 → 1.0.0-next.135
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 +35 -8
- 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 +9 -4
- 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/editor-disk-sync.d.ts +133 -0
- package/lib/browser/editor-disk-sync.d.ts.map +1 -0
- package/lib/browser/editor-disk-sync.js +232 -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 +4 -0
- package/lib/browser/index.d.ts.map +1 -1
- package/lib/browser/index.js +4 -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 +98 -0
- package/lib/browser/session-aware-connection-source.d.ts.map +1 -0
- package/lib/browser/session-aware-connection-source.js +167 -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 +24 -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 +121 -0
- package/lib/common/framed-socket-write-buffer.d.ts.map +1 -0
- package/lib/common/framed-socket-write-buffer.js +190 -0
- package/lib/common/framed-socket-write-buffer.js.map +1 -0
- package/lib/common/index.d.ts +12 -0
- package/lib/common/index.d.ts.map +1 -0
- package/lib/common/index.js +31 -0
- package/lib/common/index.js.map +1 -0
- package/lib/node/abstract-socket-forwarding-connection-handler.d.ts +8 -7
- package/lib/node/abstract-socket-forwarding-connection-handler.d.ts.map +1 -1
- package/lib/node/abstract-socket-forwarding-connection-handler.js +28 -7
- 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 +77 -0
- package/lib/node/session-bound-frontend-connection-service.d.ts.map +1 -0
- package/lib/node/session-bound-frontend-connection-service.js +128 -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 +93 -0
- package/lib/node/socket-channel-forwarder.js.map +1 -0
- package/package.json +24 -9
- package/src/browser/channel-logger.ts +9 -4
- package/src/browser/connection-diagnostics-contribution.ts +142 -0
- package/src/browser/editor-disk-sync.ts +236 -0
- package/src/browser/hydranium-file-service.ts +56 -0
- package/src/browser/index.ts +4 -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 +179 -0
- package/src/common/clock.ts +20 -0
- package/src/common/connection-resilience-options.ts +24 -0
- package/src/common/framed-socket-write-buffer.ts +227 -0
- package/src/common/index.ts +15 -0
- package/src/node/abstract-socket-forwarding-connection-handler.ts +19 -9
- package/src/node/index.ts +2 -0
- package/src/node/session-bound-frontend-connection-service.ts +155 -0
- package/src/node/socket-channel-forwarder.ts +99 -0
|
@@ -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;;;;;;;;;;;;;;;;;;GAkBG;AAEI,IAAM,qCAAqC,GAA3C,MAAM,qCAAsC,SAAQ,0EAAkC;IAC1F,wFAAwF;IACrE,QAAQ,GAAG,IAAI,GAAG,EAAiD,CAAC;IACvF,qFAAqF;IAClE,YAAY,GAAG,IAAI,GAAG,EAAkB,C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C,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;AAhEY,sFAAqC;gDAArC,qCAAqC;IADjD,IAAA,sBAAU,GAAE;GACA,qCAAqC,CAgEjD;AAED;;;;;;;;;;;;;GAaG;AACH,SAAgB,wBAAwB,CACrC,IAAqB,EACrB,OAA2B,EAC3B,MAAyB,EACzB,UAAuC,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,WAAW,CAAC,CAAC,CAAC;IACnG,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,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,"file":"socket-channel-forwarder.js","sourceRoot":"","sources":["../../src/node/socket-channel-forwarder.ts"],"names":[],"mappings":";AAAA;;;;;;;kFAOkF;;;AAElF,kDAA8D;AAC9D,sCAAmG;AAEnG,8CAM6B;AAE7B;;;;;;;;;;;;GAYG;AACH,MAAa,sBAAsB;IAYV;IACA;IAEA;IAdH,SAAS,GAAG,IAAI,2BAAoB,EAAE,CAAC;IAC1D,oGAAoG;IAC1F,SAAS,GAAkB,OAAO,CAAC,OAAO,EAAE,CAAC;IAC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KAAK,CAAC,SAAS,CAAC,UAA6B;QACpD,MAAM,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,cAAc,CAAC,CAAC;QAChE,UAAU,CAAC,OAAO,EAAE,CAAC;IACxB,CAAC;IAES,oBAAoB,CAAC,QAAyB;QACrD,MAAM,MAAM,GAAG,QAAQ,EAAE,CAAC,SAAS,EAAE,CAAC;QACtC,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,CAAY,CAAC;IAClE,CAAC;IAES,cAAc,CAAC,OAAgB;QACtC,MAAM,WAAW,GAAG,IAAI,CAAC,OAAO,CAAC,cAAc,EAAE,CAAC;QAClD,WAAW,CAAC,UAAU,CAAC,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;QAC1E,WAAW,CAAC,MAAM,EAAE,CAAC;IACxB,CAAC;IAED,OAAO;QACJ,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC;IAC5B,CAAC;CACH;AAjED,wDAiEC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hydranium/client-theia",
|
|
3
|
-
"version": "1.0.0-next.
|
|
3
|
+
"version": "1.0.0-next.135",
|
|
4
4
|
"description": "Cross-head Theia client primitives shared by the hydranium protocol heads. Provides the socket-forwarding connection-handler base that the data-server and GLSP Theia integrations subclass, plus the preference-driven Output-channel logger; carries no head-specific dependency.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"hydranium",
|
|
@@ -36,6 +36,14 @@
|
|
|
36
36
|
"types": "./lib/browser/index.d.ts",
|
|
37
37
|
"default": "./lib/browser/index.js"
|
|
38
38
|
},
|
|
39
|
+
"./common": {
|
|
40
|
+
"types": "./lib/common/index.d.ts",
|
|
41
|
+
"default": "./lib/common/index.js"
|
|
42
|
+
},
|
|
43
|
+
"./lib/common": {
|
|
44
|
+
"types": "./lib/common/index.d.ts",
|
|
45
|
+
"default": "./lib/common/index.js"
|
|
46
|
+
},
|
|
39
47
|
"./node": {
|
|
40
48
|
"types": "./lib/node/index.d.ts",
|
|
41
49
|
"default": "./lib/node/index.js"
|
|
@@ -70,20 +78,26 @@
|
|
|
70
78
|
"watch": "tsc -b -w --preserveWatchOutput"
|
|
71
79
|
},
|
|
72
80
|
"devDependencies": {
|
|
73
|
-
"@hydranium/protocol": "1.0.0-next.
|
|
74
|
-
"@theia/core": "^1.
|
|
75
|
-
"@theia/
|
|
81
|
+
"@hydranium/protocol": "1.0.0-next.135",
|
|
82
|
+
"@theia/core": "^1.70.0",
|
|
83
|
+
"@theia/editor": "^1.70.0",
|
|
84
|
+
"@theia/filesystem": "^1.70.0",
|
|
85
|
+
"@theia/output": "^1.70.0",
|
|
76
86
|
"@types/node": "^22.0.0",
|
|
77
87
|
"inversify": "6.2.2",
|
|
78
88
|
"reflect-metadata": "0.2.2",
|
|
79
89
|
"rimraf": "^5.0.0",
|
|
80
|
-
"typescript": "^5.8.0"
|
|
90
|
+
"typescript": "^5.8.0",
|
|
91
|
+
"vscode-jsonrpc": "9.0.1"
|
|
81
92
|
},
|
|
82
93
|
"peerDependencies": {
|
|
83
|
-
"@hydranium/protocol": "1.0.0-next.
|
|
84
|
-
"@theia/core": "^1.
|
|
85
|
-
"@theia/
|
|
86
|
-
"
|
|
94
|
+
"@hydranium/protocol": "1.0.0-next.135",
|
|
95
|
+
"@theia/core": "^1.70.0",
|
|
96
|
+
"@theia/editor": "^1.70.0",
|
|
97
|
+
"@theia/filesystem": "^1.70.0",
|
|
98
|
+
"@theia/output": "^1.70.0",
|
|
99
|
+
"inversify": "^6.0.0",
|
|
100
|
+
"vscode-jsonrpc": "9.0.1"
|
|
87
101
|
},
|
|
88
102
|
"engines": {
|
|
89
103
|
"node": ">=22.13"
|
|
@@ -91,5 +105,6 @@
|
|
|
91
105
|
"publishConfig": {
|
|
92
106
|
"access": "public"
|
|
93
107
|
},
|
|
108
|
+
"//peerDependencies": "@theia/core stays at 1.70 here, matching the sibling Theia packages, even though the connection-resilience bindings need 1.71: Theia only began binding `SocketWriteBuffer` then, and before that each connection built one privately, so there is no binding to rebind. Rather than split the package's floor for one feature, `bindConnectionResilience` probes for that binding and warns instead of installing when it is absent — a capability check rather than a version parse, so it answers about the container in front of it. Everything else the feature touches exists at 1.70, and the emitted declarations deliberately name no type that 1.70 lacks, so the package still compiles there. Verified by unpacking 1.70, 1.71 and 1.72, not inferred from a changelog. `vscode-jsonrpc` is EXACT because it is one link of an atomic chain: `vscode-languageserver-protocol` depends on it at exactly 9.0.1, so any other value is a second physical copy, and this wire stack breaks on copy identity.",
|
|
94
109
|
"//prepack": "The publish guard, and it deliberately is NOT a `prepare`: npm runs a workspace `prepare` BEFORE the root `postinstall` that applies patches/vscode-jsonrpc+9.0.1.patch, so building there fails on a cold clone and npm rolls the entire install back. `prepack` runs only when a tarball is made (`npm pack`, `npm publish`) and never on install, so it cannot break the install it has no business touching. It FAILS rather than rebuilds, because the rebuild is exactly the part that ordering defeats. What it defends against: `files` lists `lib`, `lib` is gitignored, and a `files` entry matching nothing is skipped SILENTLY — so `npm publish` from an unbuilt tree emits a tarball of `src` and nothing else, with no error."
|
|
95
110
|
}
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
import { AbstractLogger, DefaultTracer, type LogLevel, type MemoryReader, SystemClock } from '@hydranium/protocol';
|
|
11
11
|
import { injectable, type interfaces, unmanaged, inject } from '@theia/core/shared/inversify';
|
|
12
12
|
import { type OutputChannel, OutputChannelManager } from '@theia/output/lib/browser/output-channel';
|
|
13
|
+
import { Clock } from '../common/clock';
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
16
|
* Configuration for a {@link ChannelLogger}, supplied once at bind time via
|
|
@@ -94,9 +95,10 @@ const ChannelLoggerBase = Symbol('ChannelLoggerBase');
|
|
|
94
95
|
|
|
95
96
|
/**
|
|
96
97
|
* Inversify token for the browser `Tracer` — a {@link DefaultTracer} over
|
|
97
|
-
* the {@link ChannelLogger} (emit sink) +
|
|
98
|
-
*
|
|
99
|
-
*
|
|
98
|
+
* the {@link ChannelLogger} (emit sink) + the container's {@link Clock}, or a
|
|
99
|
+
* `SystemClock` when it binds none, + a browser heap reader. The browser head
|
|
100
|
+
* has no Langium `services.Tracer` slot, so this is how frontend services that
|
|
101
|
+
* time obtain a tracer: `@inject(ChannelTracer)`.
|
|
100
102
|
* Bound by {@link bindChannelLogger}.
|
|
101
103
|
*/
|
|
102
104
|
export const ChannelTracer = Symbol('ChannelTracer');
|
|
@@ -134,7 +136,10 @@ export function bindChannelLogger(bind: interfaces.Bind, options: ChannelLoggerO
|
|
|
134
136
|
return parentName ? base.for(parentName) : base;
|
|
135
137
|
});
|
|
136
138
|
bind(ChannelTracer)
|
|
137
|
-
.toDynamicValue(ctx =>
|
|
139
|
+
.toDynamicValue(ctx => {
|
|
140
|
+
const clock = ctx.container.isBound(Clock) ? ctx.container.get<Clock>(Clock) : new SystemClock();
|
|
141
|
+
return new DefaultTracer(ctx.container.get<ChannelLogger>(ChannelLoggerBase), clock, readBrowserMemory);
|
|
142
|
+
})
|
|
138
143
|
.inSingletonScope();
|
|
139
144
|
}
|
|
140
145
|
|
|
@@ -0,0 +1,142 @@
|
|
|
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
|
+
|
|
10
|
+
import { MessageService, nls } from '@theia/core';
|
|
11
|
+
import { FrontendApplicationContribution } from '@theia/core/lib/browser/frontend-application-contribution';
|
|
12
|
+
import { ConnectionStatus, ConnectionStatusService } from '@theia/core/lib/browser/connection-status-service';
|
|
13
|
+
import { WebSocketConnectionSource } from '@theia/core/lib/browser/messaging/ws-connection-source';
|
|
14
|
+
import { inject, injectable, type interfaces } from '@theia/core/shared/inversify';
|
|
15
|
+
import { type ConnectionBufferOverflow } from '../common/framed-socket-write-buffer';
|
|
16
|
+
import { ChannelLogger } from './channel-logger';
|
|
17
|
+
import { SessionAwareConnectionSource } from './session-aware-connection-source';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Records the browser side of the websocket lifecycle into the adopter's Output
|
|
21
|
+
* channel, and tells the user the one thing they cannot recover from on their
|
|
22
|
+
* own.
|
|
23
|
+
*
|
|
24
|
+
* Theia reports an outage only as an "Offline" status-bar item, which cannot
|
|
25
|
+
* distinguish a plain network drop from the server having stopped answering on a
|
|
26
|
+
* socket that is still up. The latter is what a connection defect looks like
|
|
27
|
+
* from here, so the two are logged differently — that distinction is what says
|
|
28
|
+
* whether reopening an editor helps or only a reload does.
|
|
29
|
+
*
|
|
30
|
+
* Purely observational apart from the overflow message: nothing here changes how
|
|
31
|
+
* the connection behaves.
|
|
32
|
+
*/
|
|
33
|
+
@injectable()
|
|
34
|
+
export class ConnectionDiagnosticsContribution implements FrontendApplicationContribution {
|
|
35
|
+
@inject(WebSocketConnectionSource) protected readonly connectionSource: WebSocketConnectionSource;
|
|
36
|
+
@inject(ConnectionStatusService) protected readonly connectionStatus: ConnectionStatusService;
|
|
37
|
+
@inject(ChannelLogger) protected readonly logger: ChannelLogger;
|
|
38
|
+
@inject(MessageService) protected readonly messageService: MessageService;
|
|
39
|
+
|
|
40
|
+
/** Main channels created so far; more than one means the server did not recognise this frontend. */
|
|
41
|
+
protected channelCount = 0;
|
|
42
|
+
protected socketClosedAt?: number;
|
|
43
|
+
protected offlineAt?: number;
|
|
44
|
+
|
|
45
|
+
initialize(): void {
|
|
46
|
+
this.connectionSource.onSocketDidOpen(() => this.handleSocketOpen());
|
|
47
|
+
this.connectionSource.onSocketDidClose(() => this.handleSocketClose());
|
|
48
|
+
this.connectionSource.onConnectionDidOpen(() => this.handleChannelOpen());
|
|
49
|
+
this.connectionStatus.onStatusChange(status => this.handleStatusChange(status));
|
|
50
|
+
if (this.connectionSource instanceof SessionAwareConnectionSource) {
|
|
51
|
+
this.connectionSource.onBufferOverflow(overflow => this.handleBufferOverflow(overflow));
|
|
52
|
+
}
|
|
53
|
+
// The socket is opened by the preloader, before this contribution exists, so the first
|
|
54
|
+
// `onSocketDidOpen` has already fired; state the current situation instead.
|
|
55
|
+
this.logger.info(`diagnostics active; socket ${this.socketId()}, backend ${this.statusName(this.connectionStatus.currentStatus)}`);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
protected handleSocketOpen(): void {
|
|
59
|
+
const downFor = this.socketClosedAt === undefined ? '' : ` after ${Date.now() - this.socketClosedAt} ms down`;
|
|
60
|
+
this.socketClosedAt = undefined;
|
|
61
|
+
this.logger.info(`websocket connected: socket ${this.socketId()}${downFor}`);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
protected handleSocketClose(): void {
|
|
65
|
+
this.socketClosedAt = Date.now();
|
|
66
|
+
this.logger.info(`websocket disconnected: socket ${this.socketId()}; outgoing messages are buffered until it returns`);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* A second channel means the reconnect was refused and the session discarded.
|
|
71
|
+
* Only reachable with `reloadOnReconnect` off — with it on, Theia reloads the
|
|
72
|
+
* page instead of opening another channel.
|
|
73
|
+
*/
|
|
74
|
+
protected handleChannelOpen(): void {
|
|
75
|
+
this.channelCount++;
|
|
76
|
+
if (this.channelCount === 1) {
|
|
77
|
+
this.logger.info(`initial channel opened on socket ${this.socketId()}`);
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
this.logger.warn(
|
|
81
|
+
`new channel #${this.channelCount} on socket ${this.socketId()}: the backend did not recognise this frontend, ` +
|
|
82
|
+
'so its session was discarded and every pending request rejected'
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
protected handleStatusChange(status: ConnectionStatus): void {
|
|
87
|
+
if (status === ConnectionStatus.ONLINE) {
|
|
88
|
+
const offlineFor = this.offlineAt === undefined ? '' : ` after ${Date.now() - this.offlineAt} ms`;
|
|
89
|
+
this.offlineAt = undefined;
|
|
90
|
+
this.logger.info(`backend reachable again${offlineFor}`);
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
this.offlineAt = Date.now();
|
|
94
|
+
const socket = this.connectionSource.socket;
|
|
95
|
+
if (socket?.connected) {
|
|
96
|
+
this.logger.warn(
|
|
97
|
+
`backend stopped answering while socket ${socket.id} is still connected: nothing this session sends will ` +
|
|
98
|
+
'arrive, and socket.io will not reconnect on its own. Reload the page to recover.'
|
|
99
|
+
);
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
this.logger.info(`backend unreachable; websocket is disconnected (socket ${this.socketId()})`);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* The outage outlasted what the buffer can hold, so changes made from here on
|
|
107
|
+
* are being thrown away rather than queued. Reconnecting resumes sending but
|
|
108
|
+
* cannot bring those back, which leaves the editor disagreeing with the
|
|
109
|
+
* server — and without a message the user would see nothing but an editor
|
|
110
|
+
* that has quietly stopped saving, so say it plainly.
|
|
111
|
+
*/
|
|
112
|
+
protected handleBufferOverflow(overflow: ConnectionBufferOverflow): void {
|
|
113
|
+
this.logger.error(`buffer full at ${overflow.maxBytes} bytes holding ${overflow.messages} message(s)`);
|
|
114
|
+
this.messageService.error(
|
|
115
|
+
nls.localize(
|
|
116
|
+
'hydranium/connection/offlineLimitReached',
|
|
117
|
+
'Disconnected for too long: recent changes were not sent. Reload the page before continuing.'
|
|
118
|
+
)
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
protected socketId(): string {
|
|
123
|
+
return this.connectionSource.socket?.id ?? WebSocketConnectionSource.NO_CONNECTION;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
protected statusName(status: ConnectionStatus): string {
|
|
127
|
+
return status === ConnectionStatus.ONLINE ? 'online' : 'offline';
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Bind {@link ConnectionDiagnosticsContribution} as a `FrontendApplicationContribution`.
|
|
133
|
+
*
|
|
134
|
+
* Needs a {@link ChannelLogger} binding, so call it from a module that has also
|
|
135
|
+
* called `bindChannelLogger`. Unlike `bindConnectionResilience` this belongs in a
|
|
136
|
+
* normal frontend module: it only observes, so it has no reason to run during
|
|
137
|
+
* preload, and `MessageService` is not available that early.
|
|
138
|
+
*/
|
|
139
|
+
export function bindConnectionDiagnostics(bind: interfaces.Bind): void {
|
|
140
|
+
bind(ConnectionDiagnosticsContribution).toSelf().inSingletonScope();
|
|
141
|
+
bind(FrontendApplicationContribution).toService(ConnectionDiagnosticsContribution);
|
|
142
|
+
}
|