@rest-vir/run-service 1.4.0 → 1.5.0
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.
|
@@ -15,6 +15,19 @@ export async function handleWebSocketRequest({ attachId, request, implementedWeb
|
|
|
15
15
|
const restVirContext = request.restVirContext?.[attachId];
|
|
16
16
|
assert.isDefined(restVirContext, 'restVirContext is not defined');
|
|
17
17
|
const webSocket = overwriteWebSocketMethods(implementedWebSocket, wsWebSocket, WebSocketLocation.OnHost);
|
|
18
|
+
/**
|
|
19
|
+
* `Duplexify`-based sockets (used by `@fastify/websocket`'s `injectWS` for testing) don't emit
|
|
20
|
+
* `'close'` after `end()` like real TCP sockets do. The `ws` library relies on the socket
|
|
21
|
+
* `'close'` event to fire `emitClose()` and complete the close handshake. Destroying the socket
|
|
22
|
+
* when it finishes writing triggers `'close'` promptly. For real TCP sockets this is
|
|
23
|
+
* effectively a no-op since they close naturally after the FIN handshake.
|
|
24
|
+
*/
|
|
25
|
+
const rawSocket = wsWebSocket._socket;
|
|
26
|
+
rawSocket?.on('finish', () => {
|
|
27
|
+
if (!rawSocket.destroyed) {
|
|
28
|
+
rawSocket.destroy();
|
|
29
|
+
}
|
|
30
|
+
});
|
|
18
31
|
const webSocketCallbackParams = {
|
|
19
32
|
context: restVirContext.context,
|
|
20
33
|
headers: request.headers,
|
|
@@ -188,6 +188,27 @@ export async function testExistingServer(server, service, options = {}) {
|
|
|
188
188
|
}
|
|
189
189
|
: {}))
|
|
190
190
|
: new WebSocket(webSocketUrl, protocols);
|
|
191
|
+
if (webSocketOrigin == undefined) {
|
|
192
|
+
/**
|
|
193
|
+
* `injectWS` creates a `ws` WebSocket with `_closeTimeout = undefined`.
|
|
194
|
+
* `setTimeout(fn, undefined)` fires immediately (0ms), which destroys the
|
|
195
|
+
* socket before the close frame can be sent, preventing the server-side close
|
|
196
|
+
* event from firing. Set a reasonable fallback timeout.
|
|
197
|
+
*
|
|
198
|
+
* Additionally, `injectWS` uses `Duplexify` streams which don't emit `'close'`
|
|
199
|
+
* after `end()` like real TCP sockets do. The `ws` library relies on the socket
|
|
200
|
+
* `'close'` event to complete the close handshake. Destroying the socket when
|
|
201
|
+
* it finishes writing triggers `'close'` promptly instead of waiting for the
|
|
202
|
+
* full close timeout.
|
|
203
|
+
*/
|
|
204
|
+
const wsInternal = webSocket;
|
|
205
|
+
wsInternal._closeTimeout = 5000;
|
|
206
|
+
wsInternal._socket?.on('finish', () => {
|
|
207
|
+
if (!wsInternal._socket?.destroyed) {
|
|
208
|
+
wsInternal._socket?.destroy();
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
}
|
|
191
212
|
const finalized = await finalizeWebSocket(webSocketDefinition, webSocket, listeners, WebSocketLocation.OnClient);
|
|
192
213
|
if (webSocketOrigin == undefined) {
|
|
193
214
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rest-vir/run-service",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "Run a service defined by @rest-vir/define-service and implemented by @rest-vir/implement-service.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"rest",
|
|
@@ -39,31 +39,31 @@
|
|
|
39
39
|
"test:update": "npm test update"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@augment-vir/assert": "^31.
|
|
43
|
-
"@augment-vir/common": "^31.
|
|
44
|
-
"@augment-vir/node": "^31.
|
|
42
|
+
"@augment-vir/assert": "^31.59.1",
|
|
43
|
+
"@augment-vir/common": "^31.59.1",
|
|
44
|
+
"@augment-vir/node": "^31.59.1",
|
|
45
45
|
"@fastify/compress": "^8.3.1",
|
|
46
46
|
"@fastify/websocket": "^11.2.0",
|
|
47
|
-
"@rest-vir/define-service": "^1.
|
|
48
|
-
"@rest-vir/implement-service": "^1.
|
|
47
|
+
"@rest-vir/define-service": "^1.5.0",
|
|
48
|
+
"@rest-vir/implement-service": "^1.5.0",
|
|
49
49
|
"cluster-vir": "^1.0.1",
|
|
50
50
|
"date-vir": "^8.1.0",
|
|
51
|
-
"fastify": "^5.
|
|
51
|
+
"fastify": "^5.7.4",
|
|
52
52
|
"light-my-request": "^6.6.0",
|
|
53
53
|
"portfinder": "^1.0.38",
|
|
54
|
-
"type-fest": "^5.3
|
|
54
|
+
"type-fest": "^5.4.3",
|
|
55
55
|
"url-vir": "^2.1.7"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
|
-
"@augment-vir/test": "^31.
|
|
59
|
-
"@fastify/multipart": "^9.
|
|
58
|
+
"@augment-vir/test": "^31.59.1",
|
|
59
|
+
"@fastify/multipart": "^9.4.0",
|
|
60
60
|
"@types/connect": "^3.4.38",
|
|
61
|
-
"@types/node": "^25.0
|
|
61
|
+
"@types/node": "^25.2.0",
|
|
62
62
|
"@types/ws": "^8.18.1",
|
|
63
63
|
"c8": "^10.1.3",
|
|
64
64
|
"istanbul-smart-text-reporter": "^1.1.5",
|
|
65
65
|
"markdown-code-example-inserter": "^3.0.3",
|
|
66
|
-
"object-shape-tester": "^6.
|
|
66
|
+
"object-shape-tester": "^6.11.0"
|
|
67
67
|
},
|
|
68
68
|
"peerDependencies": {
|
|
69
69
|
"@augment-vir/test": ">=30",
|