@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,153 @@
|
|
|
1
|
+
import { CallContext } from "../call-context.js";
|
|
2
|
+
import { Attempt, Client, ClientJoin, ClientKnobs, ClientOptions, ClientSpec, ClientStep, DialFn, RetryKnobs, SendOptions, Sent } from "../client/core.js";
|
|
3
|
+
import { Judge } from "../client/dial.js";
|
|
4
|
+
import { Operation } from "../operation.js";
|
|
5
|
+
import { GrpcConnectOptions, GrpcFactory, GrpcStatus } from "./connection.js";
|
|
6
|
+
import { Extent, Quantity } from "@mark1russell7/quantity";
|
|
7
|
+
/**
|
|
8
|
+
* These are the knobs of the client, each a time, by the names of the ordering law and of the gRPC
|
|
9
|
+
* cells. The runtime has no defaults, thus each knob is necessary. The constant
|
|
10
|
+
* `GRPC_CLIENT_STARTING_KNOBS` gives a declaration from the gRPC cells. The knobs that each client has come from the core.
|
|
11
|
+
*/
|
|
12
|
+
export interface GrpcKnobs extends ClientKnobs, RetryKnobs {
|
|
13
|
+
/** This time bounds the wait of the startup for a ready channel. The grpc-js driver has no connect timeout, and the wrapper cannot stop one connect. */
|
|
14
|
+
readonly connect_bound: Quantity;
|
|
15
|
+
/** This time is the deadline of each call, from its start. A second try ends in the same bound. The grpc-js driver sends it as `grpc-timeout`. */
|
|
16
|
+
readonly request_timeout: Quantity;
|
|
17
|
+
/** This time is the interval of the HTTP/2 PING of keepalive (`grpc.keepalive_time_ms`). "infinite" sends no PING, as grpc-js does at its defaults. */
|
|
18
|
+
readonly keepalive_time: Extent;
|
|
19
|
+
/** This time bounds the ACK of each PING (`grpc.keepalive_timeout_ms`). With no ACK, grpc-js ends the transport. */
|
|
20
|
+
readonly keepalive_timeout: Quantity;
|
|
21
|
+
/** This time with no call puts the channel in IDLE and closes its connection (`grpc.client_idle_timeout_ms`). The client then connects again. */
|
|
22
|
+
readonly client_idle_timeout: Quantity;
|
|
23
|
+
/**
|
|
24
|
+
* This time is the shortest interval of the PING that the server permits: `MinTime` of the
|
|
25
|
+
* enforcement policy of grpc-go. A shorter keepalive gets GOAWAY too_many_pings (O26). It is a fact of the server, not a knob of the client.
|
|
26
|
+
*/
|
|
27
|
+
readonly server_keepalive_min_time: Quantity;
|
|
28
|
+
/** This time is when the server or a proxy ends an idle connection with GOAWAY, or "infinite". The client must close first (O01). */
|
|
29
|
+
readonly server_idle_close: Extent;
|
|
30
|
+
/** This time is the first delay of grpc-js before a new try to connect (`grpc.initial_reconnect_backoff_ms`). */
|
|
31
|
+
readonly retry_base: Quantity;
|
|
32
|
+
/** This time is the most that one delay of grpc-js can be, before its jitter of 20 % (`grpc.max_reconnect_backoff_ms`). */
|
|
33
|
+
readonly retry_cap: Quantity;
|
|
34
|
+
/** The grpc-js driver sets no TCP keepalive on its socket: the PING of `keepalive_time` is its keepalive. Thus this knob must be "infinite". */
|
|
35
|
+
readonly keepalive_idle: Extent;
|
|
36
|
+
/** The client does not replace its connection at an age, thus this knob must be "infinite". */
|
|
37
|
+
readonly max_connection_age: Extent;
|
|
38
|
+
/** This time bounds the close at the shutdown: the calls in flight. At the bound, the client cancels each call, then closes the channel. */
|
|
39
|
+
readonly close_bound: Quantity;
|
|
40
|
+
}
|
|
41
|
+
/** A gRPC client spec is the declaration of one gRPC client: where it connects, and its knobs. */
|
|
42
|
+
export interface GrpcClientSpec extends ClientSpec<GrpcKnobs> {
|
|
43
|
+
/**
|
|
44
|
+
* True sends the PING of keepalive with no call in flight too (`grpc.keepalive_permit_without_calls`).
|
|
45
|
+
* The server must permit that (`PermitWithoutStream` of grpc-go), or it answers with GOAWAY too_many_pings (O26).
|
|
46
|
+
*/
|
|
47
|
+
readonly keepaliveWithoutCalls: boolean;
|
|
48
|
+
/** These headers go with each call, for example `authorization`. The metadata of a call adds to them. */
|
|
49
|
+
readonly metadata?: Readonly<Record<string, string>> | undefined;
|
|
50
|
+
/** This name is the service that the round-trip check asks the health service about. The default is "", the whole server. */
|
|
51
|
+
readonly healthService?: string | undefined;
|
|
52
|
+
/**
|
|
53
|
+
* These operations are the methods of the service, by their full path, with their idempotency. The
|
|
54
|
+
* client sends again only a method that this table names as idempotent. `grpcOperations` makes the
|
|
55
|
+
* table from the `idempotency_level` of each method in its proto.
|
|
56
|
+
*/
|
|
57
|
+
readonly operations?: ClientSpec<GrpcKnobs>["operations"];
|
|
58
|
+
}
|
|
59
|
+
/** These options make a client. Without them, it uses grpc-js, the real clock, and a dial with the HTTP/2 preface. */
|
|
60
|
+
export interface GrpcClientOptions extends ClientOptions<GrpcFactory> {
|
|
61
|
+
/**
|
|
62
|
+
* With this call context, each call gets the headers of the active context of its caller in its
|
|
63
|
+
* metadata, for example `traceparent`. The metadata of the spec and of the call stays. `callContext` of the entry `/otel` gives one.
|
|
64
|
+
*/
|
|
65
|
+
readonly callContext?: CallContext | undefined;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* A join is one generation of the client: each time that its channel becomes READY (D1, D2). The
|
|
69
|
+
* grpc-js driver gives no socket of its transport, thus the ends of the socket are null.
|
|
70
|
+
*/
|
|
71
|
+
export interface GrpcJoin extends ClientJoin {
|
|
72
|
+
/** This text is the target of the channel. */
|
|
73
|
+
readonly target: string;
|
|
74
|
+
}
|
|
75
|
+
/** These options tell how the client sends one call. */
|
|
76
|
+
export interface GrpcCallOptions extends SendOptions {
|
|
77
|
+
/** These headers go with this call, after the metadata of the spec. */
|
|
78
|
+
readonly metadata?: Readonly<Record<string, string>> | undefined;
|
|
79
|
+
}
|
|
80
|
+
/** A serving status is the status of a HealthCheckResponse of the health service (grpc.health.v1). */
|
|
81
|
+
export type GrpcServingStatus = "UNKNOWN" | "SERVING" | "NOT_SERVING" | "SERVICE_UNKNOWN";
|
|
82
|
+
/** A gRPC client is a dependency of a service: its declaration, its handle, its checks and its calls. */
|
|
83
|
+
export interface GrpcClient extends Client<ClientStep, GrpcJoin> {
|
|
84
|
+
/** This text is the state of the client, as `GRPC_CLIENT_MACHINE` names it. */
|
|
85
|
+
readonly status: string;
|
|
86
|
+
/**
|
|
87
|
+
* This method sends one unary call, and waits for its status. `request` holds the bytes of the
|
|
88
|
+
* request message, and an OK status gives the bytes of the response message. The client sends again
|
|
89
|
+
* only an idempotent method, one time at most, after an outcome that is not certain.
|
|
90
|
+
*/
|
|
91
|
+
call(method: string, request: Buffer, options?: GrpcCallOptions): Promise<Sent<Buffer>>;
|
|
92
|
+
/** This method sends one Check of the health service (grpc.health.v1), and gives the serving status of the reply. */
|
|
93
|
+
health(service?: string, options?: SendOptions): Promise<Sent<GrpcServingStatus>>;
|
|
94
|
+
}
|
|
95
|
+
/** The names of the status codes of gRPC, by their value. */
|
|
96
|
+
export declare const GRPC_CODES: readonly ["OK", "CANCELLED", "UNKNOWN", "INVALID_ARGUMENT", "DEADLINE_EXCEEDED", "NOT_FOUND", "ALREADY_EXISTS", "PERMISSION_DENIED", "RESOURCE_EXHAUSTED", "FAILED_PRECONDITION", "ABORTED", "OUT_OF_RANGE", "UNIMPLEMENTED", "INTERNAL", "UNAVAILABLE", "DATA_LOSS", "UNAUTHENTICATED"];
|
|
97
|
+
/** This function gives the name of a status code, for example "UNAVAILABLE". */
|
|
98
|
+
export declare const codeName: (code: number) => string;
|
|
99
|
+
/**
|
|
100
|
+
* This function gives the outcome of one call from its status:
|
|
101
|
+
* - OK is `ok`.
|
|
102
|
+
* - A code that tells that the server refused the call is a certain error: `reply` is true.
|
|
103
|
+
* - A status that tells that the call did not leave the client is a certain error with `reply` false.
|
|
104
|
+
* - Each other status is indeterminate: CANCELLED, UNKNOWN, DEADLINE_EXCEEDED, RESOURCE_EXHAUSTED,
|
|
105
|
+
* INTERNAL, UNAVAILABLE and DATA_LOSS can come after the server applied the call.
|
|
106
|
+
*/
|
|
107
|
+
export declare const grpcOutcome: (status: GrpcStatus, response: Buffer | undefined) => Attempt<Buffer>;
|
|
108
|
+
/** This method is the Check of the health service. Its request names a service, and its response gives a serving status. */
|
|
109
|
+
export declare const HEALTH_CHECK = "/grpc.health.v1.Health/Check";
|
|
110
|
+
/** These operations are in each table: the Check of the health service has no side effects. */
|
|
111
|
+
export declare const GRPC_OPERATIONS: Readonly<Record<string, Operation>>;
|
|
112
|
+
/** An idempotency level is the option `idempotency_level` of a method in its proto (descriptor.proto). */
|
|
113
|
+
export type GrpcIdempotencyLevel = "IDEMPOTENCY_UNKNOWN" | "NO_SIDE_EFFECTS" | "IDEMPOTENT";
|
|
114
|
+
/**
|
|
115
|
+
* This function makes a table of operations from the idempotency level of each method, by its full
|
|
116
|
+
* path. NO_SIDE_EFFECTS and IDEMPOTENT are idempotent. IDEMPOTENCY_UNKNOWN, the default of a proto, is not.
|
|
117
|
+
*/
|
|
118
|
+
export declare const grpcOperations: (levels: Readonly<Record<string, GrpcIdempotencyLevel>>) => Record<string, Operation>;
|
|
119
|
+
/** This function gives the bytes of a HealthCheckRequest. The service "" is the whole server, and its message is empty. */
|
|
120
|
+
export declare const healthRequest: (service: string) => Buffer;
|
|
121
|
+
/** This function gives the status of a HealthCheckResponse, or null when the bytes are not one. An empty message is UNKNOWN. */
|
|
122
|
+
export declare const healthStatus: (bytes: Buffer) => GrpcServingStatus | null;
|
|
123
|
+
/** This function gives the problems of a spec: the knobs that the client cannot use. */
|
|
124
|
+
export declare const specProblems: (name: string, spec: GrpcClientSpec) => string[];
|
|
125
|
+
/** This function gives the target of a channel from a spec: the host and the port, for the DNS resolver of grpc-js. */
|
|
126
|
+
export declare const grpcTarget: (spec: Pick<GrpcClientSpec, "host" | "port">) => string;
|
|
127
|
+
/**
|
|
128
|
+
* This function gives the arguments of `new Client` from a spec. Each timer of grpc-js comes from the
|
|
129
|
+
* declaration. The retries of grpc-js are off, and the resolver gives no service config.
|
|
130
|
+
*/
|
|
131
|
+
export declare const grpcOptions: (spec: GrpcClientSpec) => GrpcConnectOptions;
|
|
132
|
+
/** These are the bytes of the dial: the connection preface of the client (RFC 9113 §3.4), and a SETTINGS frame with no setting. */
|
|
133
|
+
export declare const HTTP2_PREFACE: Buffer;
|
|
134
|
+
/**
|
|
135
|
+
* This judge reads the first frame of the server. Only a SETTINGS frame on stream 0, with no ACK,
|
|
136
|
+
* passes: RFC 9113 §3.4 makes it the first frame of an HTTP/2 server. An HTTP/1.1 server answers with a status line.
|
|
137
|
+
*/
|
|
138
|
+
export declare const settingsJudge: Judge;
|
|
139
|
+
/** This dial opens a new TCP connection, sends the HTTP/2 preface, and waits for the SETTINGS frame of the server. The dial then destroys its socket. */
|
|
140
|
+
export declare const grpcDial: DialFn;
|
|
141
|
+
/**
|
|
142
|
+
* This function makes a gRPC client, a dependency of a service over grpc-js 1.14.
|
|
143
|
+
* - It has one channel for its life. Each time that the channel becomes READY is one generation.
|
|
144
|
+
* - The grpc-js driver connects again by itself, after its own backoff. The client connects an IDLE channel again at once.
|
|
145
|
+
* - A call is one unary call, until its status. Its deadline is the time that is left in `request_timeout`.
|
|
146
|
+
* - It tells the outcome of a call in three values from its status code (C8).
|
|
147
|
+
* - The retries of grpc-js are off, thus only the core sends a call again.
|
|
148
|
+
* - Its keepalive is the HTTP/2 PING of grpc-js. It records the target of each generation (D1).
|
|
149
|
+
*
|
|
150
|
+
* These parts come from the core of the clients: the outcomes, the second try and the wait for a ready client.
|
|
151
|
+
* The calls in flight, the bounded close and the checks come from the core too. This entry gives what grpc-js does in its own way.
|
|
152
|
+
*/
|
|
153
|
+
export declare const grpcClient: (name: string, spec: GrpcClientSpec, options?: GrpcClientOptions) => GrpcClient;
|
|
@@ -0,0 +1,474 @@
|
|
|
1
|
+
import { realClock } from "../clock.js";
|
|
2
|
+
import { ageProblems, attachClient, clientBounds, clientProblems, clientRecorder, dialCheck, finiteMs, idleCloseProblem, inFlight, localStateCheck, message, ms, notSent, operationTable, readyWait, retryProblems, roundTripCheck, sendWithReissue, socketEnds, stepChecks, timeProblems, wholeProblems, withinBound, wrapperTimerProblems, zeroProblems } from "../client/core.js";
|
|
3
|
+
import { authority, helloDial } from "../client/dial.js";
|
|
4
|
+
import { NEVER } from "../client/meets.js";
|
|
5
|
+
import { heartbeatDetection } from "../timing.js";
|
|
6
|
+
import { nodeGrpc } from "./connection.js";
|
|
7
|
+
import { grpcMeetings } from "./meets.js";
|
|
8
|
+
// src/grpc/client.ts
|
|
9
|
+
/** The names of the status codes of gRPC, by their value. */
|
|
10
|
+
const GRPC_CODES = [
|
|
11
|
+
"OK",
|
|
12
|
+
"CANCELLED",
|
|
13
|
+
"UNKNOWN",
|
|
14
|
+
"INVALID_ARGUMENT",
|
|
15
|
+
"DEADLINE_EXCEEDED",
|
|
16
|
+
"NOT_FOUND",
|
|
17
|
+
"ALREADY_EXISTS",
|
|
18
|
+
"PERMISSION_DENIED",
|
|
19
|
+
"RESOURCE_EXHAUSTED",
|
|
20
|
+
"FAILED_PRECONDITION",
|
|
21
|
+
"ABORTED",
|
|
22
|
+
"OUT_OF_RANGE",
|
|
23
|
+
"UNIMPLEMENTED",
|
|
24
|
+
"INTERNAL",
|
|
25
|
+
"UNAVAILABLE",
|
|
26
|
+
"DATA_LOSS",
|
|
27
|
+
"UNAUTHENTICATED"
|
|
28
|
+
];
|
|
29
|
+
/**
|
|
30
|
+
* These codes are certain errors: each one tells that the server or a proxy refused the call, and did
|
|
31
|
+
* not apply it. A proxy that answers 401, 403 or 404 gives UNAUTHENTICATED, PERMISSION_DENIED or UNIMPLEMENTED.
|
|
32
|
+
*/
|
|
33
|
+
const CERTAIN = /* @__PURE__ */ new Set([
|
|
34
|
+
3,
|
|
35
|
+
5,
|
|
36
|
+
6,
|
|
37
|
+
7,
|
|
38
|
+
9,
|
|
39
|
+
10,
|
|
40
|
+
11,
|
|
41
|
+
12,
|
|
42
|
+
16
|
|
43
|
+
]);
|
|
44
|
+
/**
|
|
45
|
+
* These statuses of grpc-js tell that the call did not leave the client. A status with another
|
|
46
|
+
* details text of the same code can come after the send, thus it is indeterminate:
|
|
47
|
+
* - UNAVAILABLE "No connection established": the pick of a channel in TRANSIENT_FAILURE (picker.ts:105).
|
|
48
|
+
* - UNAVAILABLE "Name resolution failed": the resolver found no address (resolver-dns.ts:119).
|
|
49
|
+
* - UNAVAILABLE "Stream refused by server": RST_STREAM REFUSED_STREAM. The server did not process the stream (RFC 9113 §8.7).
|
|
50
|
+
* - INTERNAL "Failed to start HTTP/2 stream": the stream did not start (load-balancing-call.ts:281).
|
|
51
|
+
* - DEADLINE_EXCEEDED with "Waiting for LB pick" or "waiting for name resolution": the deadline came before a stream.
|
|
52
|
+
*/
|
|
53
|
+
const NOT_SENT = [
|
|
54
|
+
[14, /^No connection established/],
|
|
55
|
+
[14, /^Name resolution failed/],
|
|
56
|
+
[14, /^Stream refused by server$/],
|
|
57
|
+
[13, /^Failed to start HTTP\/2 stream/],
|
|
58
|
+
[4, /(^|,)(Waiting for LB pick|waiting for name resolution)(,|$)/]
|
|
59
|
+
];
|
|
60
|
+
/** This function gives the name of a status code, for example "UNAVAILABLE". */
|
|
61
|
+
const codeName = (code) => GRPC_CODES[code] ?? `code ${code}`;
|
|
62
|
+
/**
|
|
63
|
+
* This function gives the outcome of one call from its status:
|
|
64
|
+
* - OK is `ok`.
|
|
65
|
+
* - A code that tells that the server refused the call is a certain error: `reply` is true.
|
|
66
|
+
* - A status that tells that the call did not leave the client is a certain error with `reply` false.
|
|
67
|
+
* - Each other status is indeterminate: CANCELLED, UNKNOWN, DEADLINE_EXCEEDED, RESOURCE_EXHAUSTED,
|
|
68
|
+
* INTERNAL, UNAVAILABLE and DATA_LOSS can come after the server applied the call.
|
|
69
|
+
*/
|
|
70
|
+
const grpcOutcome = (status, response) => {
|
|
71
|
+
if (status.code === 0) return {
|
|
72
|
+
outcome: "ok",
|
|
73
|
+
value: response ?? Buffer.alloc(0)
|
|
74
|
+
};
|
|
75
|
+
const error = `${codeName(status.code)}: ${status.details}`;
|
|
76
|
+
if (CERTAIN.has(status.code)) return {
|
|
77
|
+
outcome: "error",
|
|
78
|
+
error,
|
|
79
|
+
reply: true
|
|
80
|
+
};
|
|
81
|
+
if (NOT_SENT.some(([code, details]) => code === status.code && details.test(status.details))) return notSent(`${error} (the call did not leave the client)`);
|
|
82
|
+
return {
|
|
83
|
+
outcome: "indeterminate",
|
|
84
|
+
error
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
/** This method is the Check of the health service. Its request names a service, and its response gives a serving status. */
|
|
88
|
+
const HEALTH_CHECK = "/grpc.health.v1.Health/Check";
|
|
89
|
+
/** These operations are in each table: the Check of the health service has no side effects. */
|
|
90
|
+
const GRPC_OPERATIONS = { [HEALTH_CHECK]: { idempotent: true } };
|
|
91
|
+
/**
|
|
92
|
+
* This function makes a table of operations from the idempotency level of each method, by its full
|
|
93
|
+
* path. NO_SIDE_EFFECTS and IDEMPOTENT are idempotent. IDEMPOTENCY_UNKNOWN, the default of a proto, is not.
|
|
94
|
+
*/
|
|
95
|
+
const grpcOperations = (levels) => Object.fromEntries(Object.entries(levels).map(([method, level]) => [method, { idempotent: level !== "IDEMPOTENCY_UNKNOWN" }]));
|
|
96
|
+
/** This function gives the bytes of a varint of protobuf. */
|
|
97
|
+
const varint = (value) => {
|
|
98
|
+
const bytes = [];
|
|
99
|
+
let rest = value;
|
|
100
|
+
while (rest > 127) {
|
|
101
|
+
bytes.push(rest & 127 | 128);
|
|
102
|
+
rest = Math.floor(rest / 128);
|
|
103
|
+
}
|
|
104
|
+
bytes.push(rest);
|
|
105
|
+
return Buffer.from(bytes);
|
|
106
|
+
};
|
|
107
|
+
/** This function gives the bytes of a HealthCheckRequest. The service "" is the whole server, and its message is empty. */
|
|
108
|
+
const healthRequest = (service) => {
|
|
109
|
+
if (service === "") return Buffer.alloc(0);
|
|
110
|
+
const name = Buffer.from(service, "utf8");
|
|
111
|
+
return Buffer.concat([
|
|
112
|
+
Buffer.from([10]),
|
|
113
|
+
varint(name.length),
|
|
114
|
+
name
|
|
115
|
+
]);
|
|
116
|
+
};
|
|
117
|
+
const SERVING = [
|
|
118
|
+
"UNKNOWN",
|
|
119
|
+
"SERVING",
|
|
120
|
+
"NOT_SERVING",
|
|
121
|
+
"SERVICE_UNKNOWN"
|
|
122
|
+
];
|
|
123
|
+
/** This function gives the status of a HealthCheckResponse, or null when the bytes are not one. An empty message is UNKNOWN. */
|
|
124
|
+
const healthStatus = (bytes) => {
|
|
125
|
+
let at = 0;
|
|
126
|
+
let status = 0;
|
|
127
|
+
const read = () => {
|
|
128
|
+
let value = 0;
|
|
129
|
+
for (let shift = 0; shift < 35; shift += 7) {
|
|
130
|
+
const byte = bytes[at];
|
|
131
|
+
if (byte === void 0) return null;
|
|
132
|
+
at += 1;
|
|
133
|
+
value += (byte & 127) * 2 ** shift;
|
|
134
|
+
if ((byte & 128) === 0) return value;
|
|
135
|
+
}
|
|
136
|
+
return null;
|
|
137
|
+
};
|
|
138
|
+
while (at < bytes.length) {
|
|
139
|
+
const tag = read();
|
|
140
|
+
if (tag === null) return null;
|
|
141
|
+
const wire = tag & 7;
|
|
142
|
+
if (wire === 0) {
|
|
143
|
+
const value = read();
|
|
144
|
+
if (value === null) return null;
|
|
145
|
+
if (tag >> 3 === 1) status = value;
|
|
146
|
+
} else if (wire === 2) {
|
|
147
|
+
const length = read();
|
|
148
|
+
if (length === null || at + length > bytes.length) return null;
|
|
149
|
+
at += length;
|
|
150
|
+
} else if (wire === 1 || wire === 5) {
|
|
151
|
+
at += wire === 1 ? 8 : 4;
|
|
152
|
+
if (at > bytes.length) return null;
|
|
153
|
+
} else return null;
|
|
154
|
+
}
|
|
155
|
+
return SERVING[status] ?? null;
|
|
156
|
+
};
|
|
157
|
+
/** The longest timer of Node, in milliseconds. A longer delay starts at 1 ms, thus grpc-js cannot take it. */
|
|
158
|
+
const LONGEST_TIMER = 2147483647;
|
|
159
|
+
/** This function gives the problems of the times that grpc-js gives to `setTimeout` with no check: each one is at most the longest timer. */
|
|
160
|
+
const longestTimerProblems = (name, knobs, names) => names.flatMap((knob) => {
|
|
161
|
+
const amount = knobs[knob];
|
|
162
|
+
return amount.value !== "infinite" && ms(amount) > LONGEST_TIMER ? [`${name}'s ${knob} is above ${LONGEST_TIMER} ms, the longest timer of Node`] : [];
|
|
163
|
+
});
|
|
164
|
+
/** This function gives the problems of a spec: the knobs that the client cannot use. */
|
|
165
|
+
const specProblems = (name, spec) => {
|
|
166
|
+
const { knobs } = spec;
|
|
167
|
+
const timers = [
|
|
168
|
+
"keepalive_time",
|
|
169
|
+
"keepalive_timeout",
|
|
170
|
+
"client_idle_timeout",
|
|
171
|
+
"retry_base",
|
|
172
|
+
"retry_cap"
|
|
173
|
+
];
|
|
174
|
+
const problems = [
|
|
175
|
+
...timeProblems(name, knobs),
|
|
176
|
+
...wrapperTimerProblems(name, knobs, {
|
|
177
|
+
connect_bound: "the wait of the startup for a ready channel",
|
|
178
|
+
request_timeout: "a call"
|
|
179
|
+
}),
|
|
180
|
+
...zeroProblems(name, "grpc-js", knobs, { open: ["keepalive_time"] }),
|
|
181
|
+
...wholeProblems(name, knobs, { millis: timers }),
|
|
182
|
+
...longestTimerProblems(name, knobs, timers),
|
|
183
|
+
...retryProblems(name, knobs),
|
|
184
|
+
...ageProblems(name, knobs, "grpc-js does not replace its connection at an age")
|
|
185
|
+
];
|
|
186
|
+
for (const knob of [
|
|
187
|
+
"keepalive_timeout",
|
|
188
|
+
"client_idle_timeout",
|
|
189
|
+
"retry_base",
|
|
190
|
+
"retry_cap"
|
|
191
|
+
]) if (finiteMs(knobs[knob]) === void 0 || !(ms(knobs[knob]) > 0)) problems.push(`${name}'s ${knob} is not a finite time above zero`);
|
|
192
|
+
if (ms(knobs.client_idle_timeout) < 1e3) problems.push(`${name}'s client_idle_timeout is below 1 s: grpc-js raises it to 1 s`);
|
|
193
|
+
if (knobs.keepalive_idle.value !== "infinite") problems.push(`${name}'s keepalive_idle is not "infinite": grpc-js sets no TCP keepalive, and the PING of keepalive_time is its keepalive`);
|
|
194
|
+
if (spec.password !== void 0) problems.push(`${name} takes no password: give the credentials in metadata, for example authorization`);
|
|
195
|
+
return problems;
|
|
196
|
+
};
|
|
197
|
+
/** This function gives the target of a channel from a spec: the host and the port, for the DNS resolver of grpc-js. */
|
|
198
|
+
const grpcTarget = (spec) => authority(spec.host, spec.port);
|
|
199
|
+
/**
|
|
200
|
+
* This function gives the arguments of `new Client` from a spec. Each timer of grpc-js comes from the
|
|
201
|
+
* declaration. The retries of grpc-js are off, and the resolver gives no service config.
|
|
202
|
+
*/
|
|
203
|
+
const grpcOptions = (spec) => {
|
|
204
|
+
const { knobs } = spec;
|
|
205
|
+
const keepalive = finiteMs(knobs.keepalive_time);
|
|
206
|
+
return {
|
|
207
|
+
target: grpcTarget(spec),
|
|
208
|
+
options: {
|
|
209
|
+
"grpc.enable_retries": 0,
|
|
210
|
+
"grpc.service_config_disable_resolution": 1,
|
|
211
|
+
...keepalive === void 0 ? {} : { "grpc.keepalive_time_ms": keepalive },
|
|
212
|
+
"grpc.keepalive_timeout_ms": ms(knobs.keepalive_timeout),
|
|
213
|
+
"grpc.keepalive_permit_without_calls": spec.keepaliveWithoutCalls ? 1 : 0,
|
|
214
|
+
"grpc.client_idle_timeout_ms": ms(knobs.client_idle_timeout),
|
|
215
|
+
"grpc.initial_reconnect_backoff_ms": ms(knobs.retry_base),
|
|
216
|
+
"grpc.max_reconnect_backoff_ms": ms(knobs.retry_cap)
|
|
217
|
+
}
|
|
218
|
+
};
|
|
219
|
+
};
|
|
220
|
+
/** These are the bytes of the dial: the connection preface of the client (RFC 9113 §3.4), and a SETTINGS frame with no setting. */
|
|
221
|
+
const HTTP2_PREFACE = Buffer.concat([Buffer.from("PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n", "latin1"), Buffer.from([
|
|
222
|
+
0,
|
|
223
|
+
0,
|
|
224
|
+
0,
|
|
225
|
+
4,
|
|
226
|
+
0,
|
|
227
|
+
0,
|
|
228
|
+
0,
|
|
229
|
+
0,
|
|
230
|
+
0
|
|
231
|
+
])]);
|
|
232
|
+
/**
|
|
233
|
+
* This judge reads the first frame of the server. Only a SETTINGS frame on stream 0, with no ACK,
|
|
234
|
+
* passes: RFC 9113 §3.4 makes it the first frame of an HTTP/2 server. An HTTP/1.1 server answers with a status line.
|
|
235
|
+
*/
|
|
236
|
+
const settingsJudge = (received) => {
|
|
237
|
+
if (received.length < 9) return "more";
|
|
238
|
+
const type = received[3];
|
|
239
|
+
const flags = received[4];
|
|
240
|
+
const stream = received.readUInt32BE(5) & 2147483647;
|
|
241
|
+
return type === 4 && (flags & 1) === 0 && stream === 0 ? null : /* @__PURE__ */ new Error(`the server did not answer the HTTP/2 preface with a SETTINGS frame: its first bytes are ${received.subarray(0, 9).toString("hex")}`);
|
|
242
|
+
};
|
|
243
|
+
/** This dial opens a new TCP connection, sends the HTTP/2 preface, and waits for the SETTINGS frame of the server. The dial then destroys its socket. */
|
|
244
|
+
const grpcDial = helloDial(HTTP2_PREFACE, settingsJudge);
|
|
245
|
+
/**
|
|
246
|
+
* This function makes a gRPC client, a dependency of a service over grpc-js 1.14.
|
|
247
|
+
* - It has one channel for its life. Each time that the channel becomes READY is one generation.
|
|
248
|
+
* - The grpc-js driver connects again by itself, after its own backoff. The client connects an IDLE channel again at once.
|
|
249
|
+
* - A call is one unary call, until its status. Its deadline is the time that is left in `request_timeout`.
|
|
250
|
+
* - It tells the outcome of a call in three values from its status code (C8).
|
|
251
|
+
* - The retries of grpc-js are off, thus only the core sends a call again.
|
|
252
|
+
* - Its keepalive is the HTTP/2 PING of grpc-js. It records the target of each generation (D1).
|
|
253
|
+
*
|
|
254
|
+
* These parts come from the core of the clients: the outcomes, the second try and the wait for a ready client.
|
|
255
|
+
* The calls in flight, the bounded close and the checks come from the core too. This entry gives what grpc-js does in its own way.
|
|
256
|
+
*/
|
|
257
|
+
const grpcClient = (name, spec, options = {}) => {
|
|
258
|
+
const problems = specProblems(name, spec);
|
|
259
|
+
if (problems.length > 0) throw new Error(problems.join("; "));
|
|
260
|
+
const { knobs } = spec;
|
|
261
|
+
const clock = options.clock ?? realClock;
|
|
262
|
+
const create = options.create ?? nodeGrpc;
|
|
263
|
+
const dial = options.dial ?? grpcDial;
|
|
264
|
+
const operations = operationTable(GRPC_OPERATIONS, spec.operations);
|
|
265
|
+
const requestTimeout = ms(knobs.request_timeout);
|
|
266
|
+
const target = grpcTarget(spec);
|
|
267
|
+
let status = "none";
|
|
268
|
+
let channel = null;
|
|
269
|
+
let settled = null;
|
|
270
|
+
const joins = [];
|
|
271
|
+
const flight = inFlight();
|
|
272
|
+
const readied = readyWait(clock, () => status === "ready");
|
|
273
|
+
const emit = clientRecorder(options.record, clock, name);
|
|
274
|
+
const record = (on, to = status, detail) => {
|
|
275
|
+
const from = status;
|
|
276
|
+
status = to;
|
|
277
|
+
emit(from, to, on, detail);
|
|
278
|
+
};
|
|
279
|
+
const closing = () => status === "closing" || status === "end";
|
|
280
|
+
/** This function follows one state of the channel. The grpc-js driver ends each call in flight by itself when its transport ends. */
|
|
281
|
+
const follow = (c, state) => {
|
|
282
|
+
if (c !== channel || closing()) return;
|
|
283
|
+
if (state === "READY") {
|
|
284
|
+
if (status === "ready") return;
|
|
285
|
+
const generation = joins.length + 1;
|
|
286
|
+
joins.push({
|
|
287
|
+
generation,
|
|
288
|
+
at: clock.now(),
|
|
289
|
+
target,
|
|
290
|
+
...socketEnds(void 0)
|
|
291
|
+
});
|
|
292
|
+
record("join", "ready", `generation ${generation}, ${target}`);
|
|
293
|
+
readied.wake();
|
|
294
|
+
settled?.();
|
|
295
|
+
} else if (state === "TRANSIENT_FAILURE") {
|
|
296
|
+
if (status === "failing") return;
|
|
297
|
+
record("connect.failed", "failing", "the channel is in TRANSIENT_FAILURE: grpc-js connects again after its backoff");
|
|
298
|
+
settled?.();
|
|
299
|
+
} else if (state === "CONNECTING") {
|
|
300
|
+
if (status !== "connecting") record("channel.connecting", "connecting", target);
|
|
301
|
+
} else if (state === "IDLE") {
|
|
302
|
+
if (status === "ready") record("connection.end", "idle", "the transport ended: a GOAWAY, a reset, a FIN, the keepalive, or client_idle_timeout");
|
|
303
|
+
else if (status !== "idle") record("channel.idle", "idle", "the channel is IDLE");
|
|
304
|
+
c.state(true);
|
|
305
|
+
}
|
|
306
|
+
};
|
|
307
|
+
/** This function watches the state of the channel. It watches again before it follows, thus no change goes away. */
|
|
308
|
+
const watch = (c, current) => c.watch(current, () => {
|
|
309
|
+
if (c !== channel || closing()) return;
|
|
310
|
+
const next = c.state(false);
|
|
311
|
+
if (next !== "SHUTDOWN") watch(c, next);
|
|
312
|
+
follow(c, next);
|
|
313
|
+
});
|
|
314
|
+
/** This function gives the channel for a call, or the reason that the call does not leave the client. */
|
|
315
|
+
const usable = (signal) => {
|
|
316
|
+
if (status === "none") return notSent(`${name} has not connected`);
|
|
317
|
+
if (status !== "ready" || channel === null) return notSent(`${name} is ${status}, not ready: the call did not leave the client`);
|
|
318
|
+
if (signal?.aborted) return notSent("the caller aborted the call before it left the client");
|
|
319
|
+
return channel;
|
|
320
|
+
};
|
|
321
|
+
/** This function makes one try of a call: the unary call until its status, with the deadline that is left. */
|
|
322
|
+
const attempt = (method, request, metadata, timeout, signal) => {
|
|
323
|
+
const c = usable(signal);
|
|
324
|
+
if ("outcome" in c) return Promise.resolve(c);
|
|
325
|
+
if (!(timeout > 0)) return Promise.resolve(notSent("no time is left in request_timeout"));
|
|
326
|
+
let handle = null;
|
|
327
|
+
let ended = false;
|
|
328
|
+
return flight.track(signal, "the caller abandoned the call after it left the client", (settle) => {
|
|
329
|
+
try {
|
|
330
|
+
handle = c.unary(method, request, metadata, timeout, (given, response) => {
|
|
331
|
+
ended = true;
|
|
332
|
+
settle(grpcOutcome(given, response));
|
|
333
|
+
});
|
|
334
|
+
} catch (error) {
|
|
335
|
+
ended = true;
|
|
336
|
+
settle(notSent(message(error)));
|
|
337
|
+
}
|
|
338
|
+
}, () => {
|
|
339
|
+
if (!ended) handle?.cancel();
|
|
340
|
+
});
|
|
341
|
+
};
|
|
342
|
+
const call = (method, request, callOptions = {}) => {
|
|
343
|
+
const started = clock.now();
|
|
344
|
+
const metadata = {
|
|
345
|
+
...options.callContext?.headers(),
|
|
346
|
+
...spec.metadata,
|
|
347
|
+
...callOptions.metadata
|
|
348
|
+
};
|
|
349
|
+
return sendWithReissue({
|
|
350
|
+
clock,
|
|
351
|
+
bound: requestTimeout,
|
|
352
|
+
operation: operations[method],
|
|
353
|
+
options: callOptions,
|
|
354
|
+
attempt: (signal) => attempt(method, request, metadata, requestTimeout - (clock.now() - started), signal),
|
|
355
|
+
beforeAgain: (left, signal) => readied.wait(left, signal),
|
|
356
|
+
onReissue: () => record("command.reissue", status, method)
|
|
357
|
+
});
|
|
358
|
+
};
|
|
359
|
+
const health = async (service = "", sendOptions = {}) => {
|
|
360
|
+
const sent = await call(HEALTH_CHECK, healthRequest(service), sendOptions);
|
|
361
|
+
if (sent.outcome !== "ok") return sent;
|
|
362
|
+
const serving = healthStatus(sent.value);
|
|
363
|
+
return serving === null ? {
|
|
364
|
+
outcome: "error",
|
|
365
|
+
error: "the response is not a HealthCheckResponse",
|
|
366
|
+
reply: true,
|
|
367
|
+
attempts: sent.attempts
|
|
368
|
+
} : {
|
|
369
|
+
outcome: "ok",
|
|
370
|
+
value: serving,
|
|
371
|
+
attempts: sent.attempts
|
|
372
|
+
};
|
|
373
|
+
};
|
|
374
|
+
const handle = {
|
|
375
|
+
async connect(signal) {
|
|
376
|
+
if (signal.aborted) throw new Error(`${name}: the service stopped before the connect`);
|
|
377
|
+
record("status.connecting", "connecting", target);
|
|
378
|
+
let c;
|
|
379
|
+
try {
|
|
380
|
+
c = await create(grpcOptions(spec));
|
|
381
|
+
} catch (error) {
|
|
382
|
+
record("connect.failed", "failing", message(error));
|
|
383
|
+
throw error;
|
|
384
|
+
}
|
|
385
|
+
if (closing()) {
|
|
386
|
+
c.close();
|
|
387
|
+
return;
|
|
388
|
+
}
|
|
389
|
+
channel = c;
|
|
390
|
+
const first = new Promise((resolve) => settled = resolve);
|
|
391
|
+
const now = c.state(true);
|
|
392
|
+
watch(c, now);
|
|
393
|
+
if (now !== "IDLE") follow(c, now);
|
|
394
|
+
await withinBound(clock, ms(knobs.connect_bound), first);
|
|
395
|
+
settled = null;
|
|
396
|
+
},
|
|
397
|
+
async close() {
|
|
398
|
+
if (status === "none" || closing()) return;
|
|
399
|
+
record("close.request", "closing");
|
|
400
|
+
settled?.();
|
|
401
|
+
const c = channel;
|
|
402
|
+
if (c !== null) {
|
|
403
|
+
if (!await withinBound(clock, ms(knobs.close_bound), flight.idle())) {
|
|
404
|
+
record("close.bound", "closing");
|
|
405
|
+
record("close.destroy", "closing", `${flight.size} calls in flight`);
|
|
406
|
+
flight.settleAll("the client closed with the call in flight");
|
|
407
|
+
}
|
|
408
|
+
c.close();
|
|
409
|
+
}
|
|
410
|
+
channel = null;
|
|
411
|
+
flight.settleAll("the client closed with the call in flight");
|
|
412
|
+
record("status.end", "end");
|
|
413
|
+
}
|
|
414
|
+
};
|
|
415
|
+
const keepalive = finiteMs(knobs.keepalive_time);
|
|
416
|
+
const declaration = {
|
|
417
|
+
system: spec.system,
|
|
418
|
+
knobs: {
|
|
419
|
+
connect_bound: knobs.connect_bound,
|
|
420
|
+
request_timeout: knobs.request_timeout,
|
|
421
|
+
keepalive_time: knobs.keepalive_time,
|
|
422
|
+
keepalive_timeout: knobs.keepalive_timeout,
|
|
423
|
+
heartbeat_detection_time: heartbeatDetection(knobs.keepalive_time, knobs.keepalive_timeout, 1),
|
|
424
|
+
client_idle_timeout: knobs.client_idle_timeout,
|
|
425
|
+
retry_base: knobs.retry_base,
|
|
426
|
+
retry_cap: knobs.retry_cap,
|
|
427
|
+
keepalive_idle: knobs.keepalive_idle,
|
|
428
|
+
idle_refresh_interval: spec.keepaliveWithoutCalls && keepalive !== void 0 ? knobs.keepalive_time : NEVER,
|
|
429
|
+
max_connection_age: knobs.max_connection_age,
|
|
430
|
+
close_bound: knobs.close_bound,
|
|
431
|
+
retrans_giveup_time: knobs.retrans_giveup_time
|
|
432
|
+
},
|
|
433
|
+
operations
|
|
434
|
+
};
|
|
435
|
+
/** The round-trip check passes only for SERVING: a health service that answers NOT_SERVING fails it, as a 5xx fails the HTTP check. */
|
|
436
|
+
const roundTrip = async (sendOptions) => {
|
|
437
|
+
const sent = await health(spec.healthService ?? "", sendOptions);
|
|
438
|
+
return sent.outcome === "ok" && sent.value !== "SERVING" ? {
|
|
439
|
+
outcome: "error",
|
|
440
|
+
error: `the health service answered ${sent.value}`,
|
|
441
|
+
reply: true,
|
|
442
|
+
attempts: sent.attempts
|
|
443
|
+
} : sent;
|
|
444
|
+
};
|
|
445
|
+
const checks = (checkOptions) => stepChecks(name, checkOptions, {
|
|
446
|
+
"local-state": localStateCheck(() => status === "ready"),
|
|
447
|
+
"round-trip": roundTripCheck(roundTrip),
|
|
448
|
+
dial: dialCheck(dial, spec.host, spec.port)
|
|
449
|
+
});
|
|
450
|
+
return {
|
|
451
|
+
name,
|
|
452
|
+
declaration,
|
|
453
|
+
handle,
|
|
454
|
+
meets: grpcMeetings(name, knobs, spec.keepaliveWithoutCalls),
|
|
455
|
+
get status() {
|
|
456
|
+
return status;
|
|
457
|
+
},
|
|
458
|
+
joins,
|
|
459
|
+
call,
|
|
460
|
+
health,
|
|
461
|
+
checks,
|
|
462
|
+
attach: (svc, checkOptions) => attachClient(svc, name, declaration, handle, checks(checkOptions)),
|
|
463
|
+
problems(description) {
|
|
464
|
+
const found = clientProblems(name, description, clientBounds(knobs));
|
|
465
|
+
const idle = idleCloseProblem(name, knobs.client_idle_timeout, knobs.server_idle_close, "client_idle_timeout");
|
|
466
|
+
if (idle !== null) found.push(idle);
|
|
467
|
+
if (keepalive !== void 0 && keepalive < ms(knobs.server_keepalive_min_time)) found.push(`${name}'s keepalive_time is below server_keepalive_min_time: the server answers with GOAWAY too_many_pings (O26)`);
|
|
468
|
+
return found;
|
|
469
|
+
}
|
|
470
|
+
};
|
|
471
|
+
};
|
|
472
|
+
export { GRPC_CODES, GRPC_OPERATIONS, HEALTH_CHECK, HTTP2_PREFACE, codeName, grpcClient, grpcDial, grpcOperations, grpcOptions, grpcOutcome, grpcTarget, healthRequest, healthStatus, settingsJudge, specProblems };
|
|
473
|
+
|
|
474
|
+
//# sourceMappingURL=client.js.map
|