@replit/river 0.200.0-rc.2 → 0.200.0-rc.4
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 +21 -20
- package/dist/chunk-2BF4VMUZ.js +50 -0
- package/dist/chunk-2BF4VMUZ.js.map +1 -0
- package/dist/chunk-BZQQXMVF.js +401 -0
- package/dist/chunk-BZQQXMVF.js.map +1 -0
- package/dist/{chunk-4VNY34QG.js → chunk-F7Z2QQRL.js} +24 -18
- package/dist/chunk-F7Z2QQRL.js.map +1 -0
- package/dist/chunk-IMFMNIEO.js +384 -0
- package/dist/chunk-IMFMNIEO.js.map +1 -0
- package/dist/chunk-RDGHFHXN.js +658 -0
- package/dist/chunk-RDGHFHXN.js.map +1 -0
- package/dist/chunk-SI4YHBTI.js +277 -0
- package/dist/chunk-SI4YHBTI.js.map +1 -0
- package/dist/{chunk-7CKIN3JT.js → chunk-SIRRYRLQ.js} +73 -490
- package/dist/chunk-SIRRYRLQ.js.map +1 -0
- package/dist/{chunk-S5RL45KH.js → chunk-V57VWV5S.js} +80 -44
- package/dist/chunk-V57VWV5S.js.map +1 -0
- package/dist/{chunk-QMM35C3H.js → chunk-VXYHC666.js} +1 -1
- package/dist/chunk-VXYHC666.js.map +1 -0
- package/dist/client-f56a6da3.d.ts +49 -0
- package/dist/{connection-f900e390.d.ts → connection-11991b13.d.ts} +1 -5
- package/dist/connection-6031a354.d.ts +11 -0
- package/dist/context-73df8978.d.ts +528 -0
- package/dist/logging/index.cjs.map +1 -1
- package/dist/logging/index.d.cts +1 -1
- package/dist/logging/index.d.ts +1 -1
- package/dist/logging/index.js +1 -1
- package/dist/{index-10ebd26a.d.ts → message-fd349b27.d.ts} +31 -31
- package/dist/router/index.cjs +125 -502
- package/dist/router/index.cjs.map +1 -1
- package/dist/router/index.d.cts +11 -46
- package/dist/router/index.d.ts +11 -46
- package/dist/router/index.js +2 -4
- package/dist/server-9f31d98f.d.ts +42 -0
- package/dist/{services-970f97bb.d.ts → services-c67758fc.d.ts} +5 -602
- package/dist/transport/impls/uds/client.cjs +1247 -1238
- package/dist/transport/impls/uds/client.cjs.map +1 -1
- package/dist/transport/impls/uds/client.d.cts +4 -3
- package/dist/transport/impls/uds/client.d.ts +4 -3
- package/dist/transport/impls/uds/client.js +7 -13
- package/dist/transport/impls/uds/client.js.map +1 -1
- package/dist/transport/impls/uds/server.cjs +1311 -1170
- package/dist/transport/impls/uds/server.cjs.map +1 -1
- package/dist/transport/impls/uds/server.d.cts +4 -4
- package/dist/transport/impls/uds/server.d.ts +4 -4
- package/dist/transport/impls/uds/server.js +6 -6
- package/dist/transport/impls/ws/client.cjs +988 -987
- package/dist/transport/impls/ws/client.cjs.map +1 -1
- package/dist/transport/impls/ws/client.d.cts +6 -5
- package/dist/transport/impls/ws/client.d.ts +6 -5
- package/dist/transport/impls/ws/client.js +6 -7
- package/dist/transport/impls/ws/client.js.map +1 -1
- package/dist/transport/impls/ws/server.cjs +1192 -1066
- package/dist/transport/impls/ws/server.cjs.map +1 -1
- package/dist/transport/impls/ws/server.d.cts +4 -4
- package/dist/transport/impls/ws/server.d.ts +4 -4
- package/dist/transport/impls/ws/server.js +6 -6
- package/dist/transport/index.cjs +1446 -1380
- package/dist/transport/index.cjs.map +1 -1
- package/dist/transport/index.d.cts +4 -26
- package/dist/transport/index.d.ts +4 -26
- package/dist/transport/index.js +9 -9
- package/dist/util/testHelpers.cjs +746 -303
- package/dist/util/testHelpers.cjs.map +1 -1
- package/dist/util/testHelpers.d.cts +9 -4
- package/dist/util/testHelpers.d.ts +9 -4
- package/dist/util/testHelpers.js +36 -10
- package/dist/util/testHelpers.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-47TFNAY2.js +0 -476
- package/dist/chunk-47TFNAY2.js.map +0 -1
- package/dist/chunk-4VNY34QG.js.map +0 -1
- package/dist/chunk-7CKIN3JT.js.map +0 -1
- package/dist/chunk-CZP4LK3F.js +0 -335
- package/dist/chunk-CZP4LK3F.js.map +0 -1
- package/dist/chunk-DJCW3SKT.js +0 -59
- package/dist/chunk-DJCW3SKT.js.map +0 -1
- package/dist/chunk-NQWDT6GS.js +0 -347
- package/dist/chunk-NQWDT6GS.js.map +0 -1
- package/dist/chunk-ONUXWVRC.js +0 -492
- package/dist/chunk-ONUXWVRC.js.map +0 -1
- package/dist/chunk-QMM35C3H.js.map +0 -1
- package/dist/chunk-S5RL45KH.js.map +0 -1
- package/dist/connection-3f117047.d.ts +0 -17
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# River
|
|
2
2
|
|
|
3
|
-
⚠️ Not production ready, while Replit is using parts of
|
|
3
|
+
⚠️ Not production ready, while Replit is using parts of River in production, we are still going through rapid breaking changes. First production ready version will be `1.x.x` ⚠️
|
|
4
4
|
|
|
5
5
|
River allows multiple clients to connect to and make remote procedure calls to a remote server as if they were local procedures.
|
|
6
6
|
|
|
@@ -80,7 +80,7 @@ Before proceeding, ensure you have TypeScript 5 installed and configured appropr
|
|
|
80
80
|
First, we create a service using `ServiceSchema`:
|
|
81
81
|
|
|
82
82
|
```ts
|
|
83
|
-
import {
|
|
83
|
+
import { ServiceSchema, Procedure, Ok } from '@replit/river';
|
|
84
84
|
import { Type } from '@sinclair/typebox';
|
|
85
85
|
|
|
86
86
|
export const ExampleService = ServiceSchema.define(
|
|
@@ -134,17 +134,17 @@ In another file for the client (to create a separate entrypoint),
|
|
|
134
134
|
```ts
|
|
135
135
|
import { WebSocketClientTransport } from '@replit/river/transport/ws/client';
|
|
136
136
|
import { createClient } from '@replit/river';
|
|
137
|
-
import
|
|
137
|
+
import { WebSocket } from 'ws';
|
|
138
138
|
|
|
139
139
|
const transport = new WebSocketClientTransport(
|
|
140
140
|
async () => new WebSocket('ws://localhost:3000'),
|
|
141
141
|
'my-client-id',
|
|
142
142
|
);
|
|
143
143
|
|
|
144
|
-
const client = createClient
|
|
144
|
+
const client = createClient(
|
|
145
145
|
transport,
|
|
146
146
|
'SERVER', // transport id of the server in the previous step
|
|
147
|
-
true, // whether to eagerly connect to the server on creation (optional argument)
|
|
147
|
+
{ eagerlyConnect: true }, // whether to eagerly connect to the server on creation (optional argument)
|
|
148
148
|
);
|
|
149
149
|
|
|
150
150
|
// we get full type safety on `client`
|
|
@@ -157,15 +157,6 @@ if (result.ok) {
|
|
|
157
157
|
}
|
|
158
158
|
```
|
|
159
159
|
|
|
160
|
-
You can then access the `ParsedMetadata` in your procedure handlers:
|
|
161
|
-
|
|
162
|
-
```ts
|
|
163
|
-
async handler(ctx, ...args) {
|
|
164
|
-
// this contains the parsed metadata
|
|
165
|
-
console.log(ctx.metadata)
|
|
166
|
-
}
|
|
167
|
-
```
|
|
168
|
-
|
|
169
160
|
### Logging
|
|
170
161
|
|
|
171
162
|
To add logging, you can bind a logging function to a transport.
|
|
@@ -192,12 +183,12 @@ River defines two types of reconnects:
|
|
|
192
183
|
1. **Transparent reconnects:** These occur when the connection is temporarily lost and reestablished without losing any messages. From the application's perspective, this process is seamless and does not disrupt ongoing operations.
|
|
193
184
|
2. **Hard reconnect:** This occurs when all server state is lost, requiring the client to reinitialize anything stateful (e.g. subscriptions).
|
|
194
185
|
|
|
195
|
-
|
|
186
|
+
Hard reconnects are signaled via `sessionStatus` events.
|
|
196
187
|
|
|
197
188
|
If your application is stateful on either the server or the client, the service consumer _should_ wrap all the client-side setup with `transport.addEventListener('sessionStatus', (evt) => ...)` to do appropriate setup and teardown.
|
|
198
189
|
|
|
199
190
|
```ts
|
|
200
|
-
transport.addEventListener('
|
|
191
|
+
transport.addEventListener('sessionStatus', (evt) => {
|
|
201
192
|
if (evt.status === 'connect') {
|
|
202
193
|
// do something
|
|
203
194
|
} else if (evt.status === 'disconnect') {
|
|
@@ -205,11 +196,12 @@ transport.addEventListener('connectionStatus', (evt) => {
|
|
|
205
196
|
}
|
|
206
197
|
});
|
|
207
198
|
|
|
208
|
-
|
|
209
|
-
|
|
199
|
+
// or, listen for specific session states
|
|
200
|
+
transport.addEventListener('sessionTransition', (evt) => {
|
|
201
|
+
if (evt.state === SessionState.Connected) {
|
|
202
|
+
// switch on various transition states
|
|
203
|
+
} else if (evt.state === SessionState.NoConnection) {
|
|
210
204
|
// do something
|
|
211
|
-
} else if (evt.status === 'disconnect') {
|
|
212
|
-
// do something else
|
|
213
205
|
}
|
|
214
206
|
});
|
|
215
207
|
```
|
|
@@ -253,6 +245,15 @@ createServer(new MockServerTransport('SERVER'), services, {
|
|
|
253
245
|
});
|
|
254
246
|
```
|
|
255
247
|
|
|
248
|
+
You can then access the `ParsedMetadata` in your procedure handlers:
|
|
249
|
+
|
|
250
|
+
```ts
|
|
251
|
+
async handler(ctx, ...args) {
|
|
252
|
+
// this contains the parsed metadata
|
|
253
|
+
console.log(ctx.metadata)
|
|
254
|
+
}
|
|
255
|
+
```
|
|
256
|
+
|
|
256
257
|
### Further examples
|
|
257
258
|
|
|
258
259
|
We've also provided an end-to-end testing environment using `Next.js`, and a simple backend connected with the WebSocket transport that you can [play with on Replit](https://replit.com/@jzhao-replit/riverbed).
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Connection
|
|
3
|
+
} from "./chunk-SI4YHBTI.js";
|
|
4
|
+
|
|
5
|
+
// transport/impls/ws/connection.ts
|
|
6
|
+
var WebSocketConnection = class extends Connection {
|
|
7
|
+
ws;
|
|
8
|
+
constructor(ws) {
|
|
9
|
+
super();
|
|
10
|
+
this.ws = ws;
|
|
11
|
+
this.ws.binaryType = "arraybuffer";
|
|
12
|
+
let didError = false;
|
|
13
|
+
this.ws.onerror = () => {
|
|
14
|
+
didError = true;
|
|
15
|
+
};
|
|
16
|
+
this.ws.onclose = ({ code, reason }) => {
|
|
17
|
+
if (didError) {
|
|
18
|
+
const err = new Error(
|
|
19
|
+
`websocket closed with code and reason: ${code} - ${reason}`
|
|
20
|
+
);
|
|
21
|
+
for (const cb of this.errorListeners) {
|
|
22
|
+
cb(err);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
for (const cb of this.closeListeners) {
|
|
26
|
+
cb();
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
this.ws.onmessage = (msg) => {
|
|
30
|
+
for (const cb of this.dataListeners) {
|
|
31
|
+
cb(msg.data);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
send(payload) {
|
|
36
|
+
if (this.ws.readyState !== this.ws.OPEN) {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
this.ws.send(payload);
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
close() {
|
|
43
|
+
this.ws.close();
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export {
|
|
48
|
+
WebSocketConnection
|
|
49
|
+
};
|
|
50
|
+
//# sourceMappingURL=chunk-2BF4VMUZ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../transport/impls/ws/connection.ts"],"sourcesContent":["import { Connection } from '../../connection';\nimport { WsLike } from './wslike';\n\nexport class WebSocketConnection extends Connection {\n ws: WsLike;\n\n constructor(ws: WsLike) {\n super();\n this.ws = ws;\n this.ws.binaryType = 'arraybuffer';\n\n // Websockets are kinda shitty, they emit error events with no\n // information other than it errored, so we have to do some extra\n // work to figure out what happened.\n let didError = false;\n this.ws.onerror = () => {\n didError = true;\n };\n\n this.ws.onclose = ({ code, reason }) => {\n if (didError) {\n const err = new Error(\n `websocket closed with code and reason: ${code} - ${reason}`,\n );\n\n for (const cb of this.errorListeners) {\n cb(err);\n }\n }\n\n for (const cb of this.closeListeners) {\n cb();\n }\n };\n\n this.ws.onmessage = (msg) => {\n for (const cb of this.dataListeners) {\n cb(msg.data as Uint8Array);\n }\n };\n }\n\n send(payload: Uint8Array) {\n if (this.ws.readyState !== this.ws.OPEN) {\n return false;\n }\n this.ws.send(payload);\n return true;\n }\n\n close() {\n this.ws.close();\n }\n}\n"],"mappings":";;;;;AAGO,IAAM,sBAAN,cAAkC,WAAW;AAAA,EAClD;AAAA,EAEA,YAAY,IAAY;AACtB,UAAM;AACN,SAAK,KAAK;AACV,SAAK,GAAG,aAAa;AAKrB,QAAI,WAAW;AACf,SAAK,GAAG,UAAU,MAAM;AACtB,iBAAW;AAAA,IACb;AAEA,SAAK,GAAG,UAAU,CAAC,EAAE,MAAM,OAAO,MAAM;AACtC,UAAI,UAAU;AACZ,cAAM,MAAM,IAAI;AAAA,UACd,0CAA0C,IAAI,MAAM,MAAM;AAAA,QAC5D;AAEA,mBAAW,MAAM,KAAK,gBAAgB;AACpC,aAAG,GAAG;AAAA,QACR;AAAA,MACF;AAEA,iBAAW,MAAM,KAAK,gBAAgB;AACpC,WAAG;AAAA,MACL;AAAA,IACF;AAEA,SAAK,GAAG,YAAY,CAAC,QAAQ;AAC3B,iBAAW,MAAM,KAAK,eAAe;AACnC,WAAG,IAAI,IAAkB;AAAA,MAC3B;AAAA,IACF;AAAA,EACF;AAAA,EAEA,KAAK,SAAqB;AACxB,QAAI,KAAK,GAAG,eAAe,KAAK,GAAG,MAAM;AACvC,aAAO;AAAA,IACT;AACA,SAAK,GAAG,KAAK,OAAO;AACpB,WAAO;AAAA,EACT;AAAA,EAEA,QAAQ;AACN,SAAK,GAAG,MAAM;AAAA,EAChB;AACF;","names":[]}
|
|
@@ -0,0 +1,401 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ProtocolError,
|
|
3
|
+
Transport
|
|
4
|
+
} from "./chunk-SI4YHBTI.js";
|
|
5
|
+
import {
|
|
6
|
+
SessionStateGraph,
|
|
7
|
+
defaultClientTransportOptions
|
|
8
|
+
} from "./chunk-RDGHFHXN.js";
|
|
9
|
+
import {
|
|
10
|
+
ControlMessageHandshakeResponseSchema,
|
|
11
|
+
HandshakeErrorRetriableResponseCodes,
|
|
12
|
+
coerceErrorString,
|
|
13
|
+
currentProtocolVersion,
|
|
14
|
+
getPropagationContext,
|
|
15
|
+
handshakeRequestMessage,
|
|
16
|
+
tracing_default
|
|
17
|
+
} from "./chunk-V57VWV5S.js";
|
|
18
|
+
|
|
19
|
+
// transport/client.ts
|
|
20
|
+
import { SpanStatusCode } from "@opentelemetry/api";
|
|
21
|
+
|
|
22
|
+
// transport/rateLimit.ts
|
|
23
|
+
var LeakyBucketRateLimit = class {
|
|
24
|
+
budgetConsumed;
|
|
25
|
+
intervalHandles;
|
|
26
|
+
options;
|
|
27
|
+
constructor(options) {
|
|
28
|
+
this.options = options;
|
|
29
|
+
this.budgetConsumed = /* @__PURE__ */ new Map();
|
|
30
|
+
this.intervalHandles = /* @__PURE__ */ new Map();
|
|
31
|
+
}
|
|
32
|
+
getBackoffMs(user) {
|
|
33
|
+
if (!this.budgetConsumed.has(user))
|
|
34
|
+
return 0;
|
|
35
|
+
const exponent = Math.max(0, this.getBudgetConsumed(user) - 1);
|
|
36
|
+
const jitter = Math.floor(Math.random() * this.options.maxJitterMs);
|
|
37
|
+
const backoffMs = Math.min(
|
|
38
|
+
this.options.baseIntervalMs * 2 ** exponent,
|
|
39
|
+
this.options.maxBackoffMs
|
|
40
|
+
);
|
|
41
|
+
return backoffMs + jitter;
|
|
42
|
+
}
|
|
43
|
+
get totalBudgetRestoreTime() {
|
|
44
|
+
return this.options.budgetRestoreIntervalMs * this.options.attemptBudgetCapacity;
|
|
45
|
+
}
|
|
46
|
+
consumeBudget(user) {
|
|
47
|
+
this.stopLeak(user);
|
|
48
|
+
this.budgetConsumed.set(user, this.getBudgetConsumed(user) + 1);
|
|
49
|
+
}
|
|
50
|
+
getBudgetConsumed(user) {
|
|
51
|
+
return this.budgetConsumed.get(user) ?? 0;
|
|
52
|
+
}
|
|
53
|
+
hasBudget(user) {
|
|
54
|
+
return this.getBudgetConsumed(user) < this.options.attemptBudgetCapacity;
|
|
55
|
+
}
|
|
56
|
+
startRestoringBudget(user) {
|
|
57
|
+
if (this.intervalHandles.has(user)) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
const restoreBudgetForUser = () => {
|
|
61
|
+
const currentBudget = this.budgetConsumed.get(user);
|
|
62
|
+
if (!currentBudget) {
|
|
63
|
+
this.stopLeak(user);
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
const newBudget = currentBudget - 1;
|
|
67
|
+
if (newBudget === 0) {
|
|
68
|
+
this.budgetConsumed.delete(user);
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
this.budgetConsumed.set(user, newBudget);
|
|
72
|
+
};
|
|
73
|
+
const intervalHandle = setInterval(
|
|
74
|
+
restoreBudgetForUser,
|
|
75
|
+
this.options.budgetRestoreIntervalMs
|
|
76
|
+
);
|
|
77
|
+
this.intervalHandles.set(user, intervalHandle);
|
|
78
|
+
}
|
|
79
|
+
stopLeak(user) {
|
|
80
|
+
if (!this.intervalHandles.has(user)) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
clearInterval(this.intervalHandles.get(user));
|
|
84
|
+
this.intervalHandles.delete(user);
|
|
85
|
+
}
|
|
86
|
+
close() {
|
|
87
|
+
for (const user of this.intervalHandles.keys()) {
|
|
88
|
+
this.stopLeak(user);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
// transport/client.ts
|
|
94
|
+
import { Value } from "@sinclair/typebox/value";
|
|
95
|
+
var ClientTransport = class extends Transport {
|
|
96
|
+
/**
|
|
97
|
+
* The options for this transport.
|
|
98
|
+
*/
|
|
99
|
+
options;
|
|
100
|
+
retryBudget;
|
|
101
|
+
/**
|
|
102
|
+
* A flag indicating whether the transport should automatically reconnect
|
|
103
|
+
* when a connection is dropped.
|
|
104
|
+
* Realistically, this should always be true for clients unless you are writing
|
|
105
|
+
* tests or a special case where you don't want to reconnect.
|
|
106
|
+
*/
|
|
107
|
+
reconnectOnConnectionDrop = true;
|
|
108
|
+
/**
|
|
109
|
+
* Optional handshake options for this client.
|
|
110
|
+
*/
|
|
111
|
+
handshakeExtensions;
|
|
112
|
+
constructor(clientId, providedOptions) {
|
|
113
|
+
super(clientId, providedOptions);
|
|
114
|
+
this.options = {
|
|
115
|
+
...defaultClientTransportOptions,
|
|
116
|
+
...providedOptions
|
|
117
|
+
};
|
|
118
|
+
this.retryBudget = new LeakyBucketRateLimit(this.options);
|
|
119
|
+
}
|
|
120
|
+
extendHandshake(options) {
|
|
121
|
+
this.handshakeExtensions = options;
|
|
122
|
+
}
|
|
123
|
+
tryReconnecting(to) {
|
|
124
|
+
if (this.reconnectOnConnectionDrop && this.getStatus() === "open") {
|
|
125
|
+
this.connect(to);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
send(to, msg) {
|
|
129
|
+
if (this.getStatus() === "closed") {
|
|
130
|
+
const err = "transport is closed, cant send";
|
|
131
|
+
this.log?.error(err, {
|
|
132
|
+
clientId: this.clientId,
|
|
133
|
+
transportMessage: msg,
|
|
134
|
+
tags: ["invariant-violation"]
|
|
135
|
+
});
|
|
136
|
+
throw new Error(err);
|
|
137
|
+
}
|
|
138
|
+
let session = this.sessions.get(to);
|
|
139
|
+
if (!session) {
|
|
140
|
+
session = this.createUnconnectedSession(to);
|
|
141
|
+
}
|
|
142
|
+
return session.send(msg);
|
|
143
|
+
}
|
|
144
|
+
createUnconnectedSession(to) {
|
|
145
|
+
const session = SessionStateGraph.entrypoints.NoConnection(
|
|
146
|
+
to,
|
|
147
|
+
this.clientId,
|
|
148
|
+
{
|
|
149
|
+
onSessionGracePeriodElapsed: () => {
|
|
150
|
+
this.onSessionGracePeriodElapsed(session);
|
|
151
|
+
}
|
|
152
|
+
},
|
|
153
|
+
this.options,
|
|
154
|
+
currentProtocolVersion,
|
|
155
|
+
this.log
|
|
156
|
+
);
|
|
157
|
+
this.updateSession(session);
|
|
158
|
+
return session;
|
|
159
|
+
}
|
|
160
|
+
// listeners
|
|
161
|
+
onConnectingFailed(session) {
|
|
162
|
+
const noConnectionSession = super.onConnectingFailed(session);
|
|
163
|
+
this.tryReconnecting(noConnectionSession.to);
|
|
164
|
+
return noConnectionSession;
|
|
165
|
+
}
|
|
166
|
+
onConnClosed(session) {
|
|
167
|
+
const noConnectionSession = super.onConnClosed(session);
|
|
168
|
+
this.tryReconnecting(noConnectionSession.to);
|
|
169
|
+
return noConnectionSession;
|
|
170
|
+
}
|
|
171
|
+
onConnectionEstablished(session, conn) {
|
|
172
|
+
const handshakingSession = SessionStateGraph.transition.ConnectingToHandshaking(session, conn, {
|
|
173
|
+
onConnectionErrored: (err) => {
|
|
174
|
+
const errStr = coerceErrorString(err);
|
|
175
|
+
this.log?.error(
|
|
176
|
+
`connection to ${handshakingSession.to} errored during handshake: ${errStr}`,
|
|
177
|
+
handshakingSession.loggingMetadata
|
|
178
|
+
);
|
|
179
|
+
},
|
|
180
|
+
onConnectionClosed: () => {
|
|
181
|
+
this.log?.warn(
|
|
182
|
+
`connection to ${handshakingSession.to} closed during handshake`,
|
|
183
|
+
handshakingSession.loggingMetadata
|
|
184
|
+
);
|
|
185
|
+
this.onConnClosed(handshakingSession);
|
|
186
|
+
},
|
|
187
|
+
onHandshake: (msg) => {
|
|
188
|
+
this.onHandshakeResponse(handshakingSession, msg);
|
|
189
|
+
},
|
|
190
|
+
onInvalidHandshake: (reason) => {
|
|
191
|
+
this.log?.error(
|
|
192
|
+
`invalid handshake: ${reason}`,
|
|
193
|
+
handshakingSession.loggingMetadata
|
|
194
|
+
);
|
|
195
|
+
this.deleteSession(session);
|
|
196
|
+
this.protocolError(ProtocolError.HandshakeFailed, reason);
|
|
197
|
+
},
|
|
198
|
+
onHandshakeTimeout: () => {
|
|
199
|
+
this.log?.error(
|
|
200
|
+
`connection to ${handshakingSession.to} timed out during handshake`,
|
|
201
|
+
handshakingSession.loggingMetadata
|
|
202
|
+
);
|
|
203
|
+
this.onConnClosed(handshakingSession);
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
this.updateSession(handshakingSession);
|
|
207
|
+
void this.sendHandshake(handshakingSession);
|
|
208
|
+
return handshakingSession;
|
|
209
|
+
}
|
|
210
|
+
rejectHandshakeResponse(session, reason, metadata) {
|
|
211
|
+
session.conn.telemetry?.span.setStatus({
|
|
212
|
+
code: SpanStatusCode.ERROR,
|
|
213
|
+
message: reason
|
|
214
|
+
});
|
|
215
|
+
this.log?.warn(reason, metadata);
|
|
216
|
+
this.deleteSession(session);
|
|
217
|
+
}
|
|
218
|
+
onHandshakeResponse(session, msg) {
|
|
219
|
+
if (!Value.Check(ControlMessageHandshakeResponseSchema, msg.payload)) {
|
|
220
|
+
const reason = `received invalid handshake response`;
|
|
221
|
+
this.rejectHandshakeResponse(session, reason, {
|
|
222
|
+
...session.loggingMetadata,
|
|
223
|
+
transportMessage: msg,
|
|
224
|
+
validationErrors: [
|
|
225
|
+
...Value.Errors(ControlMessageHandshakeResponseSchema, msg.payload)
|
|
226
|
+
]
|
|
227
|
+
});
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
if (!msg.payload.status.ok) {
|
|
231
|
+
const retriable = msg.payload.status.code ? Value.Check(
|
|
232
|
+
HandshakeErrorRetriableResponseCodes,
|
|
233
|
+
msg.payload.status.code
|
|
234
|
+
) : false;
|
|
235
|
+
const reason = `handshake failed: ${msg.payload.status.reason}`;
|
|
236
|
+
this.rejectHandshakeResponse(session, reason, {
|
|
237
|
+
...session.loggingMetadata,
|
|
238
|
+
transportMessage: msg
|
|
239
|
+
});
|
|
240
|
+
if (retriable) {
|
|
241
|
+
this.tryReconnecting(session.to);
|
|
242
|
+
} else {
|
|
243
|
+
this.deleteSession(session);
|
|
244
|
+
this.protocolError(ProtocolError.HandshakeFailed, reason);
|
|
245
|
+
}
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
if (msg.payload.status.sessionId !== session.id) {
|
|
249
|
+
const reason = `session id mismatch: expected ${session.id}, got ${msg.payload.status.sessionId}`;
|
|
250
|
+
this.rejectHandshakeResponse(session, reason, {
|
|
251
|
+
...session.loggingMetadata,
|
|
252
|
+
transportMessage: msg
|
|
253
|
+
});
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
this.log?.info(`handshake from ${msg.from} ok`, {
|
|
257
|
+
...session.loggingMetadata,
|
|
258
|
+
transportMessage: msg
|
|
259
|
+
});
|
|
260
|
+
const connectedSession = SessionStateGraph.transition.HandshakingToConnected(session, {
|
|
261
|
+
onConnectionErrored: (err) => {
|
|
262
|
+
const errStr = coerceErrorString(err);
|
|
263
|
+
this.log?.warn(
|
|
264
|
+
`connection to ${connectedSession.to} errored: ${errStr}`,
|
|
265
|
+
connectedSession.loggingMetadata
|
|
266
|
+
);
|
|
267
|
+
},
|
|
268
|
+
onConnectionClosed: () => {
|
|
269
|
+
this.log?.info(
|
|
270
|
+
`connection to ${connectedSession.to} closed`,
|
|
271
|
+
connectedSession.loggingMetadata
|
|
272
|
+
);
|
|
273
|
+
this.onConnClosed(connectedSession);
|
|
274
|
+
},
|
|
275
|
+
onMessage: (msg2) => this.handleMsg(msg2),
|
|
276
|
+
onInvalidMessage: (reason) => {
|
|
277
|
+
this.deleteSession(connectedSession);
|
|
278
|
+
this.protocolError(ProtocolError.MessageOrderingViolated, reason);
|
|
279
|
+
}
|
|
280
|
+
});
|
|
281
|
+
this.updateSession(connectedSession);
|
|
282
|
+
this.retryBudget.startRestoringBudget(connectedSession.to);
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Manually attempts to connect to a client.
|
|
286
|
+
* @param to The client ID of the node to connect to.
|
|
287
|
+
*/
|
|
288
|
+
connect(to) {
|
|
289
|
+
let session = this.sessions.get(to);
|
|
290
|
+
session ??= this.createUnconnectedSession(to);
|
|
291
|
+
if (session.state !== "NoConnection" /* NoConnection */) {
|
|
292
|
+
this.log?.debug(
|
|
293
|
+
`session to ${to} has state ${session.state}, skipping connect attempt`,
|
|
294
|
+
session.loggingMetadata
|
|
295
|
+
);
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
298
|
+
if (this.getStatus() !== "open") {
|
|
299
|
+
this.log?.info(
|
|
300
|
+
`transport state is no longer open, cancelling attempt to connect to ${to}`,
|
|
301
|
+
session.loggingMetadata
|
|
302
|
+
);
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
if (!this.retryBudget.hasBudget(to)) {
|
|
306
|
+
const budgetConsumed = this.retryBudget.getBudgetConsumed(to);
|
|
307
|
+
const errMsg = `tried to connect to ${to} but retry budget exceeded (more than ${budgetConsumed} attempts in the last ${this.retryBudget.totalBudgetRestoreTime}ms)`;
|
|
308
|
+
this.log?.error(errMsg, session.loggingMetadata);
|
|
309
|
+
this.protocolError(ProtocolError.RetriesExceeded, errMsg);
|
|
310
|
+
return;
|
|
311
|
+
}
|
|
312
|
+
let sleep = Promise.resolve();
|
|
313
|
+
const backoffMs = this.retryBudget.getBackoffMs(to);
|
|
314
|
+
if (backoffMs > 0) {
|
|
315
|
+
sleep = new Promise((resolve) => setTimeout(resolve, backoffMs));
|
|
316
|
+
}
|
|
317
|
+
this.log?.info(
|
|
318
|
+
`attempting connection to ${to} (${backoffMs}ms backoff)`,
|
|
319
|
+
session.loggingMetadata
|
|
320
|
+
);
|
|
321
|
+
this.retryBudget.consumeBudget(to);
|
|
322
|
+
const reconnectPromise = tracing_default.startActiveSpan("connect", async (span) => {
|
|
323
|
+
try {
|
|
324
|
+
span.addEvent("backoff", { backoffMs });
|
|
325
|
+
await sleep;
|
|
326
|
+
if (this.getStatus() !== "open") {
|
|
327
|
+
throw new Error("transport state is no longer open");
|
|
328
|
+
}
|
|
329
|
+
span.addEvent("connecting");
|
|
330
|
+
return await this.createNewOutgoingConnection(to);
|
|
331
|
+
} catch (err) {
|
|
332
|
+
const errStr = coerceErrorString(err);
|
|
333
|
+
span.recordException(errStr);
|
|
334
|
+
span.setStatus({ code: SpanStatusCode.ERROR });
|
|
335
|
+
throw err;
|
|
336
|
+
} finally {
|
|
337
|
+
span.end();
|
|
338
|
+
}
|
|
339
|
+
});
|
|
340
|
+
const connectingSession = SessionStateGraph.transition.NoConnectionToConnecting(
|
|
341
|
+
session,
|
|
342
|
+
reconnectPromise,
|
|
343
|
+
{
|
|
344
|
+
onConnectionEstablished: (conn) => {
|
|
345
|
+
this.log?.debug(
|
|
346
|
+
`connection to ${connectingSession.to} established`,
|
|
347
|
+
connectingSession.loggingMetadata
|
|
348
|
+
);
|
|
349
|
+
this.onConnectionEstablished(connectingSession, conn);
|
|
350
|
+
},
|
|
351
|
+
onConnectionFailed: (error) => {
|
|
352
|
+
const errStr = coerceErrorString(error);
|
|
353
|
+
this.log?.error(
|
|
354
|
+
`error connecting to ${connectingSession.to}: ${errStr}`,
|
|
355
|
+
connectingSession.loggingMetadata
|
|
356
|
+
);
|
|
357
|
+
this.onConnectingFailed(connectingSession);
|
|
358
|
+
},
|
|
359
|
+
onConnectionTimeout: () => {
|
|
360
|
+
this.log?.error(
|
|
361
|
+
`connection to ${connectingSession.to} timed out`,
|
|
362
|
+
connectingSession.loggingMetadata
|
|
363
|
+
);
|
|
364
|
+
this.onConnectingFailed(connectingSession);
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
);
|
|
368
|
+
this.updateSession(connectingSession);
|
|
369
|
+
}
|
|
370
|
+
async sendHandshake(session) {
|
|
371
|
+
let metadata = void 0;
|
|
372
|
+
if (this.handshakeExtensions) {
|
|
373
|
+
metadata = await this.handshakeExtensions.construct();
|
|
374
|
+
}
|
|
375
|
+
const requestMsg = handshakeRequestMessage({
|
|
376
|
+
from: this.clientId,
|
|
377
|
+
to: session.to,
|
|
378
|
+
sessionId: session.id,
|
|
379
|
+
expectedSessionState: {
|
|
380
|
+
nextExpectedSeq: session.ack,
|
|
381
|
+
nextSentSeq: session.nextSeq()
|
|
382
|
+
},
|
|
383
|
+
metadata,
|
|
384
|
+
tracing: getPropagationContext(session.telemetry.ctx)
|
|
385
|
+
});
|
|
386
|
+
this.log?.debug(`sending handshake request to ${session.to}`, {
|
|
387
|
+
...session.loggingMetadata,
|
|
388
|
+
transportMessage: requestMsg
|
|
389
|
+
});
|
|
390
|
+
session.sendHandshake(requestMsg);
|
|
391
|
+
}
|
|
392
|
+
close() {
|
|
393
|
+
this.retryBudget.close();
|
|
394
|
+
super.close();
|
|
395
|
+
}
|
|
396
|
+
};
|
|
397
|
+
|
|
398
|
+
export {
|
|
399
|
+
ClientTransport
|
|
400
|
+
};
|
|
401
|
+
//# sourceMappingURL=chunk-BZQQXMVF.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../transport/client.ts","../transport/rateLimit.ts"],"sourcesContent":["import { SpanStatusCode } from '@opentelemetry/api';\nimport { ClientHandshakeOptions } from '../router/handshake';\nimport {\n ControlMessageHandshakeResponseSchema,\n HandshakeErrorRetriableResponseCodes,\n OpaqueTransportMessage,\n PartialTransportMessage,\n TransportClientId,\n currentProtocolVersion,\n handshakeRequestMessage,\n} from './message';\nimport {\n ClientTransportOptions,\n ProvidedClientTransportOptions,\n defaultClientTransportOptions,\n} from './options';\nimport { LeakyBucketRateLimit } from './rateLimit';\nimport { Transport } from './transport';\nimport { coerceErrorString } from '../util/stringify';\nimport { ProtocolError } from './events';\nimport { Value } from '@sinclair/typebox/value';\nimport tracer, { getPropagationContext } from '../tracing';\nimport { Connection } from './connection';\nimport { MessageMetadata } from '../logging';\nimport { SessionConnecting } from './sessionStateMachine/SessionConnecting';\nimport { SessionHandshaking } from './sessionStateMachine/SessionHandshaking';\nimport { SessionConnected } from './sessionStateMachine/SessionConnected';\nimport { SessionStateGraph } from './sessionStateMachine/transitions';\nimport { SessionState } from './sessionStateMachine/common';\nimport { SessionNoConnection } from './sessionStateMachine/SessionNoConnection';\n\nexport abstract class ClientTransport<\n ConnType extends Connection,\n> extends Transport<ConnType> {\n /**\n * The options for this transport.\n */\n protected options: ClientTransportOptions;\n\n retryBudget: LeakyBucketRateLimit;\n\n /**\n * A flag indicating whether the transport should automatically reconnect\n * when a connection is dropped.\n * Realistically, this should always be true for clients unless you are writing\n * tests or a special case where you don't want to reconnect.\n */\n reconnectOnConnectionDrop = true;\n\n /**\n * Optional handshake options for this client.\n */\n handshakeExtensions?: ClientHandshakeOptions;\n\n constructor(\n clientId: TransportClientId,\n providedOptions?: ProvidedClientTransportOptions,\n ) {\n super(clientId, providedOptions);\n this.options = {\n ...defaultClientTransportOptions,\n ...providedOptions,\n };\n this.retryBudget = new LeakyBucketRateLimit(this.options);\n }\n\n extendHandshake(options: ClientHandshakeOptions) {\n this.handshakeExtensions = options;\n }\n\n /**\n * Abstract method that creates a new {@link Connection} object.\n * This should call {@link handleConnection} when the connection is created.\n * The downstream client implementation needs to implement this.\n *\n * @param to The client ID of the node to connect to.\n * @returns The new connection object.\n */\n protected abstract createNewOutgoingConnection(\n to: TransportClientId,\n ): Promise<ConnType>;\n\n private tryReconnecting(to: string) {\n if (this.reconnectOnConnectionDrop && this.getStatus() === 'open') {\n this.connect(to);\n }\n }\n\n send(to: string, msg: PartialTransportMessage): string {\n if (this.getStatus() === 'closed') {\n const err = 'transport is closed, cant send';\n this.log?.error(err, {\n clientId: this.clientId,\n transportMessage: msg,\n tags: ['invariant-violation'],\n });\n\n throw new Error(err);\n }\n\n let session = this.sessions.get(to);\n if (!session) {\n session = this.createUnconnectedSession(to);\n }\n\n return session.send(msg);\n }\n\n private createUnconnectedSession(to: string): SessionNoConnection {\n const session = SessionStateGraph.entrypoints.NoConnection(\n to,\n this.clientId,\n {\n onSessionGracePeriodElapsed: () => {\n this.onSessionGracePeriodElapsed(session);\n },\n },\n this.options,\n currentProtocolVersion,\n this.log,\n );\n\n this.updateSession(session);\n return session;\n }\n\n // listeners\n protected onConnectingFailed(session: SessionConnecting<ConnType>) {\n const noConnectionSession = super.onConnectingFailed(session);\n this.tryReconnecting(noConnectionSession.to);\n return noConnectionSession;\n }\n\n protected onConnClosed(\n session: SessionHandshaking<ConnType> | SessionConnected<ConnType>,\n ) {\n const noConnectionSession = super.onConnClosed(session);\n this.tryReconnecting(noConnectionSession.to);\n return noConnectionSession;\n }\n\n protected onConnectionEstablished(\n session: SessionConnecting<ConnType>,\n conn: ConnType,\n ): SessionHandshaking<ConnType> {\n // transition to handshaking\n const handshakingSession =\n SessionStateGraph.transition.ConnectingToHandshaking(session, conn, {\n onConnectionErrored: (err) => {\n // just log, when we error we also emit close\n const errStr = coerceErrorString(err);\n this.log?.error(\n `connection to ${handshakingSession.to} errored during handshake: ${errStr}`,\n handshakingSession.loggingMetadata,\n );\n },\n onConnectionClosed: () => {\n this.log?.warn(\n `connection to ${handshakingSession.to} closed during handshake`,\n handshakingSession.loggingMetadata,\n );\n this.onConnClosed(handshakingSession);\n },\n onHandshake: (msg) => {\n this.onHandshakeResponse(handshakingSession, msg);\n },\n onInvalidHandshake: (reason) => {\n this.log?.error(\n `invalid handshake: ${reason}`,\n handshakingSession.loggingMetadata,\n );\n this.deleteSession(session);\n this.protocolError(ProtocolError.HandshakeFailed, reason);\n },\n onHandshakeTimeout: () => {\n this.log?.error(\n `connection to ${handshakingSession.to} timed out during handshake`,\n handshakingSession.loggingMetadata,\n );\n this.onConnClosed(handshakingSession);\n },\n });\n\n this.updateSession(handshakingSession);\n void this.sendHandshake(handshakingSession);\n return handshakingSession;\n }\n\n private rejectHandshakeResponse(\n session: SessionHandshaking<ConnType>,\n reason: string,\n metadata: MessageMetadata,\n ) {\n session.conn.telemetry?.span.setStatus({\n code: SpanStatusCode.ERROR,\n message: reason,\n });\n\n this.log?.warn(reason, metadata);\n this.deleteSession(session);\n }\n\n protected onHandshakeResponse(\n session: SessionHandshaking<ConnType>,\n msg: OpaqueTransportMessage,\n ) {\n // invariant: msg is a handshake response\n if (!Value.Check(ControlMessageHandshakeResponseSchema, msg.payload)) {\n const reason = `received invalid handshake response`;\n this.rejectHandshakeResponse(session, reason, {\n ...session.loggingMetadata,\n transportMessage: msg,\n validationErrors: [\n ...Value.Errors(ControlMessageHandshakeResponseSchema, msg.payload),\n ],\n });\n return;\n }\n\n // invariant: handshake response should be ok\n if (!msg.payload.status.ok) {\n // TODO: remove conditional check after we know code is always present\n const retriable = msg.payload.status.code\n ? Value.Check(\n HandshakeErrorRetriableResponseCodes,\n msg.payload.status.code,\n )\n : false;\n\n const reason = `handshake failed: ${msg.payload.status.reason}`;\n this.rejectHandshakeResponse(session, reason, {\n ...session.loggingMetadata,\n transportMessage: msg,\n });\n\n if (retriable) {\n this.tryReconnecting(session.to);\n } else {\n this.deleteSession(session);\n this.protocolError(ProtocolError.HandshakeFailed, reason);\n }\n\n return;\n }\n\n // invariant: session id should match between client + server\n if (msg.payload.status.sessionId !== session.id) {\n const reason = `session id mismatch: expected ${session.id}, got ${msg.payload.status.sessionId}`;\n this.rejectHandshakeResponse(session, reason, {\n ...session.loggingMetadata,\n transportMessage: msg,\n });\n return;\n }\n\n // transition to connected!\n this.log?.info(`handshake from ${msg.from} ok`, {\n ...session.loggingMetadata,\n transportMessage: msg,\n });\n\n const connectedSession =\n SessionStateGraph.transition.HandshakingToConnected(session, {\n onConnectionErrored: (err) => {\n // just log, when we error we also emit close\n const errStr = coerceErrorString(err);\n this.log?.warn(\n `connection to ${connectedSession.to} errored: ${errStr}`,\n connectedSession.loggingMetadata,\n );\n },\n onConnectionClosed: () => {\n this.log?.info(\n `connection to ${connectedSession.to} closed`,\n connectedSession.loggingMetadata,\n );\n this.onConnClosed(connectedSession);\n },\n onMessage: (msg) => this.handleMsg(msg),\n onInvalidMessage: (reason) => {\n this.deleteSession(connectedSession);\n this.protocolError(ProtocolError.MessageOrderingViolated, reason);\n },\n });\n\n this.updateSession(connectedSession);\n this.retryBudget.startRestoringBudget(connectedSession.to);\n }\n\n /**\n * Manually attempts to connect to a client.\n * @param to The client ID of the node to connect to.\n */\n connect(to: TransportClientId) {\n // create a new session if one does not exist\n let session = this.sessions.get(to);\n session ??= this.createUnconnectedSession(to);\n\n if (session.state !== SessionState.NoConnection) {\n // already trying to connect\n this.log?.debug(\n `session to ${to} has state ${session.state}, skipping connect attempt`,\n session.loggingMetadata,\n );\n return;\n }\n\n if (this.getStatus() !== 'open') {\n this.log?.info(\n `transport state is no longer open, cancelling attempt to connect to ${to}`,\n session.loggingMetadata,\n );\n return;\n }\n\n // check budget\n if (!this.retryBudget.hasBudget(to)) {\n const budgetConsumed = this.retryBudget.getBudgetConsumed(to);\n const errMsg = `tried to connect to ${to} but retry budget exceeded (more than ${budgetConsumed} attempts in the last ${this.retryBudget.totalBudgetRestoreTime}ms)`;\n this.log?.error(errMsg, session.loggingMetadata);\n this.protocolError(ProtocolError.RetriesExceeded, errMsg);\n return;\n }\n\n let sleep = Promise.resolve();\n const backoffMs = this.retryBudget.getBackoffMs(to);\n if (backoffMs > 0) {\n sleep = new Promise((resolve) => setTimeout(resolve, backoffMs));\n }\n\n this.log?.info(\n `attempting connection to ${to} (${backoffMs}ms backoff)`,\n session.loggingMetadata,\n );\n\n this.retryBudget.consumeBudget(to);\n const reconnectPromise = tracer.startActiveSpan('connect', async (span) => {\n try {\n span.addEvent('backoff', { backoffMs });\n await sleep;\n if (this.getStatus() !== 'open') {\n throw new Error('transport state is no longer open');\n }\n\n span.addEvent('connecting');\n return await this.createNewOutgoingConnection(to);\n } catch (err) {\n // rethrow the error so that the promise is rejected\n // as it was before we wrapped it in a span\n const errStr = coerceErrorString(err);\n span.recordException(errStr);\n span.setStatus({ code: SpanStatusCode.ERROR });\n throw err;\n } finally {\n span.end();\n }\n });\n\n const connectingSession =\n SessionStateGraph.transition.NoConnectionToConnecting(\n session,\n reconnectPromise,\n {\n onConnectionEstablished: (conn) => {\n this.log?.debug(\n `connection to ${connectingSession.to} established`,\n connectingSession.loggingMetadata,\n );\n\n // cast here because conn can't be narrowed to ConnType\n // in the callback due to variance rules\n this.onConnectionEstablished(connectingSession, conn as ConnType);\n },\n onConnectionFailed: (error: unknown) => {\n const errStr = coerceErrorString(error);\n this.log?.error(\n `error connecting to ${connectingSession.to}: ${errStr}`,\n connectingSession.loggingMetadata,\n );\n this.onConnectingFailed(connectingSession);\n },\n onConnectionTimeout: () => {\n this.log?.error(\n `connection to ${connectingSession.to} timed out`,\n connectingSession.loggingMetadata,\n );\n this.onConnectingFailed(connectingSession);\n },\n },\n );\n\n this.updateSession(connectingSession);\n }\n\n private async sendHandshake(session: SessionHandshaking<ConnType>) {\n let metadata: unknown = undefined;\n\n if (this.handshakeExtensions) {\n metadata = await this.handshakeExtensions.construct();\n }\n\n const requestMsg = handshakeRequestMessage({\n from: this.clientId,\n to: session.to,\n sessionId: session.id,\n expectedSessionState: {\n nextExpectedSeq: session.ack,\n nextSentSeq: session.nextSeq(),\n },\n metadata,\n tracing: getPropagationContext(session.telemetry.ctx),\n });\n\n this.log?.debug(`sending handshake request to ${session.to}`, {\n ...session.loggingMetadata,\n transportMessage: requestMsg,\n });\n\n session.sendHandshake(requestMsg);\n }\n\n close() {\n this.retryBudget.close();\n super.close();\n }\n}\n","import { TransportClientId } from './message';\n\n/**\n * Options to control the backoff and retry behavior of the client transport's connection behaviour.\n *\n * River implements exponential backoff with jitter to prevent flooding the server\n * when there's an issue with connection establishment.\n *\n * The backoff is calculated via the following:\n * backOff = min(jitter + {@link baseIntervalMs} * 2 ^ budget_consumed, {@link maxBackoffMs})\n *\n * We use a leaky bucket rate limit with a budget of {@link attemptBudgetCapacity} reconnection attempts.\n * Budget only starts to restore after a successful handshake at a rate of one budget per {@link budgetRestoreIntervalMs}.\n */\nexport interface ConnectionRetryOptions {\n /**\n * The base interval to wait before retrying a connection.\n */\n baseIntervalMs: number;\n\n /**\n * The maximum random jitter to add to the total backoff time.\n */\n maxJitterMs: number;\n\n /**\n * The maximum amount of time to wait before retrying a connection.\n * This does not include the jitter.\n */\n maxBackoffMs: number;\n\n /**\n * The max number of times to attempt a connection before a successful handshake.\n * This persists across connections but starts restoring budget after a successful handshake.\n * The restoration interval depends on {@link budgetRestoreIntervalMs}\n */\n attemptBudgetCapacity: number;\n\n /**\n * After a successful connection attempt, how long to wait before we restore a single budget.\n */\n budgetRestoreIntervalMs: number;\n}\n\nexport class LeakyBucketRateLimit {\n private budgetConsumed: Map<TransportClientId, number>;\n private intervalHandles: Map<\n TransportClientId,\n ReturnType<typeof setInterval>\n >;\n private readonly options: ConnectionRetryOptions;\n\n constructor(options: ConnectionRetryOptions) {\n this.options = options;\n this.budgetConsumed = new Map();\n this.intervalHandles = new Map();\n }\n\n getBackoffMs(user: TransportClientId) {\n if (!this.budgetConsumed.has(user)) return 0;\n\n const exponent = Math.max(0, this.getBudgetConsumed(user) - 1);\n const jitter = Math.floor(Math.random() * this.options.maxJitterMs);\n const backoffMs = Math.min(\n this.options.baseIntervalMs * 2 ** exponent,\n this.options.maxBackoffMs,\n );\n\n return backoffMs + jitter;\n }\n\n get totalBudgetRestoreTime() {\n return (\n this.options.budgetRestoreIntervalMs * this.options.attemptBudgetCapacity\n );\n }\n\n consumeBudget(user: TransportClientId) {\n // If we're consuming again, let's ensure that we're not leaking\n this.stopLeak(user);\n this.budgetConsumed.set(user, this.getBudgetConsumed(user) + 1);\n }\n\n getBudgetConsumed(user: TransportClientId) {\n return this.budgetConsumed.get(user) ?? 0;\n }\n\n hasBudget(user: TransportClientId) {\n return this.getBudgetConsumed(user) < this.options.attemptBudgetCapacity;\n }\n\n startRestoringBudget(user: TransportClientId) {\n if (this.intervalHandles.has(user)) {\n return;\n }\n\n const restoreBudgetForUser = () => {\n const currentBudget = this.budgetConsumed.get(user);\n if (!currentBudget) {\n this.stopLeak(user);\n return;\n }\n\n const newBudget = currentBudget - 1;\n if (newBudget === 0) {\n this.budgetConsumed.delete(user);\n return;\n }\n\n this.budgetConsumed.set(user, newBudget);\n };\n\n const intervalHandle = setInterval(\n restoreBudgetForUser,\n this.options.budgetRestoreIntervalMs,\n );\n\n this.intervalHandles.set(user, intervalHandle);\n }\n\n private stopLeak(user: TransportClientId) {\n if (!this.intervalHandles.has(user)) {\n return;\n }\n\n clearInterval(this.intervalHandles.get(user));\n this.intervalHandles.delete(user);\n }\n\n close() {\n for (const user of this.intervalHandles.keys()) {\n this.stopLeak(user);\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA,SAAS,sBAAsB;;;AC4CxB,IAAM,uBAAN,MAA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C;AAED,YAAQ,cAAc,UAAU;AAAA,EAClC;AAAA,EAEA,QAAQ;AACN,SAAK,YAAY,MAAM;AACvB,UAAM,MAAM;AAAA,EACd;AACF;","names":["msg"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Connection
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-SI4YHBTI.js";
|
|
4
4
|
|
|
5
5
|
// transport/transforms/messageFraming.ts
|
|
6
6
|
import { Transform } from "node:stream";
|
|
@@ -71,36 +71,42 @@ var UdsConnection = class extends Connection {
|
|
|
71
71
|
this.framer = MessageFramer.createFramedStream();
|
|
72
72
|
this.sock = sock;
|
|
73
73
|
this.input = sock.pipe(this.framer);
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
this.input.off("data", cb);
|
|
80
|
-
}
|
|
81
|
-
addCloseListener(cb) {
|
|
82
|
-
this.sock.on("close", cb);
|
|
83
|
-
}
|
|
84
|
-
addErrorListener(cb) {
|
|
74
|
+
this.sock.on("close", () => {
|
|
75
|
+
for (const cb of this.closeListeners) {
|
|
76
|
+
cb();
|
|
77
|
+
}
|
|
78
|
+
});
|
|
85
79
|
this.sock.on("error", (err) => {
|
|
86
80
|
if (err instanceof Error && "code" in err && err.code === "EPIPE") {
|
|
87
81
|
return;
|
|
88
82
|
}
|
|
89
|
-
cb
|
|
83
|
+
for (const cb of this.errorListeners) {
|
|
84
|
+
cb(err);
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
this.input.on("data", (msg) => {
|
|
88
|
+
for (const cb of this.dataListeners) {
|
|
89
|
+
cb(msg);
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
this.sock.on("end", () => {
|
|
93
|
+
this.sock.destroy();
|
|
90
94
|
});
|
|
91
95
|
}
|
|
92
96
|
send(payload) {
|
|
93
|
-
if (this.framer.destroyed || !this.sock.writable)
|
|
97
|
+
if (this.framer.destroyed || !this.sock.writable || this.sock.closed) {
|
|
94
98
|
return false;
|
|
95
|
-
|
|
99
|
+
}
|
|
100
|
+
this.sock.write(MessageFramer.write(payload));
|
|
101
|
+
return true;
|
|
96
102
|
}
|
|
97
103
|
close() {
|
|
98
|
-
this.sock.
|
|
99
|
-
this.framer.
|
|
104
|
+
this.sock.end();
|
|
105
|
+
this.framer.end();
|
|
100
106
|
}
|
|
101
107
|
};
|
|
102
108
|
|
|
103
109
|
export {
|
|
104
110
|
UdsConnection
|
|
105
111
|
};
|
|
106
|
-
//# sourceMappingURL=chunk-
|
|
112
|
+
//# sourceMappingURL=chunk-F7Z2QQRL.js.map
|