@mark1russell7/service 0.8.18 → 0.8.20
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 +19 -0
- package/build/backoff.d.ts +44 -2
- package/build/{builder-zO48Vgoj.d.ts → builder.d.ts} +14 -101
- package/build/builder.js +499 -0
- package/build/builder.js.map +1 -0
- package/build/{call-context-DDhcVvn5.d.ts → call-context.d.ts} +3 -4
- package/build/channel.d.ts +1 -1
- package/build/{core-BSzt4RI2.d.ts → client/core.d.ts} +32 -61
- package/build/{machine-BhVeHr_m.js → client/core.js} +4 -153
- package/build/client/core.js.map +1 -0
- package/build/{dial-ChwIcvd4.d.ts → client/dial.d.ts} +3 -4
- package/build/client/dial.js +52 -0
- package/build/client/dial.js.map +1 -0
- package/build/client/machine.js +29 -0
- package/build/client/machine.js.map +1 -0
- package/build/client/meets.d.ts +35 -0
- package/build/client/meets.js +78 -0
- package/build/client/meets.js.map +1 -0
- package/build/clock.d.ts +1 -1
- package/build/conformance.d.ts +122 -0
- package/build/conformance.js +470 -0
- package/build/conformance.js.map +1 -0
- package/build/contract.d.ts +28 -0
- package/build/contract.js +184 -0
- package/build/contract.js.map +1 -0
- package/build/description.d.ts +161 -0
- package/build/description.js +11 -0
- package/build/description.js.map +1 -0
- package/build/drains.js +35 -0
- package/build/drains.js.map +1 -0
- package/build/events.d.ts +25 -0
- package/build/fakes.d.ts +43 -0
- package/build/fakes.js +93 -0
- package/build/fakes.js.map +1 -0
- package/build/grpc/client.d.ts +153 -0
- package/build/grpc/client.js +474 -0
- package/build/grpc/client.js.map +1 -0
- package/build/grpc/connection.d.ts +97 -0
- package/build/grpc/connection.js +59 -0
- package/build/grpc/connection.js.map +1 -0
- package/build/grpc/machine.d.ts +12 -0
- package/build/grpc/machine.js +149 -0
- package/build/grpc/machine.js.map +1 -0
- package/build/grpc/meets.d.ts +14 -0
- package/build/grpc/meets.js +105 -0
- package/build/grpc/meets.js.map +1 -0
- package/build/grpc/starting.d.ts +33 -0
- package/build/grpc/starting.js +89 -0
- package/build/grpc/starting.js.map +1 -0
- package/build/grpc.d.ts +9 -303
- package/build/grpc.js +7 -854
- package/build/health.d.ts +93 -0
- package/build/health.js +223 -0
- package/build/health.js.map +1 -0
- package/build/heartbeat.d.ts +1 -1
- package/build/host/discovery.d.ts +61 -0
- package/build/host/discovery.js +113 -0
- package/build/host/discovery.js.map +1 -0
- package/build/host/env.d.ts +14 -0
- package/build/host/env.js +57 -0
- package/build/host/env.js.map +1 -0
- package/build/host/fakes.d.ts +82 -0
- package/build/host/fakes.js +239 -0
- package/build/host/fakes.js.map +1 -0
- package/build/host/group.d.ts +142 -0
- package/build/host/group.js +517 -0
- package/build/host/group.js.map +1 -0
- package/build/host/install.d.ts +96 -0
- package/build/host/install.js +330 -0
- package/build/host/install.js.map +1 -0
- package/build/host/lock.d.ts +78 -0
- package/build/host/lock.js +190 -0
- package/build/host/lock.js.map +1 -0
- package/build/host/logs.d.ts +26 -0
- package/build/host/logs.js +48 -0
- package/build/host/logs.js.map +1 -0
- package/build/host/node.d.ts +14 -0
- package/build/host/node.js +309 -0
- package/build/host/node.js.map +1 -0
- package/build/{ports-B1ayTL-j.d.ts → host/ports.d.ts} +15 -16
- package/build/host/ports.js +17 -0
- package/build/host/ports.js.map +1 -0
- package/build/host/probes.d.ts +51 -0
- package/build/host/probes.js +139 -0
- package/build/host/probes.js.map +1 -0
- package/build/host/processes.d.ts +32 -0
- package/build/host/processes.js +63 -0
- package/build/host/processes.js.map +1 -0
- package/build/host/render.d.ts +84 -0
- package/build/host/render.js +235 -0
- package/build/host/render.js.map +1 -0
- package/build/host/watch.d.ts +90 -0
- package/build/host/watch.js +165 -0
- package/build/host/watch.js.map +1 -0
- package/build/host.d.ts +13 -671
- package/build/host.js +12 -2126
- package/build/http/answers.js +29 -0
- package/build/http/answers.js.map +1 -0
- package/build/http/fake-server.js +61 -0
- package/build/http/fake-server.js.map +1 -0
- package/build/http/outcome.d.ts +115 -0
- package/build/http/outcome.js +325 -0
- package/build/http/outcome.js.map +1 -0
- package/build/http/probes.d.ts +83 -0
- package/build/http/probes.js +232 -0
- package/build/http/probes.js.map +1 -0
- package/build/http/transport.d.ts +165 -0
- package/build/http/transport.js +517 -0
- package/build/http/transport.js.map +1 -0
- package/build/http-client/client.d.ts +121 -0
- package/build/http-client/client.js +330 -0
- package/build/http-client/client.js.map +1 -0
- package/build/http-client/connection.d.ts +78 -0
- package/build/http-client/connection.js +54 -0
- package/build/http-client/connection.js.map +1 -0
- package/build/http-client/machine.d.ts +14 -0
- package/build/http-client/machine.js +109 -0
- package/build/http-client/machine.js.map +1 -0
- package/build/http-client/meets.d.ts +11 -0
- package/build/http-client/meets.js +74 -0
- package/build/http-client/meets.js.map +1 -0
- package/build/http-client/session.d.ts +87 -0
- package/build/http-client/session.js +99 -0
- package/build/http-client/session.js.map +1 -0
- package/build/http-client/starting.d.ts +25 -0
- package/build/http-client/starting.js +65 -0
- package/build/http-client/starting.js.map +1 -0
- package/build/http-client.d.ts +9 -330
- package/build/http-client.js +8 -707
- package/build/http.d.ts +5 -353
- package/build/http.js +3 -1086
- package/build/identity.d.ts +16 -0
- package/build/identity.js +44 -0
- package/build/identity.js.map +1 -0
- package/build/index.d.ts +35 -412
- package/build/index.js +24 -3277
- package/build/knobs.d.ts +1 -0
- package/build/{knobs-BJcz6m01.js → knobs.js} +2 -34
- package/build/knobs.js.map +1 -0
- package/build/latch.d.ts +29 -0
- package/build/latch.js +122 -0
- package/build/latch.js.map +1 -0
- package/build/{rules-HyFCBStQ.d.ts → law.d.ts} +19 -37
- package/build/law.js +149 -0
- package/build/law.js.map +1 -0
- package/build/lifecycle.d.ts +144 -0
- package/build/lifecycle.js +411 -0
- package/build/lifecycle.js.map +1 -0
- package/build/limiter/machine.d.ts +40 -0
- package/build/limiter/machine.js +279 -0
- package/build/limiter/machine.js.map +1 -0
- package/build/{policy-CBcK2XGg.d.ts → limiter/policy.d.ts} +28 -29
- package/build/{policy-UYALkqVq.js → limiter/policy.js} +10 -9
- package/build/limiter/policy.js.map +1 -0
- package/build/{limiter-Cm8nC-Gd.d.ts → limiter/quota.d.ts} +50 -76
- package/build/{limiter-Bgy6Gmvl.js → limiter/quota.js} +32 -425
- package/build/limiter/quota.js.map +1 -0
- package/build/{store-DFwFKrsB.d.ts → limiter/store.d.ts} +10 -11
- package/build/limiter/store.js +145 -0
- package/build/limiter/store.js.map +1 -0
- package/build/limiter.d.ts +4 -3
- package/build/limiter.js +4 -2
- package/build/lint.d.ts +152 -0
- package/build/lint.js +576 -0
- package/build/lint.js.map +1 -0
- package/build/logger.d.ts +71 -0
- package/build/logger.js +183 -0
- package/build/logger.js.map +1 -0
- package/build/machines.d.ts +41 -0
- package/build/machines.js +451 -0
- package/build/machines.js.map +1 -0
- package/build/metrics.d.ts +53 -0
- package/build/metrics.js +111 -0
- package/build/metrics.js.map +1 -0
- package/build/mongodb/client.d.ts +131 -0
- package/build/mongodb/client.js +388 -0
- package/build/mongodb/client.js.map +1 -0
- package/build/mongodb/connection.d.ts +112 -0
- package/build/mongodb/connection.js +12 -0
- package/build/mongodb/connection.js.map +1 -0
- package/build/mongodb/machine.d.ts +14 -0
- package/build/mongodb/machine.js +122 -0
- package/build/mongodb/machine.js.map +1 -0
- package/build/mongodb/meets.d.ts +15 -0
- package/build/mongodb/meets.js +103 -0
- package/build/mongodb/meets.js.map +1 -0
- package/build/mongodb/starting.d.ts +29 -0
- package/build/mongodb/starting.js +77 -0
- package/build/mongodb/starting.js.map +1 -0
- package/build/mongodb.d.ts +8 -296
- package/build/mongodb.js +7 -682
- package/build/operation.d.ts +27 -0
- package/build/{operation-DF73RZOI.js → operation.js} +2 -2
- package/build/operation.js.map +1 -0
- package/build/otel.d.ts +2 -2
- package/build/pg/client.d.ts +96 -0
- package/build/pg/client.js +277 -0
- package/build/pg/client.js.map +1 -0
- package/build/pg/connection.d.ts +75 -0
- package/build/pg/connection.js +11 -0
- package/build/pg/connection.js.map +1 -0
- package/build/pg/machine.d.ts +13 -0
- package/build/pg/machine.js +111 -0
- package/build/pg/machine.js.map +1 -0
- package/build/pg/meets.d.ts +14 -0
- package/build/pg/meets.js +83 -0
- package/build/pg/meets.js.map +1 -0
- package/build/pg/starting.d.ts +26 -0
- package/build/pg/starting.js +62 -0
- package/build/pg/starting.js.map +1 -0
- package/build/pg.d.ts +8 -219
- package/build/pg.js +7 -525
- package/build/poller.d.ts +9 -0
- package/build/poller.js +152 -0
- package/build/poller.js.map +1 -0
- package/build/process.d.ts +114 -0
- package/build/process.js +170 -0
- package/build/process.js.map +1 -0
- package/build/profiles.d.ts +68 -0
- package/build/profiles.js +120 -0
- package/build/profiles.js.map +1 -0
- package/build/{queue-DXdw1vLO.d.ts → queue.d.ts} +16 -29
- package/build/queue.js +279 -0
- package/build/queue.js.map +1 -0
- package/build/rabbitmq/client.d.ts +144 -0
- package/build/rabbitmq/client.js +426 -0
- package/build/rabbitmq/client.js.map +1 -0
- package/build/rabbitmq/connection.d.ts +91 -0
- package/build/rabbitmq/connection.js +15 -0
- package/build/rabbitmq/connection.js.map +1 -0
- package/build/rabbitmq/machine.d.ts +13 -0
- package/build/rabbitmq/machine.js +159 -0
- package/build/rabbitmq/machine.js.map +1 -0
- package/build/rabbitmq/meets.d.ts +12 -0
- package/build/rabbitmq/meets.js +96 -0
- package/build/rabbitmq/meets.js.map +1 -0
- package/build/rabbitmq/starting.d.ts +27 -0
- package/build/rabbitmq/starting.js +67 -0
- package/build/rabbitmq/starting.js.map +1 -0
- package/build/rabbitmq.d.ts +8 -283
- package/build/rabbitmq.js +7 -742
- package/build/redis/client.d.ts +86 -0
- package/build/redis/client.js +285 -0
- package/build/redis/client.js.map +1 -0
- package/build/redis/connection.d.ts +57 -0
- package/build/redis/connection.js +11 -0
- package/build/redis/connection.js.map +1 -0
- package/build/redis/limiter.d.ts +43 -0
- package/build/redis/limiter.js +164 -0
- package/build/redis/limiter.js.map +1 -0
- package/build/redis/machine.d.ts +12 -0
- package/build/redis/machine.js +144 -0
- package/build/redis/machine.js.map +1 -0
- package/build/redis/meets.d.ts +11 -0
- package/build/redis/meets.js +75 -0
- package/build/redis/meets.js.map +1 -0
- package/build/redis/operations.d.ts +5 -0
- package/build/redis/operations.js +114 -0
- package/build/redis/operations.js.map +1 -0
- package/build/redis.d.ts +10 -207
- package/build/redis.js +9 -771
- package/build/requests.d.ts +66 -0
- package/build/requests.js +279 -0
- package/build/requests.js.map +1 -0
- package/build/retrier.d.ts +62 -0
- package/build/{retrier-Dnjhvxol.js → retrier.js} +2 -2
- package/build/retrier.js.map +1 -0
- package/build/routes.d.ts +35 -0
- package/build/routes.js +77 -0
- package/build/routes.js.map +1 -0
- package/build/rules.d.ts +19 -2
- package/build/stops.d.ts +51 -0
- package/build/stops.js +86 -0
- package/build/stops.js.map +1 -0
- package/build/testing.d.ts +8 -270
- package/build/testing.js +4 -1027
- package/build/testing.js.map +1 -1
- package/build/timing.d.ts +63 -0
- package/build/{timing-DZl36uXs.js → timing.js} +2 -2
- package/build/timing.js.map +1 -0
- package/build/units.d.ts +17 -0
- package/build/units.js +236 -0
- package/build/units.js.map +1 -0
- package/build/watchdog.d.ts +34 -0
- package/build/watchdog.js +53 -0
- package/build/watchdog.js.map +1 -0
- package/build/websocket/client.d.ts +136 -0
- package/build/websocket/client.js +422 -0
- package/build/websocket/client.js.map +1 -0
- package/build/websocket/connection.d.ts +83 -0
- package/build/websocket/connection.js +57 -0
- package/build/websocket/connection.js.map +1 -0
- package/build/websocket/machine.d.ts +12 -0
- package/build/websocket/machine.js +155 -0
- package/build/websocket/machine.js.map +1 -0
- package/build/websocket/meets.d.ts +14 -0
- package/build/websocket/meets.js +92 -0
- package/build/websocket/meets.js.map +1 -0
- package/build/websocket/starting.d.ts +25 -0
- package/build/websocket/starting.js +69 -0
- package/build/websocket/starting.js.map +1 -0
- package/build/websocket.d.ts +9 -264
- package/build/websocket.js +8 -774
- package/build/worker.d.ts +92 -0
- package/build/worker.js +153 -0
- package/build/worker.js.map +1 -0
- package/package.json +4 -3
- package/build/backoff-QTRGfkEK.d.ts +0 -45
- package/build/clock-DpVgpY4h.d.ts +0 -2
- package/build/grpc.js.map +0 -1
- package/build/host.js.map +0 -1
- package/build/http-client.js.map +0 -1
- package/build/http.js.map +0 -1
- package/build/index.js.map +0 -1
- package/build/knobs-BJcz6m01.js.map +0 -1
- package/build/lifecycle-D0J-zwZF.d.ts +0 -374
- package/build/limiter-Bgy6Gmvl.js.map +0 -1
- package/build/logger-B6drv9w0.d.ts +0 -488
- package/build/machine-BhVeHr_m.js.map +0 -1
- package/build/mongodb.js.map +0 -1
- package/build/operation-DF73RZOI.js.map +0 -1
- package/build/pg.js.map +0 -1
- package/build/policy-UYALkqVq.js.map +0 -1
- package/build/process-7R9M29wN.js +0 -437
- package/build/process-7R9M29wN.js.map +0 -1
- package/build/rabbitmq.js.map +0 -1
- package/build/redis.js.map +0 -1
- package/build/requests-DD2ALv0_.js +0 -583
- package/build/requests-DD2ALv0_.js.map +0 -1
- package/build/retrier-Dnjhvxol.js.map +0 -1
- package/build/timing-DZl36uXs.js.map +0 -1
- package/build/websocket.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connection.js","names":[],"sources":["../../src/websocket/connection.ts"],"sourcesContent":["import type { ClientSocket, Factory } from \"../client/core.ts\";\n\n/**\n * These are the listeners of one connection. The connection holds each event until the client\n * listens. Thus an event that comes between the creation and the listen does not go away.\n */\nexport interface WsListeners {\n /** This event tells that the upgrade ended with 101, and the connection can send. */\n open(): void;\n /** This event gives one message of the server. A text message is UTF-8 in the buffer. */\n message(data: Buffer, binary: boolean): void;\n /** This event gives the payload of one pong frame. */\n pong(data: Buffer): void;\n /** This event tells that the connection closed, with the code and the reason of the close frame. Code 1006 tells that no close frame came. */\n close(code: number, reason: string): void;\n /** This event gives an error of the connection. A close follows it. */\n error(error: Error): void;\n}\n\n/**\n * A connection is the part of a `WebSocket` of ws 8 that the wrapper uses. A fake for tests has\n * each part too. Thus the package depends on no type of ws.\n */\nexport interface WsConnection {\n /** This method gives the listeners of the connection. The connection then gives each event that it holds. */\n listen(listeners: WsListeners): void;\n /** This method writes one message. The callback gets an error when the write fails. It throws while the connection is not open. */\n send(data: string | Buffer, callback: (error?: Error) => void): void;\n /** This method writes one ping frame with this payload. It throws while the connection is not open. */\n ping(data: Buffer): void;\n /** This method writes a close frame, and waits for the close frame of the server. It destroys nothing. */\n close(code: number, reason: string): void;\n /** This method destroys the socket at once. The cells measured 0.3 ms to 1 ms from the call to the close of the socket. */\n terminate(): void;\n /** This field holds the socket after the upgrade, or undefined before it. The join reads its addresses. */\n readonly socket: ClientSocket | undefined;\n /** This text is the subprotocol that the server chose, or \"\" when it chose none. */\n readonly protocol: string;\n}\n\n/**\n * These are the options that the wrapper gives `new WebSocket(url, protocols, options)` of ws. Each\n * time comes from the declaration. ws gives the options that it does not read to `net.connect`.\n */\nexport interface WsDriverOptions {\n /** This time bounds the TCP connect and the upgrade, in milliseconds. */\n readonly handshakeTimeout: number;\n /** ws answers each ping of the server with a pong. The heartbeat of the server then finds the client alive. */\n readonly autoPong: true;\n /** This time bounds the close handshake of ws, in milliseconds. The wrapper gives its own bound, `close_bound`. */\n readonly closeTimeout: number;\n /** ws sets no keepalive on its socket. The wrapper turns it on only when the declaration gives an idle time. */\n readonly keepAlive: boolean;\n /** This time is the idle time of TCP keepalive, in milliseconds. Node truncates it to whole seconds. */\n readonly keepAliveInitialDelay?: number | undefined;\n /** These headers go with the upgrade request, for example `authorization`. */\n readonly headers?: Readonly<Record<string, string>> | undefined;\n}\n\n/** These are the arguments of `new WebSocket(url, protocols, options)`. */\nexport interface WsConnectOptions {\n readonly url: string;\n readonly protocols: readonly string[];\n readonly options: WsDriverOptions;\n}\n\n/** A connection factory makes one connection from its options. The connection opens later, and tells it with the event `open`. */\nexport type WsFactory = Factory<WsConnectOptions, WsConnection>;\n\n/** This type is the part of a `WebSocket` of ws 8 that the adapter uses. */\ninterface WsDriver {\n on(event: string, listener: (...args: never[]) => void): unknown;\n send(data: string | Buffer, callback: (error?: Error | null) => void): void;\n ping(data: Buffer): void;\n close(code: number, reason: string): void;\n terminate(): void;\n readonly protocol: string;\n}\n\n/** This function gives a message of ws as one buffer. At the default `binaryType` of ws, a message is a buffer already. */\nconst asBuffer = (data: unknown): Buffer => {\n if (Buffer.isBuffer(data)) return data;\n if (Array.isArray(data)) return Buffer.concat(data as Buffer[]);\n return Buffer.from(data as ArrayBuffer);\n};\n\n/**\n * This function adapts a `WebSocket` of ws to a connection. It listens to `error` at once, because\n * in Node an error with no listener throws. It takes the socket from the event `upgrade`.\n */\nexport const adaptWs = (ws: WsDriver): WsConnection => {\n let socket: ClientSocket | undefined;\n let listeners: WsListeners | null = null;\n const held: Array<(given: WsListeners) => void> = [];\n const deliver = (event: (given: WsListeners) => void): void => {\n if (listeners === null) held.push(event);\n else event(listeners);\n };\n ws.on(\"upgrade\", (response: { readonly socket?: ClientSocket }) => {\n socket = response.socket;\n });\n ws.on(\"open\", () => deliver((given) => given.open()));\n ws.on(\"message\", (data: unknown, binary: boolean) => deliver((given) => given.message(asBuffer(data), binary)));\n ws.on(\"pong\", (data: Buffer) => deliver((given) => given.pong(data)));\n ws.on(\"close\", (code: number, reason: Buffer) => deliver((given) => given.close(code, reason.toString(\"utf8\"))));\n ws.on(\"error\", (error: Error) => deliver((given) => given.error(error)));\n return {\n listen(given) {\n listeners = given;\n for (const event of held.splice(0)) event(given);\n },\n send: (data, callback) => ws.send(data, (error) => callback(error ?? undefined)),\n ping: (data) => ws.ping(data),\n close: (code, reason) => ws.close(code, reason),\n terminate: () => ws.terminate(),\n get socket() {\n return socket;\n },\n get protocol() {\n return ws.protocol;\n },\n };\n};\n\n/**\n * This factory makes a `WebSocket` of ws. It loads ws only when a client connects, thus a service\n * that does not use WebSocket does not need it. The specifier is a value, thus the package needs no types of ws.\n */\nexport const nodeWs: WsFactory = async ({ url, protocols, options }) => {\n const specifier = \"ws\";\n type Constructor = new (url: string, protocols: string[], options: WsDriverOptions) => WsDriver;\n const loaded = (await import(specifier)) as { readonly WebSocket?: Constructor; readonly default?: Constructor };\n const WebSocket = loaded.WebSocket ?? loaded.default;\n if (WebSocket === undefined) throw new Error(\"ws gives no WebSocket class\");\n return adaptWs(new WebSocket(url, [...protocols], options));\n};\n"],"mappings":";;AAgFA,MAAM,YAAY,SAA0B;CAC1C,IAAI,OAAO,SAAS,IAAI,GAAG,OAAO;CAClC,IAAI,MAAM,QAAQ,IAAI,GAAG,OAAO,OAAO,OAAO,IAAgB;CAC9D,OAAO,OAAO,KAAK,IAAmB;AACxC;;;;;AAMA,MAAa,WAAW,OAA+B;CACrD,IAAI;CACJ,IAAI,YAAgC;CACpC,MAAM,OAA4C,CAAC;CACnD,MAAM,WAAW,UAA8C;EAC7D,IAAI,cAAc,MAAM,KAAK,KAAK,KAAK;OAClC,MAAM,SAAS;CACtB;CACA,GAAG,GAAG,YAAY,aAAiD;EACjE,SAAS,SAAS;CACpB,CAAC;CACD,GAAG,GAAG,cAAc,SAAS,UAAU,MAAM,KAAK,CAAC,CAAC;CACpD,GAAG,GAAG,YAAY,MAAe,WAAoB,SAAS,UAAU,MAAM,QAAQ,SAAS,IAAI,GAAG,MAAM,CAAC,CAAC;CAC9G,GAAG,GAAG,SAAS,SAAiB,SAAS,UAAU,MAAM,KAAK,IAAI,CAAC,CAAC;CACpE,GAAG,GAAG,UAAU,MAAc,WAAmB,SAAS,UAAU,MAAM,MAAM,MAAM,OAAO,SAAS,MAAM,CAAC,CAAC,CAAC;CAC/G,GAAG,GAAG,UAAU,UAAiB,SAAS,UAAU,MAAM,MAAM,KAAK,CAAC,CAAC;CACvE,OAAO;EACL,OAAO,OAAO;GACZ,YAAY;GACZ,KAAK,MAAM,SAAS,KAAK,OAAO,CAAC,GAAG,MAAM,KAAK;EACjD;EACA,OAAO,MAAM,aAAa,GAAG,KAAK,OAAO,UAAU,SAAS,SAAS,KAAA,CAAS,CAAC;EAC/E,OAAO,SAAS,GAAG,KAAK,IAAI;EAC5B,QAAQ,MAAM,WAAW,GAAG,MAAM,MAAM,MAAM;EAC9C,iBAAiB,GAAG,UAAU;EAC9B,IAAI,SAAS;GACX,OAAO;EACT;EACA,IAAI,WAAW;GACb,OAAO,GAAG;EACZ;CACF;AACF;;;;;AAMA,MAAa,SAAoB,OAAO,EAAE,KAAK,WAAW,cAAc;CAGtE,MAAM,SAAU,MAAM,OAAO;CAC7B,MAAM,YAAY,OAAO,aAAa,OAAO;CAC7C,IAAI,cAAc,KAAA,GAAW,MAAM,IAAI,MAAM,6BAA6B;CAC1E,OAAO,QAAQ,IAAI,UAAU,KAAK,CAAC,GAAG,SAAS,GAAG,OAAO,CAAC;AAC5D"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Machine } from "@mark1russell7/algebra";
|
|
2
|
+
/**
|
|
3
|
+
* The WebSocket client of the service as a `mark1russell7.machine/1` document. It is one generation
|
|
4
|
+
* at a time: one `WebSocket` of ws 8. The states:
|
|
5
|
+
* - `ready`: the upgrade ended with 101, and the client sends each call. Its heartbeat sends a ping frame each interval.
|
|
6
|
+
* - `failing`: no generation is open. The client connects again after its backoff.
|
|
7
|
+
* - `closing`: the calls in flight, then the close handshake, in `close_bound`. At the bound, `terminate()`.
|
|
8
|
+
*
|
|
9
|
+
* The end of the connection and the last miss of the heartbeat end the generation. A test records
|
|
10
|
+
* the transitions of the client and replays them against this document.
|
|
11
|
+
*/
|
|
12
|
+
export declare const WS_CLIENT_MACHINE: Machine;
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { clientKnob, closeTimer, transition } from "../client/machine.js";
|
|
2
|
+
// src/websocket/machine.ts
|
|
3
|
+
/** The states where the client can close, and the states where a call can start its second try. */
|
|
4
|
+
const SERVING = [
|
|
5
|
+
"connecting",
|
|
6
|
+
"ready",
|
|
7
|
+
"failing"
|
|
8
|
+
];
|
|
9
|
+
const LIVE = [...SERVING, "closing"];
|
|
10
|
+
/**
|
|
11
|
+
* The WebSocket client of the service as a `mark1russell7.machine/1` document. It is one generation
|
|
12
|
+
* at a time: one `WebSocket` of ws 8. The states:
|
|
13
|
+
* - `ready`: the upgrade ended with 101, and the client sends each call. Its heartbeat sends a ping frame each interval.
|
|
14
|
+
* - `failing`: no generation is open. The client connects again after its backoff.
|
|
15
|
+
* - `closing`: the calls in flight, then the close handshake, in `close_bound`. At the bound, `terminate()`.
|
|
16
|
+
*
|
|
17
|
+
* The end of the connection and the last miss of the heartbeat end the generation. A test records
|
|
18
|
+
* the transitions of the client and replays them against this document.
|
|
19
|
+
*/
|
|
20
|
+
const WS_CLIENT_MACHINE = {
|
|
21
|
+
format: "mark1russell7.machine/1",
|
|
22
|
+
id: "service.machine.websocket-client",
|
|
23
|
+
title: "The WebSocket client of the service, over ws 8",
|
|
24
|
+
layer: "driver",
|
|
25
|
+
version: "0.1.0",
|
|
26
|
+
sources: [{
|
|
27
|
+
ref: "packages/service/src/websocket (the client implements this document)",
|
|
28
|
+
rung: "implemented"
|
|
29
|
+
}],
|
|
30
|
+
states: {
|
|
31
|
+
none: {
|
|
32
|
+
initial: true,
|
|
33
|
+
note: "the client exists, and its first connection does not"
|
|
34
|
+
},
|
|
35
|
+
connecting: { note: "the TCP connect and the upgrade, in connect_bound" },
|
|
36
|
+
ready: { note: "the connection is open. The heartbeat finds a silent server, and the timer of a call ends a call that waits" },
|
|
37
|
+
failing: { note: "no generation is open. The client connects again after its backoff" },
|
|
38
|
+
closing: { note: "the calls in flight, then the close handshake, in close_bound. At the bound, terminate() destroys the socket" },
|
|
39
|
+
end: {
|
|
40
|
+
final: true,
|
|
41
|
+
note: "the service closed the client"
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
events: {
|
|
45
|
+
"status.connecting": { kind: "local" },
|
|
46
|
+
join: {
|
|
47
|
+
kind: "rx",
|
|
48
|
+
note: "the upgrade ended with 101: a new generation (D1)"
|
|
49
|
+
},
|
|
50
|
+
"connect.failed": {
|
|
51
|
+
kind: "local",
|
|
52
|
+
note: "the connect or the upgrade failed, or did not end in connect_bound"
|
|
53
|
+
},
|
|
54
|
+
"retry.connect": {
|
|
55
|
+
kind: "timer",
|
|
56
|
+
note: "the backoff ended: a new try"
|
|
57
|
+
},
|
|
58
|
+
"connection.error": {
|
|
59
|
+
kind: "rx",
|
|
60
|
+
note: "an error event of the connection. Its close follows"
|
|
61
|
+
},
|
|
62
|
+
"connection.end": {
|
|
63
|
+
kind: "rx",
|
|
64
|
+
note: "the connection closed: a reset, a FIN, a close frame of the server, or the kernel"
|
|
65
|
+
},
|
|
66
|
+
"heartbeat.miss": {
|
|
67
|
+
kind: "timer",
|
|
68
|
+
note: "a ping frame got no pong in heartbeat_timeout"
|
|
69
|
+
},
|
|
70
|
+
"heartbeat.dead": {
|
|
71
|
+
kind: "local",
|
|
72
|
+
note: "the last miss in sequence: terminate() destroys the socket at once"
|
|
73
|
+
},
|
|
74
|
+
"command.reissue": { kind: "local" },
|
|
75
|
+
"close.request": { kind: "local" },
|
|
76
|
+
"close.bound": {
|
|
77
|
+
kind: "timer",
|
|
78
|
+
note: "the calls in flight or the close handshake did not end in close_bound"
|
|
79
|
+
},
|
|
80
|
+
"close.destroy": {
|
|
81
|
+
kind: "local",
|
|
82
|
+
note: "terminate() destroys a socket that a silent server does not close"
|
|
83
|
+
},
|
|
84
|
+
"status.end": { kind: "local" }
|
|
85
|
+
},
|
|
86
|
+
knobs: {
|
|
87
|
+
connect_bound: clientKnob("handshakeTimeout"),
|
|
88
|
+
heartbeat_interval: clientKnob("heartbeat.interval"),
|
|
89
|
+
heartbeat_timeout: clientKnob("heartbeat.timeout"),
|
|
90
|
+
retry_base: clientKnob("retry.base"),
|
|
91
|
+
retry_cap: clientKnob("retry.cap"),
|
|
92
|
+
close_bound: clientKnob("close.bound")
|
|
93
|
+
},
|
|
94
|
+
timers: {
|
|
95
|
+
connect_timeout: {
|
|
96
|
+
duration: {
|
|
97
|
+
knob: "connect_bound",
|
|
98
|
+
unit: "s"
|
|
99
|
+
},
|
|
100
|
+
arms: ["enter:connecting"],
|
|
101
|
+
cancels: ["join", "connect.failed"],
|
|
102
|
+
fires: "connect.failed",
|
|
103
|
+
note: "the bound of the wrapper on the open. ws bounds the connect and the upgrade with the same time"
|
|
104
|
+
},
|
|
105
|
+
heartbeat: {
|
|
106
|
+
duration: {
|
|
107
|
+
expr: "heartbeat_interval + heartbeat_timeout",
|
|
108
|
+
unit: "s"
|
|
109
|
+
},
|
|
110
|
+
arms: ["join", "heartbeat.miss"],
|
|
111
|
+
cancels: [
|
|
112
|
+
"connection.end",
|
|
113
|
+
"heartbeat.dead",
|
|
114
|
+
"close.request"
|
|
115
|
+
],
|
|
116
|
+
fires: "heartbeat.miss",
|
|
117
|
+
note: "one ping at a time: a ping frame each interval, and a miss at its timeout with no pong. Each pong starts it again"
|
|
118
|
+
},
|
|
119
|
+
retry: {
|
|
120
|
+
duration: {
|
|
121
|
+
expr: "min(retry_cap, retry_base * pow(2, fired)) + retry_base",
|
|
122
|
+
unit: "s"
|
|
123
|
+
},
|
|
124
|
+
arms: [
|
|
125
|
+
"connect.failed",
|
|
126
|
+
"connection.end",
|
|
127
|
+
"heartbeat.dead"
|
|
128
|
+
],
|
|
129
|
+
cancels: ["close.request"],
|
|
130
|
+
fires: "retry.connect",
|
|
131
|
+
backoff: { resets: ["join"] },
|
|
132
|
+
note: "the most delay: the backoff doubles from retry_base to retry_cap, with a jitter up to retry_base"
|
|
133
|
+
},
|
|
134
|
+
close: closeTimer()
|
|
135
|
+
},
|
|
136
|
+
transitions: [
|
|
137
|
+
transition("connect", "none", "status.connecting", "connecting"),
|
|
138
|
+
transition("join", "connecting", "join", "ready"),
|
|
139
|
+
transition("connect-failed", "connecting", "connect.failed", "failing", { timer: "connect_timeout" }),
|
|
140
|
+
transition("retry", "failing", "retry.connect", "connecting", { timer: "retry" }),
|
|
141
|
+
transition("connection-end", "ready", "connection.end", "failing"),
|
|
142
|
+
transition("heartbeat-miss", "ready", "heartbeat.miss", "ready", { timer: "heartbeat" }),
|
|
143
|
+
transition("heartbeat-dead", "ready", "heartbeat.dead", "failing"),
|
|
144
|
+
transition("connection-error-ready", "ready", "connection.error", "ready"),
|
|
145
|
+
transition("connection-error-closing", "closing", "connection.error", "closing"),
|
|
146
|
+
...LIVE.map((state) => transition(`reissue-${state}`, state, "command.reissue", state)),
|
|
147
|
+
transition("close", [...SERVING], "close.request", "closing"),
|
|
148
|
+
transition("close-bound", "closing", "close.bound", "closing", { timer: "close" }),
|
|
149
|
+
transition("close-destroy", "closing", "close.destroy", "closing"),
|
|
150
|
+
transition("end", "closing", "status.end", "end")
|
|
151
|
+
]
|
|
152
|
+
};
|
|
153
|
+
export { WS_CLIENT_MACHINE };
|
|
154
|
+
|
|
155
|
+
//# sourceMappingURL=machine.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"machine.js","names":["knob","t"],"sources":["../../src/websocket/machine.ts"],"sourcesContent":["import type { Machine } from \"@mark1russell7/algebra\";\nimport { clientKnob as knob, closeTimer, transition as t } from \"../client/machine.ts\";\n\n/** The states where the client can close, and the states where a call can start its second try. */\nconst SERVING = [\"connecting\", \"ready\", \"failing\"] as const;\nconst LIVE = [...SERVING, \"closing\"] as const;\n\n/**\n * The WebSocket client of the service as a `mark1russell7.machine/1` document. It is one generation\n * at a time: one `WebSocket` of ws 8. The states:\n * - `ready`: the upgrade ended with 101, and the client sends each call. Its heartbeat sends a ping frame each interval.\n * - `failing`: no generation is open. The client connects again after its backoff.\n * - `closing`: the calls in flight, then the close handshake, in `close_bound`. At the bound, `terminate()`.\n *\n * The end of the connection and the last miss of the heartbeat end the generation. A test records\n * the transitions of the client and replays them against this document.\n */\nexport const WS_CLIENT_MACHINE: Machine = {\n format: \"mark1russell7.machine/1\",\n id: \"service.machine.websocket-client\",\n title: \"The WebSocket client of the service, over ws 8\",\n layer: \"driver\",\n version: \"0.1.0\",\n sources: [{ ref: \"packages/service/src/websocket (the client implements this document)\", rung: \"implemented\" }],\n states: {\n none: { initial: true, note: \"the client exists, and its first connection does not\" },\n connecting: { note: \"the TCP connect and the upgrade, in connect_bound\" },\n ready: { note: \"the connection is open. The heartbeat finds a silent server, and the timer of a call ends a call that waits\" },\n failing: { note: \"no generation is open. The client connects again after its backoff\" },\n closing: { note: \"the calls in flight, then the close handshake, in close_bound. At the bound, terminate() destroys the socket\" },\n end: { final: true, note: \"the service closed the client\" },\n },\n events: {\n \"status.connecting\": { kind: \"local\" },\n join: { kind: \"rx\", note: \"the upgrade ended with 101: a new generation (D1)\" },\n \"connect.failed\": { kind: \"local\", note: \"the connect or the upgrade failed, or did not end in connect_bound\" },\n \"retry.connect\": { kind: \"timer\", note: \"the backoff ended: a new try\" },\n \"connection.error\": { kind: \"rx\", note: \"an error event of the connection. Its close follows\" },\n \"connection.end\": { kind: \"rx\", note: \"the connection closed: a reset, a FIN, a close frame of the server, or the kernel\" },\n \"heartbeat.miss\": { kind: \"timer\", note: \"a ping frame got no pong in heartbeat_timeout\" },\n \"heartbeat.dead\": { kind: \"local\", note: \"the last miss in sequence: terminate() destroys the socket at once\" },\n \"command.reissue\": { kind: \"local\" },\n \"close.request\": { kind: \"local\" },\n \"close.bound\": { kind: \"timer\", note: \"the calls in flight or the close handshake did not end in close_bound\" },\n \"close.destroy\": { kind: \"local\", note: \"terminate() destroys a socket that a silent server does not close\" },\n \"status.end\": { kind: \"local\" },\n },\n knobs: {\n connect_bound: knob(\"handshakeTimeout\"),\n heartbeat_interval: knob(\"heartbeat.interval\"),\n heartbeat_timeout: knob(\"heartbeat.timeout\"),\n retry_base: knob(\"retry.base\"),\n retry_cap: knob(\"retry.cap\"),\n close_bound: knob(\"close.bound\"),\n },\n timers: {\n connect_timeout: {\n duration: { knob: \"connect_bound\", unit: \"s\" },\n arms: [\"enter:connecting\"],\n cancels: [\"join\", \"connect.failed\"],\n fires: \"connect.failed\",\n note: \"the bound of the wrapper on the open. ws bounds the connect and the upgrade with the same time\",\n },\n heartbeat: {\n duration: { expr: \"heartbeat_interval + heartbeat_timeout\", unit: \"s\" },\n arms: [\"join\", \"heartbeat.miss\"],\n cancels: [\"connection.end\", \"heartbeat.dead\", \"close.request\"],\n fires: \"heartbeat.miss\",\n note: \"one ping at a time: a ping frame each interval, and a miss at its timeout with no pong. Each pong starts it again\",\n },\n retry: {\n duration: { expr: \"min(retry_cap, retry_base * pow(2, fired)) + retry_base\", unit: \"s\" },\n arms: [\"connect.failed\", \"connection.end\", \"heartbeat.dead\"],\n cancels: [\"close.request\"],\n fires: \"retry.connect\",\n backoff: { resets: [\"join\"] },\n note: \"the most delay: the backoff doubles from retry_base to retry_cap, with a jitter up to retry_base\",\n },\n close: closeTimer(),\n },\n transitions: [\n t(\"connect\", \"none\", \"status.connecting\", \"connecting\"),\n t(\"join\", \"connecting\", \"join\", \"ready\"),\n t(\"connect-failed\", \"connecting\", \"connect.failed\", \"failing\", { timer: \"connect_timeout\" }),\n t(\"retry\", \"failing\", \"retry.connect\", \"connecting\", { timer: \"retry\" }),\n t(\"connection-end\", \"ready\", \"connection.end\", \"failing\"),\n t(\"heartbeat-miss\", \"ready\", \"heartbeat.miss\", \"ready\", { timer: \"heartbeat\" }),\n t(\"heartbeat-dead\", \"ready\", \"heartbeat.dead\", \"failing\"),\n t(\"connection-error-ready\", \"ready\", \"connection.error\", \"ready\"),\n t(\"connection-error-closing\", \"closing\", \"connection.error\", \"closing\"),\n ...LIVE.map((state) => t(`reissue-${state}`, state, \"command.reissue\", state)),\n t(\"close\", [...SERVING], \"close.request\", \"closing\"),\n t(\"close-bound\", \"closing\", \"close.bound\", \"closing\", { timer: \"close\" }),\n t(\"close-destroy\", \"closing\", \"close.destroy\", \"closing\"),\n t(\"end\", \"closing\", \"status.end\", \"end\"),\n ],\n};\n"],"mappings":";;;AAIA,MAAM,UAAU;CAAC;CAAc;CAAS;AAAS;AACjD,MAAM,OAAO,CAAC,GAAG,SAAS,SAAS;;;;;;;;;;;AAYnC,MAAa,oBAA6B;CACxC,QAAQ;CACR,IAAI;CACJ,OAAO;CACP,OAAO;CACP,SAAS;CACT,SAAS,CAAC;EAAE,KAAK;EAAwE,MAAM;CAAc,CAAC;CAC9G,QAAQ;EACN,MAAM;GAAE,SAAS;GAAM,MAAM;EAAuD;EACpF,YAAY,EAAE,MAAM,oDAAoD;EACxE,OAAO,EAAE,MAAM,8GAA8G;EAC7H,SAAS,EAAE,MAAM,qEAAqE;EACtF,SAAS,EAAE,MAAM,+GAA+G;EAChI,KAAK;GAAE,OAAO;GAAM,MAAM;EAAgC;CAC5D;CACA,QAAQ;EACN,qBAAqB,EAAE,MAAM,QAAQ;EACrC,MAAM;GAAE,MAAM;GAAM,MAAM;EAAoD;EAC9E,kBAAkB;GAAE,MAAM;GAAS,MAAM;EAAqE;EAC9G,iBAAiB;GAAE,MAAM;GAAS,MAAM;EAA+B;EACvE,oBAAoB;GAAE,MAAM;GAAM,MAAM;EAAsD;EAC9F,kBAAkB;GAAE,MAAM;GAAM,MAAM;EAAoF;EAC1H,kBAAkB;GAAE,MAAM;GAAS,MAAM;EAAgD;EACzF,kBAAkB;GAAE,MAAM;GAAS,MAAM;EAAqE;EAC9G,mBAAmB,EAAE,MAAM,QAAQ;EACnC,iBAAiB,EAAE,MAAM,QAAQ;EACjC,eAAe;GAAE,MAAM;GAAS,MAAM;EAAwE;EAC9G,iBAAiB;GAAE,MAAM;GAAS,MAAM;EAAoE;EAC5G,cAAc,EAAE,MAAM,QAAQ;CAChC;CACA,OAAO;EACL,eAAeA,WAAK,kBAAkB;EACtC,oBAAoBA,WAAK,oBAAoB;EAC7C,mBAAmBA,WAAK,mBAAmB;EAC3C,YAAYA,WAAK,YAAY;EAC7B,WAAWA,WAAK,WAAW;EAC3B,aAAaA,WAAK,aAAa;CACjC;CACA,QAAQ;EACN,iBAAiB;GACf,UAAU;IAAE,MAAM;IAAiB,MAAM;GAAI;GAC7C,MAAM,CAAC,kBAAkB;GACzB,SAAS,CAAC,QAAQ,gBAAgB;GAClC,OAAO;GACP,MAAM;EACR;EACA,WAAW;GACT,UAAU;IAAE,MAAM;IAA0C,MAAM;GAAI;GACtE,MAAM,CAAC,QAAQ,gBAAgB;GAC/B,SAAS;IAAC;IAAkB;IAAkB;GAAe;GAC7D,OAAO;GACP,MAAM;EACR;EACA,OAAO;GACL,UAAU;IAAE,MAAM;IAA2D,MAAM;GAAI;GACvF,MAAM;IAAC;IAAkB;IAAkB;GAAgB;GAC3D,SAAS,CAAC,eAAe;GACzB,OAAO;GACP,SAAS,EAAE,QAAQ,CAAC,MAAM,EAAE;GAC5B,MAAM;EACR;EACA,OAAO,WAAW;CACpB;CACA,aAAa;EACXC,WAAE,WAAW,QAAQ,qBAAqB,YAAY;EACtDA,WAAE,QAAQ,cAAc,QAAQ,OAAO;EACvCA,WAAE,kBAAkB,cAAc,kBAAkB,WAAW,EAAE,OAAO,kBAAkB,CAAC;EAC3FA,WAAE,SAAS,WAAW,iBAAiB,cAAc,EAAE,OAAO,QAAQ,CAAC;EACvEA,WAAE,kBAAkB,SAAS,kBAAkB,SAAS;EACxDA,WAAE,kBAAkB,SAAS,kBAAkB,SAAS,EAAE,OAAO,YAAY,CAAC;EAC9EA,WAAE,kBAAkB,SAAS,kBAAkB,SAAS;EACxDA,WAAE,0BAA0B,SAAS,oBAAoB,OAAO;EAChEA,WAAE,4BAA4B,WAAW,oBAAoB,SAAS;EACtE,GAAG,KAAK,KAAK,UAAUA,WAAE,WAAW,SAAS,OAAO,mBAAmB,KAAK,CAAC;EAC7EA,WAAE,SAAS,CAAC,GAAG,OAAO,GAAG,iBAAiB,SAAS;EACnDA,WAAE,eAAe,WAAW,eAAe,WAAW,EAAE,OAAO,QAAQ,CAAC;EACxEA,WAAE,iBAAiB,WAAW,iBAAiB,SAAS;EACxDA,WAAE,OAAO,WAAW,cAAc,KAAK;CACzC;AACF"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Meeting } from "../client/meets.js";
|
|
2
|
+
import { WsKnobs } from "./client.js";
|
|
3
|
+
/**
|
|
4
|
+
* This function gives the manifestations that a WebSocket client can meet, and the detectors of
|
|
5
|
+
* each, from its knobs. The WS cells measured them on ws 8:
|
|
6
|
+
* - At a heartbeat of 2 s, a timeout of 1 s and 1 miss, the drop came 0.999 s to 1.0035 s after the
|
|
7
|
+
* ping that got no pong. The slowest of 495 runs took 1.003761 s.
|
|
8
|
+
* - `terminate()` closes the socket 0.3 ms to 1 ms after the drop. The close of the global WebSocket
|
|
9
|
+
* only writes a close frame, and its socket stayed ESTABLISHED.
|
|
10
|
+
* - The kernel of a frozen server acknowledges each ping, thus only the heartbeat finds it.
|
|
11
|
+
* - At `tcp_retries2 = 3`, the kernel gave up before a pong timeout of 10 s.
|
|
12
|
+
* - Without a heartbeat, the client waited for the keepalive of undici: 70 s. ws sets no keepalive.
|
|
13
|
+
*/
|
|
14
|
+
export declare const wsMeetings: (name: string, knobs: WsKnobs, misses: number) => Meeting[];
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { NEVER, WHAT, immediate, keepaliveAnswered, keepaliveReset, keepaliveSilent, kernelGiveUp } from "../client/meets.js";
|
|
2
|
+
import { finiteMs } from "../client/core.js";
|
|
3
|
+
import { heartbeatDetection } from "../timing.js";
|
|
4
|
+
// src/websocket/meets.ts
|
|
5
|
+
/**
|
|
6
|
+
* This function gives the manifestations that a WebSocket client can meet, and the detectors of
|
|
7
|
+
* each, from its knobs. The WS cells measured them on ws 8:
|
|
8
|
+
* - At a heartbeat of 2 s, a timeout of 1 s and 1 miss, the drop came 0.999 s to 1.0035 s after the
|
|
9
|
+
* ping that got no pong. The slowest of 495 runs took 1.003761 s.
|
|
10
|
+
* - `terminate()` closes the socket 0.3 ms to 1 ms after the drop. The close of the global WebSocket
|
|
11
|
+
* only writes a close frame, and its socket stayed ESTABLISHED.
|
|
12
|
+
* - The kernel of a frozen server acknowledges each ping, thus only the heartbeat finds it.
|
|
13
|
+
* - At `tcp_retries2 = 3`, the kernel gave up before a pong timeout of 10 s.
|
|
14
|
+
* - Without a heartbeat, the client waited for the keepalive of undici: 70 s. ws sets no keepalive.
|
|
15
|
+
*/
|
|
16
|
+
const wsMeetings = (name, knobs, misses) => {
|
|
17
|
+
const interval = finiteMs(knobs.heartbeat_interval);
|
|
18
|
+
const detection = heartbeatDetection(knobs.heartbeat_interval, knobs.heartbeat_timeout, misses);
|
|
19
|
+
const heartbeat = (situation) => ({
|
|
20
|
+
by: "heartbeat_detection_time",
|
|
21
|
+
within: detection,
|
|
22
|
+
situation,
|
|
23
|
+
effect: `the heartbeat destroys the socket with terminate(), each call in flight fails as indeterminate, and ${name} connects again`
|
|
24
|
+
});
|
|
25
|
+
const call = {
|
|
26
|
+
by: "request_timeout",
|
|
27
|
+
within: knobs.request_timeout,
|
|
28
|
+
situation: "in flight",
|
|
29
|
+
effect: "the timer of the wrapper ends the call as indeterminate, and the connection stays"
|
|
30
|
+
};
|
|
31
|
+
const giveUp = kernelGiveUp(knobs.retrans_giveup_time, "each call in flight fails as indeterminate");
|
|
32
|
+
const silent = (manifestation) => ({
|
|
33
|
+
manifestation,
|
|
34
|
+
what: WHAT[manifestation],
|
|
35
|
+
detectors: [
|
|
36
|
+
call,
|
|
37
|
+
heartbeat("in flight"),
|
|
38
|
+
giveUp,
|
|
39
|
+
heartbeat("idle"),
|
|
40
|
+
keepaliveSilent(knobs.keepalive_idle)
|
|
41
|
+
]
|
|
42
|
+
});
|
|
43
|
+
return [
|
|
44
|
+
{
|
|
45
|
+
manifestation: "rst",
|
|
46
|
+
what: WHAT.rst,
|
|
47
|
+
detectors: [
|
|
48
|
+
immediate("in flight", "ws closes with code 1006, the call fails as indeterminate, and the client connects again"),
|
|
49
|
+
{
|
|
50
|
+
by: "heartbeat_interval",
|
|
51
|
+
within: interval === void 0 ? NEVER : knobs.heartbeat_interval,
|
|
52
|
+
situation: "idle",
|
|
53
|
+
effect: "the next ping frame gets a reset, and the client connects again"
|
|
54
|
+
},
|
|
55
|
+
keepaliveReset(knobs.keepalive_idle)
|
|
56
|
+
]
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
manifestation: "fin",
|
|
60
|
+
what: WHAT.fin,
|
|
61
|
+
detectors: [immediate("in flight", "the FIN arrives, ws closes with code 1006, and the call fails as indeterminate"), immediate("idle", "the FIN arrives, ws closes with code 1006, and the client connects again")]
|
|
62
|
+
},
|
|
63
|
+
silent("blackhole"),
|
|
64
|
+
silent("freeze-host"),
|
|
65
|
+
{
|
|
66
|
+
manifestation: "freeze-process",
|
|
67
|
+
what: WHAT["freeze-process"],
|
|
68
|
+
detectors: [
|
|
69
|
+
call,
|
|
70
|
+
heartbeat("in flight"),
|
|
71
|
+
heartbeat("idle"),
|
|
72
|
+
keepaliveAnswered()
|
|
73
|
+
]
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
manifestation: "app-stall",
|
|
77
|
+
what: "the server holds its reply, for example in a slow handler, and its library still answers each ping",
|
|
78
|
+
detectors: [
|
|
79
|
+
call,
|
|
80
|
+
{
|
|
81
|
+
...heartbeat("idle"),
|
|
82
|
+
within: NEVER,
|
|
83
|
+
effect: "the library of the server still answers each ping with a pong"
|
|
84
|
+
},
|
|
85
|
+
keepaliveAnswered()
|
|
86
|
+
]
|
|
87
|
+
}
|
|
88
|
+
];
|
|
89
|
+
};
|
|
90
|
+
export { wsMeetings };
|
|
91
|
+
|
|
92
|
+
//# sourceMappingURL=meets.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"meets.js","names":[],"sources":["../../src/websocket/meets.ts"],"sourcesContent":["import type { Detector, Meeting, Situation } from \"../client/meets.ts\";\nimport { NEVER, WHAT, immediate, keepaliveAnswered, keepaliveReset, keepaliveSilent, kernelGiveUp } from \"../client/meets.ts\";\nimport { finiteMs } from \"../client/core.ts\";\nimport { heartbeatDetection } from \"../timing.ts\";\nimport type { WsKnobs } from \"./client.ts\";\n\n/**\n * This function gives the manifestations that a WebSocket client can meet, and the detectors of\n * each, from its knobs. The WS cells measured them on ws 8:\n * - At a heartbeat of 2 s, a timeout of 1 s and 1 miss, the drop came 0.999 s to 1.0035 s after the\n * ping that got no pong. The slowest of 495 runs took 1.003761 s.\n * - `terminate()` closes the socket 0.3 ms to 1 ms after the drop. The close of the global WebSocket\n * only writes a close frame, and its socket stayed ESTABLISHED.\n * - The kernel of a frozen server acknowledges each ping, thus only the heartbeat finds it.\n * - At `tcp_retries2 = 3`, the kernel gave up before a pong timeout of 10 s.\n * - Without a heartbeat, the client waited for the keepalive of undici: 70 s. ws sets no keepalive.\n */\nexport const wsMeetings = (name: string, knobs: WsKnobs, misses: number): Meeting[] => {\n const interval = finiteMs(knobs.heartbeat_interval);\n const detection = heartbeatDetection(knobs.heartbeat_interval, knobs.heartbeat_timeout, misses);\n const heartbeat = (situation: Situation): Detector => ({\n by: \"heartbeat_detection_time\",\n within: detection,\n situation,\n effect: `the heartbeat destroys the socket with terminate(), each call in flight fails as indeterminate, and ${name} connects again`,\n });\n const call: Detector = {\n by: \"request_timeout\",\n within: knobs.request_timeout,\n situation: \"in flight\",\n effect: \"the timer of the wrapper ends the call as indeterminate, and the connection stays\",\n };\n const giveUp = kernelGiveUp(knobs.retrans_giveup_time, \"each call in flight fails as indeterminate\");\n const silent = (manifestation: \"blackhole\" | \"freeze-host\"): Meeting => ({\n manifestation,\n what: WHAT[manifestation],\n detectors: [call, heartbeat(\"in flight\"), giveUp, heartbeat(\"idle\"), keepaliveSilent(knobs.keepalive_idle)],\n });\n return [\n {\n manifestation: \"rst\",\n what: WHAT.rst,\n detectors: [\n immediate(\"in flight\", \"ws closes with code 1006, the call fails as indeterminate, and the client connects again\"),\n {\n by: \"heartbeat_interval\",\n within: interval === undefined ? NEVER : knobs.heartbeat_interval,\n situation: \"idle\",\n effect: \"the next ping frame gets a reset, and the client connects again\",\n },\n keepaliveReset(knobs.keepalive_idle),\n ],\n },\n {\n manifestation: \"fin\",\n what: WHAT.fin,\n detectors: [\n immediate(\"in flight\", \"the FIN arrives, ws closes with code 1006, and the call fails as indeterminate\"),\n immediate(\"idle\", \"the FIN arrives, ws closes with code 1006, and the client connects again\"),\n ],\n },\n silent(\"blackhole\"),\n silent(\"freeze-host\"),\n {\n manifestation: \"freeze-process\",\n what: WHAT[\"freeze-process\"],\n detectors: [call, heartbeat(\"in flight\"), heartbeat(\"idle\"), keepaliveAnswered()],\n },\n {\n manifestation: \"app-stall\",\n what: \"the server holds its reply, for example in a slow handler, and its library still answers each ping\",\n detectors: [call, { ...heartbeat(\"idle\"), within: NEVER, effect: \"the library of the server still answers each ping with a pong\" }, keepaliveAnswered()],\n },\n ];\n};\n"],"mappings":";;;;;;;;;;;;;;;AAiBA,MAAa,cAAc,MAAc,OAAgB,WAA8B;CACrF,MAAM,WAAW,SAAS,MAAM,kBAAkB;CAClD,MAAM,YAAY,mBAAmB,MAAM,oBAAoB,MAAM,mBAAmB,MAAM;CAC9F,MAAM,aAAa,eAAoC;EACrD,IAAI;EACJ,QAAQ;EACR;EACA,QAAQ,uGAAuG,KAAK;CACtH;CACA,MAAM,OAAiB;EACrB,IAAI;EACJ,QAAQ,MAAM;EACd,WAAW;EACX,QAAQ;CACV;CACA,MAAM,SAAS,aAAa,MAAM,qBAAqB,4CAA4C;CACnG,MAAM,UAAU,mBAAyD;EACvE;EACA,MAAM,KAAK;EACX,WAAW;GAAC;GAAM,UAAU,WAAW;GAAG;GAAQ,UAAU,MAAM;GAAG,gBAAgB,MAAM,cAAc;EAAC;CAC5G;CACA,OAAO;EACL;GACE,eAAe;GACf,MAAM,KAAK;GACX,WAAW;IACT,UAAU,aAAa,0FAA0F;IACjH;KACE,IAAI;KACJ,QAAQ,aAAa,KAAA,IAAY,QAAQ,MAAM;KAC/C,WAAW;KACX,QAAQ;IACV;IACA,eAAe,MAAM,cAAc;GACrC;EACF;EACA;GACE,eAAe;GACf,MAAM,KAAK;GACX,WAAW,CACT,UAAU,aAAa,gFAAgF,GACvG,UAAU,QAAQ,0EAA0E,CAC9F;EACF;EACA,OAAO,WAAW;EAClB,OAAO,aAAa;EACpB;GACE,eAAe;GACf,MAAM,KAAK;GACX,WAAW;IAAC;IAAM,UAAU,WAAW;IAAG,UAAU,MAAM;IAAG,kBAAkB;GAAC;EAClF;EACA;GACE,eAAe;GACf,MAAM;GACN,WAAW;IAAC;IAAM;KAAE,GAAG,UAAU,MAAM;KAAG,QAAQ;KAAO,QAAQ;IAAgE;IAAG,kBAAkB;GAAC;EACzJ;CACF;AACF"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Poll } from "../timing.js";
|
|
2
|
+
import { WsKnobs } from "./client.js";
|
|
3
|
+
/**
|
|
4
|
+
* This poll is the poll of the checks that `WS_CLIENT_STARTING_KNOBS` fits. It is `STARTING_POLL` of
|
|
5
|
+
* the core: each 5 s with a jitter of 20 %, and a timeout of 4 s (B6, O12). The poll does not depend on the driver.
|
|
6
|
+
*/
|
|
7
|
+
export declare const WS_CLIENT_STARTING_POLL: Poll;
|
|
8
|
+
/** This count is the heartbeat misses to start from: 1, as in the WS cells. The drop came 0.999 s to 1.0035 s after the ping with no pong. */
|
|
9
|
+
export declare const WS_CLIENT_STARTING_MISSES = 1;
|
|
10
|
+
/**
|
|
11
|
+
* These knobs are a declaration to start from, from what the WS cells measured on ws 8. The runtime
|
|
12
|
+
* has no defaults: a service gives these knobs, or its own. Each value holds the borders that the cells measured:
|
|
13
|
+
* - `connect_bound` 5 s: the connect timeout of DP44. ws sets no handshake timeout by default.
|
|
14
|
+
* - `request_timeout` 9.5 s: in the slowest poll of 10 s (O13).
|
|
15
|
+
* - `heartbeat_interval` 4 s: in the WST cells, a ping each 4 s kept a flow through a router that
|
|
16
|
+
* forgets it at 5 s. A ping each 6 s did not (O03).
|
|
17
|
+
* - `heartbeat_timeout` 3 s: a stall of 1 s with a pong timeout of 3 s dropped nothing. The detection is 4 s + 3 s = 7 s.
|
|
18
|
+
* - `retry_base` 0.5 s and `retry_cap` 4 s: the reconnect of the cells, from 500 ms, doubling to 4 s.
|
|
19
|
+
* The client adds a jitter up to the base. Thus the most delay is 4.5 s, in the slowest poll of 10 s.
|
|
20
|
+
* - `keepalive_idle` "infinite": ws sets no keepalive, and the heartbeat refreshes an idle flow.
|
|
21
|
+
* - `max_connection_age` "infinite": the client does not replace its connection at an age.
|
|
22
|
+
* - `close_bound` 2 s: a close frame to a silent server gets no answer. The `closeTimeout` of ws is 30 s.
|
|
23
|
+
* - `retrans_giveup_time` 924.6 s: the give-up of Linux at `tcp_retries2 = 15`.
|
|
24
|
+
*/
|
|
25
|
+
export declare const WS_CLIENT_STARTING_KNOBS: WsKnobs;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { STARTING_POLL } from "../client/core.js";
|
|
2
|
+
// src/websocket/starting.ts
|
|
3
|
+
/**
|
|
4
|
+
* This poll is the poll of the checks that `WS_CLIENT_STARTING_KNOBS` fits. It is `STARTING_POLL` of
|
|
5
|
+
* the core: each 5 s with a jitter of 20 %, and a timeout of 4 s (B6, O12). The poll does not depend on the driver.
|
|
6
|
+
*/
|
|
7
|
+
const WS_CLIENT_STARTING_POLL = STARTING_POLL;
|
|
8
|
+
/** This count is the heartbeat misses to start from: 1, as in the WS cells. The drop came 0.999 s to 1.0035 s after the ping with no pong. */
|
|
9
|
+
const WS_CLIENT_STARTING_MISSES = 1;
|
|
10
|
+
/**
|
|
11
|
+
* These knobs are a declaration to start from, from what the WS cells measured on ws 8. The runtime
|
|
12
|
+
* has no defaults: a service gives these knobs, or its own. Each value holds the borders that the cells measured:
|
|
13
|
+
* - `connect_bound` 5 s: the connect timeout of DP44. ws sets no handshake timeout by default.
|
|
14
|
+
* - `request_timeout` 9.5 s: in the slowest poll of 10 s (O13).
|
|
15
|
+
* - `heartbeat_interval` 4 s: in the WST cells, a ping each 4 s kept a flow through a router that
|
|
16
|
+
* forgets it at 5 s. A ping each 6 s did not (O03).
|
|
17
|
+
* - `heartbeat_timeout` 3 s: a stall of 1 s with a pong timeout of 3 s dropped nothing. The detection is 4 s + 3 s = 7 s.
|
|
18
|
+
* - `retry_base` 0.5 s and `retry_cap` 4 s: the reconnect of the cells, from 500 ms, doubling to 4 s.
|
|
19
|
+
* The client adds a jitter up to the base. Thus the most delay is 4.5 s, in the slowest poll of 10 s.
|
|
20
|
+
* - `keepalive_idle` "infinite": ws sets no keepalive, and the heartbeat refreshes an idle flow.
|
|
21
|
+
* - `max_connection_age` "infinite": the client does not replace its connection at an age.
|
|
22
|
+
* - `close_bound` 2 s: a close frame to a silent server gets no answer. The `closeTimeout` of ws is 30 s.
|
|
23
|
+
* - `retrans_giveup_time` 924.6 s: the give-up of Linux at `tcp_retries2 = 15`.
|
|
24
|
+
*/
|
|
25
|
+
const WS_CLIENT_STARTING_KNOBS = {
|
|
26
|
+
connect_bound: {
|
|
27
|
+
value: 5,
|
|
28
|
+
unit: "s"
|
|
29
|
+
},
|
|
30
|
+
request_timeout: {
|
|
31
|
+
value: 9.5,
|
|
32
|
+
unit: "s"
|
|
33
|
+
},
|
|
34
|
+
heartbeat_interval: {
|
|
35
|
+
value: 4,
|
|
36
|
+
unit: "s"
|
|
37
|
+
},
|
|
38
|
+
heartbeat_timeout: {
|
|
39
|
+
value: 3,
|
|
40
|
+
unit: "s"
|
|
41
|
+
},
|
|
42
|
+
retry_base: {
|
|
43
|
+
value: .5,
|
|
44
|
+
unit: "s"
|
|
45
|
+
},
|
|
46
|
+
retry_cap: {
|
|
47
|
+
value: 4,
|
|
48
|
+
unit: "s"
|
|
49
|
+
},
|
|
50
|
+
keepalive_idle: {
|
|
51
|
+
value: "infinite",
|
|
52
|
+
unit: "s"
|
|
53
|
+
},
|
|
54
|
+
max_connection_age: {
|
|
55
|
+
value: "infinite",
|
|
56
|
+
unit: "s"
|
|
57
|
+
},
|
|
58
|
+
close_bound: {
|
|
59
|
+
value: 2,
|
|
60
|
+
unit: "s"
|
|
61
|
+
},
|
|
62
|
+
retrans_giveup_time: {
|
|
63
|
+
value: 924.6,
|
|
64
|
+
unit: "s"
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
export { WS_CLIENT_STARTING_KNOBS, WS_CLIENT_STARTING_MISSES, WS_CLIENT_STARTING_POLL };
|
|
68
|
+
|
|
69
|
+
//# sourceMappingURL=starting.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"starting.js","names":[],"sources":["../../src/websocket/starting.ts"],"sourcesContent":["import { STARTING_POLL } from \"../client/core.ts\";\nimport type { Poll } from \"../timing.ts\";\nimport type { WsKnobs } from \"./client.ts\";\n\n/**\n * This poll is the poll of the checks that `WS_CLIENT_STARTING_KNOBS` fits. It is `STARTING_POLL` of\n * the core: each 5 s with a jitter of 20 %, and a timeout of 4 s (B6, O12). The poll does not depend on the driver.\n */\nexport const WS_CLIENT_STARTING_POLL: Poll = STARTING_POLL;\n\n/** This count is the heartbeat misses to start from: 1, as in the WS cells. The drop came 0.999 s to 1.0035 s after the ping with no pong. */\nexport const WS_CLIENT_STARTING_MISSES = 1;\n\n/**\n * These knobs are a declaration to start from, from what the WS cells measured on ws 8. The runtime\n * has no defaults: a service gives these knobs, or its own. Each value holds the borders that the cells measured:\n * - `connect_bound` 5 s: the connect timeout of DP44. ws sets no handshake timeout by default.\n * - `request_timeout` 9.5 s: in the slowest poll of 10 s (O13).\n * - `heartbeat_interval` 4 s: in the WST cells, a ping each 4 s kept a flow through a router that\n * forgets it at 5 s. A ping each 6 s did not (O03).\n * - `heartbeat_timeout` 3 s: a stall of 1 s with a pong timeout of 3 s dropped nothing. The detection is 4 s + 3 s = 7 s.\n * - `retry_base` 0.5 s and `retry_cap` 4 s: the reconnect of the cells, from 500 ms, doubling to 4 s.\n * The client adds a jitter up to the base. Thus the most delay is 4.5 s, in the slowest poll of 10 s.\n * - `keepalive_idle` \"infinite\": ws sets no keepalive, and the heartbeat refreshes an idle flow.\n * - `max_connection_age` \"infinite\": the client does not replace its connection at an age.\n * - `close_bound` 2 s: a close frame to a silent server gets no answer. The `closeTimeout` of ws is 30 s.\n * - `retrans_giveup_time` 924.6 s: the give-up of Linux at `tcp_retries2 = 15`.\n */\nexport const WS_CLIENT_STARTING_KNOBS: WsKnobs = {\n connect_bound: { value: 5, unit: \"s\" },\n request_timeout: { value: 9.5, unit: \"s\" },\n heartbeat_interval: { value: 4, unit: \"s\" },\n heartbeat_timeout: { value: 3, unit: \"s\" },\n retry_base: { value: 0.5, unit: \"s\" },\n retry_cap: { value: 4, unit: \"s\" },\n keepalive_idle: { value: \"infinite\", unit: \"s\" },\n max_connection_age: { value: \"infinite\", unit: \"s\" },\n close_bound: { value: 2, unit: \"s\" },\n retrans_giveup_time: { value: 924.6, unit: \"s\" },\n};\n"],"mappings":";;;;;;AAQA,MAAa,0BAAgC;;AAG7C,MAAa,4BAA4B;;;;;;;;;;;;;;;;AAiBzC,MAAa,2BAAoC;CAC/C,eAAe;EAAE,OAAO;EAAG,MAAM;CAAI;CACrC,iBAAiB;EAAE,OAAO;EAAK,MAAM;CAAI;CACzC,oBAAoB;EAAE,OAAO;EAAG,MAAM;CAAI;CAC1C,mBAAmB;EAAE,OAAO;EAAG,MAAM;CAAI;CACzC,YAAY;EAAE,OAAO;EAAK,MAAM;CAAI;CACpC,WAAW;EAAE,OAAO;EAAG,MAAM;CAAI;CACjC,gBAAgB;EAAE,OAAO;EAAY,MAAM;CAAI;CAC/C,oBAAoB;EAAE,OAAO;EAAY,MAAM;CAAI;CACnD,aAAa;EAAE,OAAO;EAAG,MAAM;CAAI;CACnC,qBAAqB;EAAE,OAAO;EAAO,MAAM;CAAI;AACjD"}
|