@mark1russell7/service 0.8.1 → 0.8.3

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 CHANGED
@@ -92,6 +92,9 @@ The format of a description is `mark1russell7.service/1`.
92
92
  - **The logger port.** A `Logger` has one method, `log(level, message, fields)`, thus an adapter to another logger is a few lines. `consoleLogger({ level })` writes to the console at `info` and above by default.
93
93
  - **Lines of JSON.** `consoleLogger({ level, format: "json" })` writes one line of JSON for each entry, with `level`, `message` and each field. An error field gives its name, its message and its stack. The default format is `text`, as before.
94
94
  - **Trace ids.** `consoleLogger({ traceIds })`, with `traceIds` from `@mark1russell7/service/otel`, adds the `trace_id` and the `span_id` of the active span of OpenTelemetry to each entry. A field of the entry with the same name stays. When no span is active, for example when no program registered an SDK, the entry does not change. Only the entry `/otel` loads `@opentelemetry/api`.
95
+ - **The context of a call.** `callContext` from `@mark1russell7/service/otel` takes the trace and the baggage across the network, with the propagator that the program registers:
96
+ - `httpTransport(server, knobs, { callContext })` runs each handler in the context of the headers of its request. The request joins the trace of `traceparent`. Its `baggage` is dropped, unless `trustBaggage(req)` gives true, for example after a token check.
97
+ - `httpClient(name, spec, { callContext })` and `grpcClient(name, spec, { callContext })` send the headers of the active context with each call, for example `traceparent`. A header of the call, or metadata of the spec or of the call, with the same name stays.
95
98
  - **No logger.** Without a logger, the runtime writes no log, as before. `testLogger()` of `@mark1russell7/service/testing` keeps each entry, thus a test can examine the log.
96
99
 
97
100
  ## The machines
@@ -816,7 +819,7 @@ pnpm add @mark1russell7/service
816
819
 
817
820
  For the Redis client, the application also installs `ioredis@6`. For the PostgreSQL client, it installs `pg@8`. For the MongoDB client, it installs `mongodb@7`. For the RabbitMQ client, it installs `amqplib@2`. For the WebSocket client, it installs `ws@8`.
818
821
 
819
- For the gRPC client, it installs `@grpc/grpc-js@1`. The HTTP client needs no other package. For the trace ids of `/otel`, it installs `@opentelemetry/api@1`.
822
+ For the gRPC client, it installs `@grpc/grpc-js@1`. The HTTP client needs no other package. For the trace ids and the call context of `/otel`, it installs `@opentelemetry/api@1`.
820
823
 
821
824
  ### One copy of service
822
825
 
@@ -0,0 +1,17 @@
1
+ //#region src/call-context.d.ts
2
+ /** These are the headers of an incoming call, as `node:http` gives them: the names are in lower case. */
3
+ type IncomingHeaders = Readonly<Record<string, string | readonly string[] | undefined>>;
4
+ /** A call context reads the context of an incoming call, and writes the context of an outgoing call. */
5
+ interface CallContext {
6
+ /**
7
+ * This function runs `fn` in the context of the headers of an incoming call. The context has the
8
+ * trace of `traceparent`. It has the baggage only when `trusted` is true. A call that is not trusted
9
+ * joins the trace of its caller, but its baggage is dropped.
10
+ */
11
+ run<T>(headers: IncomingHeaders, trusted: boolean, fn: () => T): T;
12
+ /** This function gives the headers of the active context for an outgoing call, for example `traceparent`. */
13
+ headers(): Record<string, string>;
14
+ }
15
+ //#endregion
16
+ export { IncomingHeaders as n, CallContext as t };
17
+ //# sourceMappingURL=call-context-gR8FhbF_.d.ts.map
package/build/grpc.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { N as Poll, ut as Operation } from "./logger-BN2BfPgU.js";
2
2
  import { C as MANIFESTATIONS, D as firstDetector, E as Situation, O as unwatched, S as Detector, T as Meeting, _ as Sent, a as ClientKnobs, b as retryProblems, c as ClientSpec, d as Factory, f as ReadyWait, g as SendOptions, h as STARTING_POLL, i as ClientJoin, l as ClientStep, n as CheckOptions, o as ClientOptions, p as RetryKnobs, r as Client, s as ClientSocket, t as Attempt, u as DialFn, v as readyWait, w as Manifestation } from "./core-Dt0HEVMq.js";
3
3
  import { t as Judge } from "./dial-CSQOl-yj.js";
4
+ import { t as CallContext } from "./call-context-gR8FhbF_.js";
4
5
  import { Extent, Quantity } from "@mark1russell7/quantity";
5
6
  import { Machine } from "@mark1russell7/algebra";
6
7
  //#region src/grpc/connection.d.ts
@@ -154,7 +155,13 @@ interface GrpcClientSpec extends ClientSpec<GrpcKnobs> {
154
155
  readonly operations?: ClientSpec<GrpcKnobs>["operations"];
155
156
  }
156
157
  /** These options make a client. Without them, it uses grpc-js, the real clock, and a dial with the HTTP/2 preface. */
157
- type GrpcClientOptions = ClientOptions<GrpcFactory>;
158
+ interface GrpcClientOptions extends ClientOptions<GrpcFactory> {
159
+ /**
160
+ * With this call context, each call gets the headers of the active context of its caller in its
161
+ * metadata, for example `traceparent`. The metadata of the spec and of the call stays. `callContext` of the entry `/otel` gives one.
162
+ */
163
+ readonly callContext?: CallContext | undefined;
164
+ }
158
165
  /**
159
166
  * A join is one generation of the client: each time that its channel becomes READY (D1, D2). The
160
167
  * grpc-js driver gives no socket of its transport, thus the ends of the socket are null.
package/build/grpc.js CHANGED
@@ -495,6 +495,7 @@ const grpcClient = (name, spec, options = {}) => {
495
495
  const call = (method, request, callOptions = {}) => {
496
496
  const started = clock.now();
497
497
  const metadata = {
498
+ ...options.callContext?.headers(),
498
499
  ...spec.metadata,
499
500
  ...callOptions.metadata
500
501
  };
package/build/grpc.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"grpc.js","names":["SERVING","knob","t"],"sources":["../src/grpc/connection.ts","../src/grpc/meets.ts","../src/grpc/client.ts","../src/grpc/machine.ts","../src/grpc/starting.ts"],"sourcesContent":["import type { Factory } from \"../client/core.ts\";\n\n/** A state is the connectivity state of a channel of grpc-js, by the names of its enum `connectivityState`. */\nexport type GrpcState = \"IDLE\" | \"CONNECTING\" | \"READY\" | \"TRANSIENT_FAILURE\" | \"SHUTDOWN\";\n\n/** These states are in the sequence of the enum of grpc-js: the index of a state is its value. */\nexport const GRPC_STATES: readonly GrpcState[] = [\"IDLE\", \"CONNECTING\", \"READY\", \"TRANSIENT_FAILURE\", \"SHUTDOWN\"];\n\n/** A status is the end of one call: its code (0 is OK) and its details. */\nexport interface GrpcStatus {\n readonly code: number;\n readonly details: string;\n}\n\n/** A call handle stops one call in flight. The grpc-js driver then writes RST_STREAM with the code CANCEL. */\nexport interface GrpcCallHandle {\n cancel(): void;\n}\n\n/**\n * A channel is the part of a `Client` of grpc-js 1.14 that the wrapper uses. A fake for tests has\n * each part too. Thus the package depends on no type of grpc-js.\n */\nexport interface GrpcChannel {\n /** This method gives the state of the channel. True also starts a connect when the channel is IDLE. */\n state(connect: boolean): GrpcState;\n /** This method starts `changed` one time, when the state of the channel is no longer `current`. */\n watch(current: GrpcState, changed: () => void): void;\n /**\n * This method sends one unary call: the method path and the bytes of its request message. `done`\n * gets the status of the call, and the bytes of the response message when the status is OK. The\n * call ends at `timeout` milliseconds with DEADLINE_EXCEEDED, and grpc-js sends the header `grpc-timeout`.\n */\n unary(\n method: string,\n request: Buffer,\n metadata: Readonly<Record<string, string>>,\n timeout: number,\n done: (status: GrpcStatus, response: Buffer | undefined) => void,\n ): GrpcCallHandle;\n /** This method closes the channel. Its state becomes SHUTDOWN, and it does not connect again. */\n close(): void;\n}\n\n/**\n * These are the options of the channel that the wrapper gives `new Client(target, credentials, options)`.\n * Each time comes from the declaration, in milliseconds.\n */\nexport interface GrpcChannelOptions {\n /** The wrapper turns off the retries of grpc-js, the transparent retry too. Only the core decides a second send. */\n readonly \"grpc.enable_retries\": 0;\n /** The wrapper reads no service config from the resolver. Thus no record of DNS changes the policy of a call. */\n readonly \"grpc.service_config_disable_resolution\": 1;\n /** This time is the interval of the HTTP/2 PING of keepalive. Without it, grpc-js sends no PING. */\n readonly \"grpc.keepalive_time_ms\"?: number | undefined;\n /** This time bounds the ACK of each PING. Without an ACK in this time, grpc-js ends the transport. */\n readonly \"grpc.keepalive_timeout_ms\": number;\n /** 1 sends the PING with no call in flight too. The server must permit that, or it answers with GOAWAY too_many_pings (O26). */\n readonly \"grpc.keepalive_permit_without_calls\": 0 | 1;\n /** This time with no call puts the channel in IDLE, and closes its connection. */\n readonly \"grpc.client_idle_timeout_ms\": number;\n /** This time is the first delay of grpc-js before a new try to connect. */\n readonly \"grpc.initial_reconnect_backoff_ms\": number;\n /** This time is the most that one delay of grpc-js can be, before its jitter of 20 %. */\n readonly \"grpc.max_reconnect_backoff_ms\": number;\n}\n\n/** These are the arguments of `new Client(target, credentials, options)`. The credentials are insecure: the client speaks h2c. */\nexport interface GrpcConnectOptions {\n readonly target: string;\n readonly options: GrpcChannelOptions;\n}\n\n/** A channel factory makes one channel from its options. The channel connects later, when the wrapper asks it. */\nexport type GrpcFactory = Factory<GrpcConnectOptions, GrpcChannel>;\n\n/** This type is the part of a `Client` of grpc-js 1.14 that the adapter uses. */\ninterface GrpcDriverClient {\n getChannel(): {\n getConnectivityState(connect: boolean): number;\n watchConnectivityState(current: number, deadline: number, callback: (error?: Error) => void): void;\n };\n makeUnaryRequest(\n method: string,\n serialize: (value: Buffer) => Buffer,\n deserialize: (bytes: Buffer) => Buffer,\n argument: Buffer,\n metadata: unknown,\n options: { readonly deadline: number },\n callback: (error: { readonly code?: number; readonly details?: string; readonly message?: string } | null, value?: Buffer) => void,\n ): GrpcCallHandle;\n close(): void;\n}\n\n/** This type is the part of the module of grpc-js that the adapter uses. */\ninterface GrpcDriver {\n readonly Client: new (target: string, credentials: unknown, options: GrpcChannelOptions) => GrpcDriverClient;\n readonly credentials: { createInsecure(): unknown };\n readonly Metadata: new () => { add(key: string, value: string): void };\n}\n\n/** These functions give the bytes of a message as they are. The caller encodes and decodes its messages. */\nconst identity = (bytes: Buffer): Buffer => bytes;\n\n/** This function gives the state of a value of the enum of grpc-js. */\nconst stateOf = (value: number): GrpcState => GRPC_STATES[value] ?? \"SHUTDOWN\";\n\n/**\n * This function adapts a `Client` of grpc-js to a channel. The deadline of grpc-js is a time of the\n * wall clock, thus the adapter adds the timeout to `Date.now()`.\n */\nexport const adaptGrpc = (grpc: GrpcDriver, client: GrpcDriverClient): GrpcChannel => {\n const channel = client.getChannel();\n return {\n state: (connect) => stateOf(channel.getConnectivityState(connect)),\n watch(current, changed) {\n try {\n channel.watchConnectivityState(GRPC_STATES.indexOf(current), Number.POSITIVE_INFINITY, (error) => {\n if (error === undefined) changed();\n });\n } catch {\n // The grpc-js driver throws when the channel is shut down: no state comes after SHUTDOWN\n }\n },\n unary(method, request, metadata, timeout, done) {\n const sent = new grpc.Metadata();\n for (const [key, value] of Object.entries(metadata)) sent.add(key, value);\n const deadline = Number.isFinite(timeout) ? Date.now() + timeout : Number.POSITIVE_INFINITY;\n return client.makeUnaryRequest(method, identity, identity, request, sent, { deadline }, (error, value) => {\n if (error === null) done({ code: 0, details: \"\" }, value ?? Buffer.alloc(0));\n else done({ code: error.code ?? 2, details: error.details ?? error.message ?? \"\" }, undefined);\n });\n },\n close: () => client.close(),\n };\n};\n\n/**\n * This factory makes a `Client` of grpc-js. It loads grpc-js only when a client connects, thus a\n * service that does not use gRPC does not need it. The specifier is a value, thus the package needs no types of grpc-js.\n */\nexport const nodeGrpc: GrpcFactory = async ({ target, options }) => {\n const specifier = \"@grpc/grpc-js\";\n const loaded = (await import(specifier)) as Partial<GrpcDriver> & { readonly default?: GrpcDriver };\n const grpc = loaded.Client === undefined ? loaded.default : (loaded as GrpcDriver);\n if (grpc?.Client === undefined) throw new Error(\"@grpc/grpc-js gives no Client class\");\n return adaptGrpc(grpc, new grpc.Client(target, grpc.credentials.createInsecure(), options));\n};\n","import type { Detector, Meeting, Situation } from \"../client/meets.ts\";\nimport { NEVER, WHAT, immediate, kernelGiveUp } from \"../client/meets.ts\";\nimport { finiteMs } from \"../client/core.ts\";\nimport { heartbeatDetection } from \"../timing.ts\";\nimport type { GrpcKnobs } from \"./client.ts\";\n\n/**\n * This function gives the manifestations that a gRPC client can meet, and the detectors of each,\n * from its knobs. The gRPC cells measured them on grpc-js 1.14.6:\n * - At its defaults, grpc-js has no detector: no keepalive, no deadline, and no TCP keepalive.\n * - A reset gave each call ECONNRESET in 1.1 ms to 1.4 ms. The FIN of a stopped server ended an idle connection in 43 µs.\n * - The keepalive ended a silent transport at keepalive_time + keepalive_timeout: 80.012 s at 60 s\n * against etcd, and 320.005 s at 300 s against grpc-go (DP24).\n * - Without `keepaliveWithoutCalls`, grpc-js sends a PING only with a call in flight.\n * - At client_idle_timeout, the channel goes IDLE, and the client connects again. A server that does\n * not answer then keeps the channel out of READY.\n */\nexport const grpcMeetings = (name: string, knobs: GrpcKnobs, withoutCalls: boolean): Meeting[] => {\n const interval = finiteMs(knobs.keepalive_time);\n const detection = heartbeatDetection(knobs.keepalive_time, knobs.keepalive_timeout, 1);\n const keepalive = (situation: Situation): Detector => ({\n by: \"heartbeat_detection_time\",\n within: situation === \"idle\" && !withoutCalls ? NEVER : detection,\n situation,\n effect:\n situation === \"idle\" && !withoutCalls\n ? \"grpc-js sends no PING with no call in flight\"\n : `the PING gets no ACK in keepalive_timeout, the transport ends, each call in flight fails with UNAVAILABLE, and ${name} connects again`,\n });\n const deadline: Detector = {\n by: \"request_timeout\",\n within: knobs.request_timeout,\n situation: \"in flight\",\n effect: \"the deadline ends the call with DEADLINE_EXCEEDED as indeterminate, and the transport stays\",\n };\n // A new connection after client_idle_timeout meets the failure, and the channel does not become READY\n const reconnect: Detector = {\n by: \"client_idle_timeout\",\n within: knobs.client_idle_timeout,\n situation: \"idle\",\n effect: `the channel goes IDLE, ${name} connects again, and the new connection does not become ready`,\n };\n const giveUp = kernelGiveUp(knobs.retrans_giveup_time, \"each call in flight fails with UNAVAILABLE\");\n const silent = (manifestation: \"blackhole\" | \"freeze-host\"): Meeting => ({\n manifestation,\n what: WHAT[manifestation],\n detectors: [deadline, keepalive(\"in flight\"), giveUp, keepalive(\"idle\"), reconnect],\n });\n return [\n {\n manifestation: \"rst\",\n what: WHAT.rst,\n detectors: [\n immediate(\"in flight\", \"the reset arrives, each call fails with UNAVAILABLE as indeterminate, and the channel goes IDLE\"),\n {\n by: \"keepalive_time\",\n within: interval === undefined || !withoutCalls ? NEVER : knobs.keepalive_time,\n situation: \"idle\",\n effect: \"the next PING gets a reset, and the client connects again\",\n },\n { ...reconnect, effect: `the channel goes IDLE, ${name} connects again, and the server refuses the connect` },\n ],\n },\n {\n manifestation: \"fin\",\n what: WHAT.fin,\n detectors: [\n immediate(\"in flight\", \"the FIN arrives, and each call fails with UNAVAILABLE as indeterminate\"),\n immediate(\"idle\", \"the FIN arrives, the channel goes IDLE, 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 // The kernel of the server completes a new TCP connect, but its process sends no SETTINGS frame\n detectors: [deadline, keepalive(\"in flight\"), keepalive(\"idle\"), reconnect],\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: [\n deadline,\n { ...keepalive(\"idle\"), within: NEVER, effect: \"the library of the server still answers each PING with an ACK\" },\n { ...reconnect, within: NEVER, effect: \"the library of the server still takes a new connection\" },\n ],\n },\n ];\n};\n","import type { Extent, Quantity } from \"@mark1russell7/quantity\";\nimport { realClock } from \"../clock.ts\";\nimport type {\n Attempt,\n CheckOptions,\n Client,\n ClientJoin,\n ClientKnobs,\n ClientOptions,\n ClientSpec,\n ClientStep,\n DialFn,\n RetryKnobs,\n SendOptions,\n Sent,\n} from \"../client/core.ts\";\nimport {\n ageProblems,\n attachClient,\n clientBounds,\n clientProblems,\n clientRecorder,\n dialCheck,\n finiteMs,\n idleCloseProblem,\n inFlight,\n localStateCheck,\n message,\n ms,\n notSent,\n operationTable,\n readyWait,\n retryProblems,\n roundTripCheck,\n sendWithReissue,\n socketEnds,\n stepChecks,\n timeProblems,\n wholeProblems,\n withinBound,\n wrapperTimerProblems,\n zeroProblems,\n} from \"../client/core.ts\";\nimport type { Judge } from \"../client/dial.ts\";\nimport { authority, helloDial } from \"../client/dial.ts\";\nimport { NEVER } from \"../client/meets.ts\";\nimport type { Dependency } from \"../description.ts\";\nimport type { DependencyHandle } from \"../lifecycle.ts\";\nimport type { Operation } from \"../operation.ts\";\nimport { heartbeatDetection } from \"../timing.ts\";\nimport type { GrpcCallHandle, GrpcChannel, GrpcConnectOptions, GrpcFactory, GrpcState, GrpcStatus } from \"./connection.ts\";\nimport { nodeGrpc } from \"./connection.ts\";\nimport { grpcMeetings } from \"./meets.ts\";\n\n/**\n * These are the knobs of the client, each a time, by the names of the ordering law and of the gRPC\n * cells. The runtime has no defaults, thus each knob is necessary. The constant\n * `GRPC_CLIENT_STARTING_KNOBS` gives a declaration from the gRPC cells. The knobs that each client has come from the core.\n */\nexport interface GrpcKnobs extends ClientKnobs, RetryKnobs {\n /** 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. */\n readonly connect_bound: Quantity;\n /** 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`. */\n readonly request_timeout: Quantity;\n /** 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. */\n readonly keepalive_time: Extent;\n /** This time bounds the ACK of each PING (`grpc.keepalive_timeout_ms`). With no ACK, grpc-js ends the transport. */\n readonly keepalive_timeout: Quantity;\n /** This time with no call puts the channel in IDLE and closes its connection (`grpc.client_idle_timeout_ms`). The client then connects again. */\n readonly client_idle_timeout: Quantity;\n /**\n * This time is the shortest interval of the PING that the server permits: `MinTime` of the\n * 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.\n */\n readonly server_keepalive_min_time: Quantity;\n /** This time is when the server or a proxy ends an idle connection with GOAWAY, or \"infinite\". The client must close first (O01). */\n readonly server_idle_close: Extent;\n /** This time is the first delay of grpc-js before a new try to connect (`grpc.initial_reconnect_backoff_ms`). */\n readonly retry_base: Quantity;\n /** This time is the most that one delay of grpc-js can be, before its jitter of 20 % (`grpc.max_reconnect_backoff_ms`). */\n readonly retry_cap: Quantity;\n /** 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\". */\n readonly keepalive_idle: Extent;\n /** The client does not replace its connection at an age, thus this knob must be \"infinite\". */\n readonly max_connection_age: Extent;\n /** This time bounds the close at the shutdown: the calls in flight. At the bound, the client cancels each call, then closes the channel. */\n readonly close_bound: Quantity;\n}\n\n/** A gRPC client spec is the declaration of one gRPC client: where it connects, and its knobs. */\nexport interface GrpcClientSpec extends ClientSpec<GrpcKnobs> {\n /**\n * True sends the PING of keepalive with no call in flight too (`grpc.keepalive_permit_without_calls`).\n * The server must permit that (`PermitWithoutStream` of grpc-go), or it answers with GOAWAY too_many_pings (O26).\n */\n readonly keepaliveWithoutCalls: boolean;\n /** These headers go with each call, for example `authorization`. The metadata of a call adds to them. */\n readonly metadata?: Readonly<Record<string, string>> | undefined;\n /** This name is the service that the round-trip check asks the health service about. The default is \"\", the whole server. */\n readonly healthService?: string | undefined;\n /**\n * These operations are the methods of the service, by their full path, with their idempotency. The\n * client sends again only a method that this table names as idempotent. `grpcOperations` makes the\n * table from the `idempotency_level` of each method in its proto.\n */\n readonly operations?: ClientSpec<GrpcKnobs>[\"operations\"];\n}\n\n/** These options make a client. Without them, it uses grpc-js, the real clock, and a dial with the HTTP/2 preface. */\nexport type GrpcClientOptions = ClientOptions<GrpcFactory>;\n\n/**\n * A join is one generation of the client: each time that its channel becomes READY (D1, D2). The\n * grpc-js driver gives no socket of its transport, thus the ends of the socket are null.\n */\nexport interface GrpcJoin extends ClientJoin {\n /** This text is the target of the channel. */\n readonly target: string;\n}\n\n/** These options tell how the client sends one call. */\nexport interface GrpcCallOptions extends SendOptions {\n /** These headers go with this call, after the metadata of the spec. */\n readonly metadata?: Readonly<Record<string, string>> | undefined;\n}\n\n/** A serving status is the status of a HealthCheckResponse of the health service (grpc.health.v1). */\nexport type GrpcServingStatus = \"UNKNOWN\" | \"SERVING\" | \"NOT_SERVING\" | \"SERVICE_UNKNOWN\";\n\n/** A gRPC client is a dependency of a service: its declaration, its handle, its checks and its calls. */\nexport interface GrpcClient extends Client<ClientStep, GrpcJoin> {\n /** This text is the state of the client, as `GRPC_CLIENT_MACHINE` names it. */\n readonly status: string;\n /**\n * This method sends one unary call, and waits for its status. `request` holds the bytes of the\n * request message, and an OK status gives the bytes of the response message. The client sends again\n * only an idempotent method, one time at most, after an outcome that is not certain.\n */\n call(method: string, request: Buffer, options?: GrpcCallOptions): Promise<Sent<Buffer>>;\n /** This method sends one Check of the health service (grpc.health.v1), and gives the serving status of the reply. */\n health(service?: string, options?: SendOptions): Promise<Sent<GrpcServingStatus>>;\n}\n\n/** The names of the status codes of gRPC, by their value. */\nexport const GRPC_CODES = [\n \"OK\",\n \"CANCELLED\",\n \"UNKNOWN\",\n \"INVALID_ARGUMENT\",\n \"DEADLINE_EXCEEDED\",\n \"NOT_FOUND\",\n \"ALREADY_EXISTS\",\n \"PERMISSION_DENIED\",\n \"RESOURCE_EXHAUSTED\",\n \"FAILED_PRECONDITION\",\n \"ABORTED\",\n \"OUT_OF_RANGE\",\n \"UNIMPLEMENTED\",\n \"INTERNAL\",\n \"UNAVAILABLE\",\n \"DATA_LOSS\",\n \"UNAUTHENTICATED\",\n] as const;\n\n/**\n * These codes are certain errors: each one tells that the server or a proxy refused the call, and did\n * not apply it. A proxy that answers 401, 403 or 404 gives UNAUTHENTICATED, PERMISSION_DENIED or UNIMPLEMENTED.\n */\nconst CERTAIN = new Set([3, 5, 6, 7, 9, 10, 11, 12, 16]);\n\n/**\n * These statuses of grpc-js tell that the call did not leave the client. A status with another\n * details text of the same code can come after the send, thus it is indeterminate:\n * - UNAVAILABLE \"No connection established\": the pick of a channel in TRANSIENT_FAILURE (picker.ts:105).\n * - UNAVAILABLE \"Name resolution failed\": the resolver found no address (resolver-dns.ts:119).\n * - UNAVAILABLE \"Stream refused by server\": RST_STREAM REFUSED_STREAM. The server did not process the stream (RFC 9113 §8.7).\n * - INTERNAL \"Failed to start HTTP/2 stream\": the stream did not start (load-balancing-call.ts:281).\n * - DEADLINE_EXCEEDED with \"Waiting for LB pick\" or \"waiting for name resolution\": the deadline came before a stream.\n */\nconst NOT_SENT: ReadonlyArray<readonly [number, RegExp]> = [\n [14, /^No connection established/],\n [14, /^Name resolution failed/],\n [14, /^Stream refused by server$/],\n [13, /^Failed to start HTTP\\/2 stream/],\n [4, /(^|,)(Waiting for LB pick|waiting for name resolution)(,|$)/],\n];\n\n/** This function gives the name of a status code, for example \"UNAVAILABLE\". */\nexport const codeName = (code: number): string => GRPC_CODES[code] ?? `code ${code}`;\n\n/**\n * This function gives the outcome of one call from its status:\n * - OK is `ok`.\n * - A code that tells that the server refused the call is a certain error: `reply` is true.\n * - A status that tells that the call did not leave the client is a certain error with `reply` false.\n * - Each other status is indeterminate: CANCELLED, UNKNOWN, DEADLINE_EXCEEDED, RESOURCE_EXHAUSTED,\n * INTERNAL, UNAVAILABLE and DATA_LOSS can come after the server applied the call.\n */\nexport const grpcOutcome = (status: GrpcStatus, response: Buffer | undefined): Attempt<Buffer> => {\n if (status.code === 0) return { outcome: \"ok\", value: response ?? Buffer.alloc(0) };\n const error = `${codeName(status.code)}: ${status.details}`;\n if (CERTAIN.has(status.code)) return { outcome: \"error\", error, reply: true };\n if (NOT_SENT.some(([code, details]) => code === status.code && details.test(status.details))) return notSent(`${error} (the call did not leave the client)`);\n return { outcome: \"indeterminate\", error };\n};\n\n/** This method is the Check of the health service. Its request names a service, and its response gives a serving status. */\nexport const HEALTH_CHECK = \"/grpc.health.v1.Health/Check\";\n\n/** These operations are in each table: the Check of the health service has no side effects. */\nexport const GRPC_OPERATIONS: Readonly<Record<string, Operation>> = { [HEALTH_CHECK]: { idempotent: true } };\n\n/** An idempotency level is the option `idempotency_level` of a method in its proto (descriptor.proto). */\nexport type GrpcIdempotencyLevel = \"IDEMPOTENCY_UNKNOWN\" | \"NO_SIDE_EFFECTS\" | \"IDEMPOTENT\";\n\n/**\n * This function makes a table of operations from the idempotency level of each method, by its full\n * path. NO_SIDE_EFFECTS and IDEMPOTENT are idempotent. IDEMPOTENCY_UNKNOWN, the default of a proto, is not.\n */\nexport const grpcOperations = (levels: Readonly<Record<string, GrpcIdempotencyLevel>>): Record<string, Operation> =>\n Object.fromEntries(Object.entries(levels).map(([method, level]) => [method, { idempotent: level !== \"IDEMPOTENCY_UNKNOWN\" }]));\n\n/** This function gives the bytes of a varint of protobuf. */\nconst varint = (value: number): Buffer => {\n const bytes: number[] = [];\n let rest = value;\n while (rest > 0x7f) {\n bytes.push((rest & 0x7f) | 0x80);\n rest = Math.floor(rest / 128);\n }\n bytes.push(rest);\n return Buffer.from(bytes);\n};\n\n/** This function gives the bytes of a HealthCheckRequest. The service \"\" is the whole server, and its message is empty. */\nexport const healthRequest = (service: string): Buffer => {\n if (service === \"\") return Buffer.alloc(0);\n const name = Buffer.from(service, \"utf8\");\n return Buffer.concat([Buffer.from([0x0a]), varint(name.length), name]);\n};\n\nconst SERVING: readonly GrpcServingStatus[] = [\"UNKNOWN\", \"SERVING\", \"NOT_SERVING\", \"SERVICE_UNKNOWN\"];\n\n/** This function gives the status of a HealthCheckResponse, or null when the bytes are not one. An empty message is UNKNOWN. */\nexport const healthStatus = (bytes: Buffer): GrpcServingStatus | null => {\n let at = 0;\n let status = 0;\n const read = (): number | null => {\n let value = 0;\n for (let shift = 0; shift < 35; shift += 7) {\n const byte = bytes[at];\n if (byte === undefined) return null;\n at += 1;\n value += (byte & 0x7f) * 2 ** shift;\n if ((byte & 0x80) === 0) return value;\n }\n return null;\n };\n while (at < bytes.length) {\n const tag = read();\n if (tag === null) return null;\n const wire = tag & 7;\n if (wire === 0) {\n const value = read();\n if (value === null) return null;\n if (tag >> 3 === 1) status = value;\n } else if (wire === 2) {\n const length = read();\n if (length === null || at + length > bytes.length) return null;\n at += length;\n } else if (wire === 1 || wire === 5) {\n at += wire === 1 ? 8 : 4;\n if (at > bytes.length) return null;\n } else return null;\n }\n return SERVING[status] ?? null;\n};\n\n/** The longest timer of Node, in milliseconds. A longer delay starts at 1 ms, thus grpc-js cannot take it. */\nconst LONGEST_TIMER = 0x7fffffff;\n\n/** 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. */\nconst longestTimerProblems = (name: string, knobs: object, names: readonly string[]): string[] =>\n names.flatMap((knob) => {\n const amount = (knobs as Record<string, Extent>)[knob]!;\n return amount.value !== \"infinite\" && ms(amount) > LONGEST_TIMER ? [`${name}'s ${knob} is above ${LONGEST_TIMER} ms, the longest timer of Node`] : [];\n });\n\n/** This function gives the problems of a spec: the knobs that the client cannot use. */\nexport const specProblems = (name: string, spec: GrpcClientSpec): string[] => {\n const { knobs } = spec;\n const timers = [\"keepalive_time\", \"keepalive_timeout\", \"client_idle_timeout\", \"retry_base\", \"retry_cap\"];\n const problems = [\n ...timeProblems(name, knobs),\n // The grpc-js driver has no connect timeout, and gives a call no deadline: the wrapper gives both\n ...wrapperTimerProblems(name, knobs, { connect_bound: \"the wait of the startup for a ready channel\", request_timeout: \"a call\" }),\n ...zeroProblems(name, \"grpc-js\", knobs, { open: [\"keepalive_time\"] }),\n // The grpc-js driver takes each timer in whole milliseconds\n ...wholeProblems(name, knobs, { millis: timers }),\n ...longestTimerProblems(name, knobs, timers),\n ...retryProblems(name, knobs),\n ...ageProblems(name, knobs, \"grpc-js does not replace its connection at an age\"),\n ];\n for (const knob of [\"keepalive_timeout\", \"client_idle_timeout\", \"retry_base\", \"retry_cap\"] as const)\n if (finiteMs(knobs[knob]) === undefined || !(ms(knobs[knob]) > 0)) problems.push(`${name}'s ${knob} is not a finite time above zero`);\n // The grpc-js driver raises an idle timeout below 1 s to 1 s (internal-channel.ts:323-326)\n if (ms(knobs.client_idle_timeout) < 1000) problems.push(`${name}'s client_idle_timeout is below 1 s: grpc-js raises it to 1 s`);\n if (knobs.keepalive_idle.value !== \"infinite\")\n problems.push(`${name}'s keepalive_idle is not \"infinite\": grpc-js sets no TCP keepalive, and the PING of keepalive_time is its keepalive`);\n if (spec.password !== undefined) problems.push(`${name} takes no password: give the credentials in metadata, for example authorization`);\n return problems;\n};\n\n/** This function gives the target of a channel from a spec: the host and the port, for the DNS resolver of grpc-js. */\nexport const grpcTarget = (spec: Pick<GrpcClientSpec, \"host\" | \"port\">): string => authority(spec.host, spec.port);\n\n/**\n * This function gives the arguments of `new Client` from a spec. Each timer of grpc-js comes from the\n * declaration. The retries of grpc-js are off, and the resolver gives no service config.\n */\nexport const grpcOptions = (spec: GrpcClientSpec): GrpcConnectOptions => {\n const { knobs } = spec;\n const keepalive = finiteMs(knobs.keepalive_time);\n return {\n target: grpcTarget(spec),\n options: {\n \"grpc.enable_retries\": 0,\n \"grpc.service_config_disable_resolution\": 1,\n ...(keepalive === undefined ? {} : { \"grpc.keepalive_time_ms\": keepalive }),\n \"grpc.keepalive_timeout_ms\": ms(knobs.keepalive_timeout),\n \"grpc.keepalive_permit_without_calls\": spec.keepaliveWithoutCalls ? 1 : 0,\n \"grpc.client_idle_timeout_ms\": ms(knobs.client_idle_timeout),\n \"grpc.initial_reconnect_backoff_ms\": ms(knobs.retry_base),\n \"grpc.max_reconnect_backoff_ms\": ms(knobs.retry_cap),\n },\n };\n};\n\n/** These are the bytes of the dial: the connection preface of the client (RFC 9113 §3.4), and a SETTINGS frame with no setting. */\nexport const HTTP2_PREFACE: Buffer = Buffer.concat([Buffer.from(\"PRI * HTTP/2.0\\r\\n\\r\\nSM\\r\\n\\r\\n\", \"latin1\"), Buffer.from([0, 0, 0, 4, 0, 0, 0, 0, 0])]);\n\n/**\n * This judge reads the first frame of the server. Only a SETTINGS frame on stream 0, with no ACK,\n * 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.\n */\nexport const settingsJudge: Judge = (received) => {\n if (received.length < 9) return \"more\";\n const type = received[3];\n const flags = received[4]!;\n const stream = received.readUInt32BE(5) & 0x7fffffff;\n return type === 0x04 && (flags & 0x01) === 0 && stream === 0\n ? null\n : 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\")}`);\n};\n\n/** 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. */\nexport const grpcDial: DialFn = helloDial(HTTP2_PREFACE, settingsJudge);\n\n/**\n * This function makes a gRPC client, a dependency of a service over grpc-js 1.14.\n * - It has one channel for its life. Each time that the channel becomes READY is one generation.\n * - The grpc-js driver connects again by itself, after its own backoff. The client connects an IDLE channel again at once.\n * - A call is one unary call, until its status. Its deadline is the time that is left in `request_timeout`.\n * - It tells the outcome of a call in three values from its status code (C8).\n * - The retries of grpc-js are off, thus only the core sends a call again.\n * - Its keepalive is the HTTP/2 PING of grpc-js. It records the target of each generation (D1).\n *\n * These parts come from the core of the clients: the outcomes, the second try and the wait for a ready client.\n * 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.\n */\nexport const grpcClient = (name: string, spec: GrpcClientSpec, options: GrpcClientOptions = {}): GrpcClient => {\n const problems = specProblems(name, spec);\n if (problems.length > 0) throw new Error(problems.join(\"; \"));\n const { knobs } = spec;\n const clock = options.clock ?? realClock;\n const create = options.create ?? nodeGrpc;\n const dial = options.dial ?? grpcDial;\n const operations = operationTable(GRPC_OPERATIONS, spec.operations);\n const requestTimeout = ms(knobs.request_timeout);\n const target = grpcTarget(spec);\n\n let status = \"none\";\n let channel: GrpcChannel | null = null;\n // This function ends the wait of the startup, at the first READY or TRANSIENT_FAILURE\n let settled: (() => void) | null = null;\n const joins: GrpcJoin[] = [];\n const flight = inFlight();\n const readied = readyWait(clock, () => status === \"ready\");\n\n const emit = clientRecorder(options.record, clock, name);\n const record = (on: string, to: string = status, detail?: string): void => {\n const from = status;\n status = to;\n emit(from, to, on, detail);\n };\n const closing = (): boolean => status === \"closing\" || status === \"end\";\n\n /** This function follows one state of the channel. The grpc-js driver ends each call in flight by itself when its transport ends. */\n const follow = (c: GrpcChannel, state: GrpcState): void => {\n if (c !== channel || closing()) return;\n if (state === \"READY\") {\n if (status === \"ready\") return;\n const generation = joins.length + 1;\n joins.push({ generation, at: clock.now(), target, ...socketEnds(undefined) });\n record(\"join\", \"ready\", `generation ${generation}, ${target}`);\n readied.wake();\n settled?.();\n } else if (state === \"TRANSIENT_FAILURE\") {\n if (status === \"failing\") return;\n record(\"connect.failed\", \"failing\", \"the channel is in TRANSIENT_FAILURE: grpc-js connects again after its backoff\");\n settled?.();\n } else if (state === \"CONNECTING\") {\n if (status !== \"connecting\") record(\"channel.connecting\", \"connecting\", target);\n } else if (state === \"IDLE\") {\n if (status === \"ready\") record(\"connection.end\", \"idle\", \"the transport ended: a GOAWAY, a reset, a FIN, the keepalive, or client_idle_timeout\");\n else if (status !== \"idle\") record(\"channel.idle\", \"idle\", \"the channel is IDLE\");\n // An IDLE channel connects only for a call: the client connects at once, thus readiness is earned again\n c.state(true);\n }\n };\n\n /** This function watches the state of the channel. It watches again before it follows, thus no change goes away. */\n const watch = (c: GrpcChannel, current: GrpcState): void =>\n c.watch(current, () => {\n if (c !== channel || closing()) return;\n const next = c.state(false);\n if (next !== \"SHUTDOWN\") watch(c, next);\n follow(c, next);\n });\n\n /** This function gives the channel for a call, or the reason that the call does not leave the client. */\n const usable = (signal: AbortSignal | undefined): GrpcChannel | Attempt<never> => {\n if (status === \"none\") return notSent(`${name} has not connected`);\n if (status !== \"ready\" || channel === null) return notSent(`${name} is ${status}, not ready: the call did not leave the client`);\n if (signal?.aborted) return notSent(\"the caller aborted the call before it left the client\");\n return channel;\n };\n\n /** This function makes one try of a call: the unary call until its status, with the deadline that is left. */\n const attempt = (\n method: string,\n request: Buffer,\n metadata: Readonly<Record<string, string>>,\n timeout: number,\n signal: AbortSignal | undefined,\n ): Promise<Attempt<Buffer>> => {\n const c = usable(signal);\n if (\"outcome\" in c) return Promise.resolve(c);\n if (!(timeout > 0)) return Promise.resolve(notSent(\"no time is left in request_timeout\"));\n let handle: GrpcCallHandle | null = null;\n let ended = false;\n return flight.track<Buffer>(\n signal,\n \"the caller abandoned the call after it left the client\",\n (settle) => {\n try {\n handle = c.unary(method, request, metadata, timeout, (given, response) => {\n ended = true;\n settle(grpcOutcome(given, response));\n });\n } catch (error) {\n ended = true;\n settle(notSent(message(error)));\n }\n },\n // A call that the caller abandons, or that the close ends, gets RST_STREAM CANCEL\n () => {\n if (!ended) handle?.cancel();\n },\n );\n };\n\n const call = (method: string, request: Buffer, callOptions: GrpcCallOptions = {}): Promise<Sent<Buffer>> => {\n const started = clock.now();\n const metadata = { ...spec.metadata, ...callOptions.metadata };\n return sendWithReissue({\n clock,\n bound: requestTimeout,\n operation: operations[method],\n options: callOptions,\n // The deadline of each try is the time that is left: a second try ends at the bound of the call\n attempt: (signal) => attempt(method, request, metadata, requestTimeout - (clock.now() - started), signal),\n // The grpc-js driver connects again by itself: the second try waits for a ready channel, in the time that is left\n beforeAgain: (left, signal) => readied.wait(left, signal),\n onReissue: () => record(\"command.reissue\", status, method),\n });\n };\n\n const health = async (service = \"\", sendOptions: SendOptions = {}): Promise<Sent<GrpcServingStatus>> => {\n const sent = await call(HEALTH_CHECK, healthRequest(service), sendOptions);\n if (sent.outcome !== \"ok\") return sent;\n const serving = healthStatus(sent.value);\n return serving === null\n ? { outcome: \"error\", error: \"the response is not a HealthCheckResponse\", reply: true, attempts: sent.attempts }\n : { outcome: \"ok\", value: serving, attempts: sent.attempts };\n };\n\n const handle: DependencyHandle = {\n async connect(signal) {\n if (signal.aborted) throw new Error(`${name}: the service stopped before the connect`);\n record(\"status.connecting\", \"connecting\", target);\n let c: GrpcChannel;\n try {\n c = await create(grpcOptions(spec));\n } catch (error) {\n record(\"connect.failed\", \"failing\", message(error));\n throw error;\n }\n if (closing()) {\n c.close();\n return;\n }\n channel = c;\n const first = new Promise<void>((resolve) => (settled = resolve));\n // A server that is down does not stop the startup: grpc-js connects again in the background,\n // and the checks keep readiness tripped until the channel is ready (readiness is earned)\n const now = c.state(true);\n watch(c, now);\n if (now !== \"IDLE\") follow(c, now);\n // The wait ends at the first READY or TRANSIENT_FAILURE, or at connect_bound. A connect into a black hole stays CONNECTING\n await withinBound(clock, ms(knobs.connect_bound), first);\n settled = null;\n },\n async close() {\n if (status === \"none\" || closing()) return;\n record(\"close.request\", \"closing\");\n settled?.();\n const c = channel;\n if (c !== null) {\n // The calls in flight end first. At the bound, each one gets RST_STREAM CANCEL, and then the channel closes\n if (!(await withinBound(clock, ms(knobs.close_bound), flight.idle()))) {\n record(\"close.bound\", \"closing\");\n record(\"close.destroy\", \"closing\", `${flight.size} calls in flight`);\n flight.settleAll(\"the client closed with the call in flight\");\n }\n c.close();\n }\n channel = null;\n flight.settleAll(\"the client closed with the call in flight\");\n record(\"status.end\", \"end\");\n },\n };\n\n const keepalive = finiteMs(knobs.keepalive_time);\n const declaration: Omit<Dependency, \"name\"> = {\n system: spec.system,\n knobs: {\n connect_bound: knobs.connect_bound,\n request_timeout: knobs.request_timeout,\n keepalive_time: knobs.keepalive_time,\n keepalive_timeout: knobs.keepalive_timeout,\n // One PING at a time, and the transport ends at its timeout: keepalive_time + keepalive_timeout\n heartbeat_detection_time: heartbeatDetection(knobs.keepalive_time, knobs.keepalive_timeout, 1),\n client_idle_timeout: knobs.client_idle_timeout,\n retry_base: knobs.retry_base,\n retry_cap: knobs.retry_cap,\n keepalive_idle: knobs.keepalive_idle,\n // A PING with no call in flight refreshes an idle flow (O03). Without it, nothing does\n idle_refresh_interval: spec.keepaliveWithoutCalls && keepalive !== undefined ? knobs.keepalive_time : NEVER,\n max_connection_age: knobs.max_connection_age,\n close_bound: knobs.close_bound,\n retrans_giveup_time: knobs.retrans_giveup_time,\n },\n operations,\n };\n\n /** The round-trip check passes only for SERVING: a health service that answers NOT_SERVING fails it, as a 5xx fails the HTTP check. */\n const roundTrip = async (sendOptions: SendOptions): Promise<Sent<unknown>> => {\n const sent = await health(spec.healthService ?? \"\", sendOptions);\n return sent.outcome === \"ok\" && sent.value !== \"SERVING\"\n ? { outcome: \"error\", error: `the health service answered ${sent.value}`, reply: true, attempts: sent.attempts }\n : sent;\n };\n\n const checks = (checkOptions: CheckOptions) =>\n stepChecks<ClientStep>(name, checkOptions, {\n // The state of the channel, without a round trip\n \"local-state\": localStateCheck(() => status === \"ready\"),\n // A Check of the health service on the channel of the application, until its status\n \"round-trip\": roundTripCheck(roundTrip),\n // A new connection each time, with the HTTP/2 preface\n dial: dialCheck(dial, spec.host, spec.port),\n });\n\n return {\n name,\n declaration,\n handle,\n meets: grpcMeetings(name, knobs, spec.keepaliveWithoutCalls),\n get status() {\n return status;\n },\n joins,\n call,\n health,\n checks,\n attach: (svc, checkOptions) => attachClient(svc, name, declaration, handle, checks(checkOptions)),\n problems(description) {\n const found = clientProblems(name, description, clientBounds(knobs));\n // O01: the channel must close an idle connection before the server or a proxy does\n const idle = idleCloseProblem(name, knobs.client_idle_timeout, knobs.server_idle_close, \"client_idle_timeout\");\n if (idle !== null) found.push(idle);\n // O26: a PING more often than the server permits gets GOAWAY too_many_pings\n if (keepalive !== undefined && keepalive < ms(knobs.server_keepalive_min_time))\n found.push(`${name}'s keepalive_time is below server_keepalive_min_time: the server answers with GOAWAY too_many_pings (O26)`);\n return found;\n },\n };\n};\n","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\", \"idle\", \"failing\"] as const;\nconst LIVE = [...SERVING, \"closing\"] as const;\n\n/**\n * The gRPC client of the service as a `mark1russell7.machine/1` document. It is one channel of\n * grpc-js 1.14 for the life of the client. Each READY of the channel is one generation. The states:\n * - `ready`: the channel is READY, and the client sends each call. The keepalive sends a PING each keepalive_time.\n * - `idle`: the transport ended, or the channel had no call in client_idle_timeout. The client connects again at once.\n * - `failing`: the channel is in TRANSIENT_FAILURE. The grpc-js driver connects again after its backoff.\n * - `closing`: the calls in flight, in `close_bound`. At the bound, each call gets RST_STREAM CANCEL.\n *\n * A test records the transitions of the client and replays them against this document.\n */\nexport const GRPC_CLIENT_MACHINE: Machine = {\n format: \"mark1russell7.machine/1\",\n id: \"service.machine.grpc-client\",\n title: \"The gRPC client of the service, over grpc-js 1.14\",\n layer: \"driver\",\n version: \"0.1.0\",\n sources: [{ ref: \"packages/service/src/grpc (the client implements this document)\", rung: \"implemented\" }],\n states: {\n none: { initial: true, note: \"the client exists, and its channel does not\" },\n connecting: { note: \"the channel is CONNECTING: the TCP connect and the HTTP/2 preface. The grpc-js driver has no connect timeout\" },\n ready: { note: \"the channel is READY. The deadline ends a call that waits, and the keepalive finds a silent transport\" },\n idle: { note: \"the channel is IDLE. The client asks it to connect at once\" },\n failing: { note: \"the channel is in TRANSIENT_FAILURE. The grpc-js driver connects again after its backoff, and each call fails as not sent\" },\n closing: { note: \"the calls in flight, in close_bound. At the bound, each call gets RST_STREAM CANCEL, then the channel closes\" },\n end: { final: true, note: \"the service closed the client\" },\n },\n events: {\n \"status.connecting\": { kind: \"local\" },\n join: { kind: \"rx\", note: \"the channel became READY: a new generation (D1)\" },\n \"connect.failed\": { kind: \"rx\", note: \"the channel went to TRANSIENT_FAILURE: a connect failed\" },\n \"channel.connecting\": { kind: \"rx\", note: \"the channel started a new connect\" },\n \"channel.idle\": { kind: \"rx\", note: \"the channel went to IDLE before it was READY\" },\n \"connection.end\": {\n kind: \"rx\",\n note: \"the transport ended: a GOAWAY, a reset, a FIN, the keepalive, or client_idle_timeout. The grpc-js driver ends each call in flight with UNAVAILABLE\",\n },\n \"command.reissue\": { kind: \"local\" },\n \"close.request\": { kind: \"local\" },\n \"close.bound\": { kind: \"timer\", note: \"the calls in flight did not end in close_bound\" },\n \"close.destroy\": { kind: \"local\", note: \"the client cancels each call in flight, then closes the channel\" },\n \"status.end\": { kind: \"local\" },\n },\n knobs: {\n keepalive_time: knob(\"grpc.keepalive_time_ms\"),\n keepalive_timeout: knob(\"grpc.keepalive_timeout_ms\"),\n client_idle_timeout: knob(\"grpc.client_idle_timeout_ms\"),\n retry_base: knob(\"grpc.initial_reconnect_backoff_ms\"),\n retry_cap: knob(\"grpc.max_reconnect_backoff_ms\"),\n close_bound: knob(\"close.bound\"),\n },\n timers: {\n keepalive: {\n duration: { expr: \"keepalive_time + keepalive_timeout\", unit: \"s\" },\n arms: [\"join\"],\n cancels: [\"connection.end\", \"close.request\"],\n fires: \"connection.end\",\n note: \"a timer of grpc-js: one PING each keepalive_time, and the end of the transport at keepalive_timeout with no ACK\",\n },\n idle: {\n duration: { knob: \"client_idle_timeout\", unit: \"s\" },\n arms: [\"join\"],\n cancels: [\"connection.end\", \"close.request\"],\n fires: \"connection.end\",\n note: \"a timer of grpc-js: client_idle_timeout with no call puts the channel in IDLE\",\n },\n retry: {\n duration: { expr: \"min(retry_cap, retry_base * pow(1.6, fired)) * 1.2\", unit: \"s\" },\n arms: [\"connect.failed\"],\n cancels: [\"close.request\"],\n fires: \"join\",\n backoff: { resets: [\"join\"] },\n note: \"a timer of grpc-js, the most delay: the backoff grows by 1.6 from retry_base to retry_cap, with a jitter of 20 %. The first delay has no jitter\",\n },\n close: closeTimer(),\n },\n transitions: [\n t(\"connect\", \"none\", \"status.connecting\", \"connecting\"),\n t(\"join\", [\"connecting\", \"idle\", \"failing\"], \"join\", \"ready\"),\n t(\"connect-failed\", [\"connecting\", \"idle\", \"ready\"], \"connect.failed\", \"failing\"),\n t(\"retry\", \"failing\", \"join\", \"ready\", { timer: \"retry\" }),\n t(\"channel-connecting\", [\"idle\", \"failing\"], \"channel.connecting\", \"connecting\"),\n t(\"channel-idle\", [\"connecting\", \"failing\"], \"channel.idle\", \"idle\"),\n t(\"connection-end\", \"ready\", \"connection.end\", \"idle\"),\n t(\"keepalive\", \"ready\", \"connection.end\", \"idle\", { timer: \"keepalive\" }),\n t(\"idle-timeout\", \"ready\", \"connection.end\", \"idle\", { timer: \"idle\" }),\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","import { STARTING_POLL } from \"../client/core.ts\";\nimport type { Poll } from \"../timing.ts\";\nimport type { GrpcKnobs } from \"./client.ts\";\n\n/**\n * This poll is the poll of the checks that `GRPC_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 GRPC_CLIENT_STARTING_POLL: Poll = STARTING_POLL;\n\n/**\n * This value tells if the keepalive sends a PING with no call in flight, to start from: false. The\n * grpc-go server refuses such a PING at its defaults (`PermitWithoutStream` false). It answers with GOAWAY too_many_pings (O26).\n */\nexport const GRPC_CLIENT_STARTING_WITHOUT_CALLS = false;\n\n/**\n * These knobs are a declaration to start from, from what the gRPC cells measured on grpc-js 1.14.6.\n * The runtime 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. The grpc-js driver has no connect timeout, thus this bounds the wait of the startup.\n * - `request_timeout` 9.5 s: in the slowest poll of 10 s (O13). In DP44 a deadline of 4 s ended each\n * call at 4.003 s to 4.004 s. The race of the two deadlines gave CANCELLED to 2 to 4 calls of 11.\n * - `keepalive_time` 300 s and `keepalive_timeout` 20 s: DP24. The PING must not come before the\n * `MinTime` of the server, 5 min at the defaults of grpc-go (O26). The transport ended at 320.005 s.\n * Against etcd, with a `MinTime` of 5 s, 60 s ended it at 80.012 s. A PING each 4 s against 5 s got GOAWAY at the 4th PING.\n * - `server_keepalive_min_time` 300 s: the `MinTime` of grpc-go v1.84.0 at its defaults.\n * - `client_idle_timeout` 60 s and `server_idle_close` 75 s: the proxies of the cells sent GOAWAY to an idle connection.\n * They did that at 75 s (nginx), 180 s (Traefik), 300 s (Caddy) and 1 h (Envoy). The client closes first (O01).\n * The default of grpc-js is 30 min.\n * - `retry_base` 1 s: the first backoff of grpc-js in T07, with no jitter. `retry_cap` 4 s: the most\n * delay is 4.8 s with the jitter of 20 %, in the slowest poll of 10 s. The default of grpc-js is 120 s.\n * - `keepalive_idle` \"infinite\": grpc-js sets no TCP keepalive, and the PING is its keepalive.\n * - `max_connection_age` \"infinite\": the client does not replace its connection at an age.\n * - `close_bound` 2 s: the calls in flight, then RST_STREAM CANCEL for each call that stays.\n * - `retrans_giveup_time` 924.6 s: the give-up of Linux at `tcp_retries2 = 15`.\n */\nexport const GRPC_CLIENT_STARTING_KNOBS: GrpcKnobs = {\n connect_bound: { value: 5, unit: \"s\" },\n request_timeout: { value: 9.5, unit: \"s\" },\n keepalive_time: { value: 300, unit: \"s\" },\n keepalive_timeout: { value: 20, unit: \"s\" },\n server_keepalive_min_time: { value: 300, unit: \"s\" },\n client_idle_timeout: { value: 60, unit: \"s\" },\n server_idle_close: { value: 75, unit: \"s\" },\n retry_base: { value: 1, 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":";;;;;AAMA,MAAa,cAAoC;CAAC;CAAQ;CAAc;CAAS;CAAqB;AAAU;;AAgGhH,MAAM,YAAY,UAA0B;;AAG5C,MAAM,WAAW,UAA6B,YAAY,UAAU;;;;;AAMpE,MAAa,aAAa,MAAkB,WAA0C;CACpF,MAAM,UAAU,OAAO,WAAW;CAClC,OAAO;EACL,QAAQ,YAAY,QAAQ,QAAQ,qBAAqB,OAAO,CAAC;EACjE,MAAM,SAAS,SAAS;GACtB,IAAI;IACF,QAAQ,uBAAuB,YAAY,QAAQ,OAAO,GAAG,OAAO,oBAAoB,UAAU;KAChG,IAAI,UAAU,KAAA,GAAW,QAAQ;IACnC,CAAC;GACH,QAAQ,CAER;EACF;EACA,MAAM,QAAQ,SAAS,UAAU,SAAS,MAAM;GAC9C,MAAM,OAAO,IAAI,KAAK,SAAS;GAC/B,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,QAAQ,GAAG,KAAK,IAAI,KAAK,KAAK;GACxE,MA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CAAI;CACrC,iBAAiB;EAAE,OAAO;EAAK,MAAM;CAAI;CACzC,gBAAgB;EAAE,OAAO;EAAK,MAAM;CAAI;CACxC,mBAAmB;EAAE,OAAO;EAAI,MAAM;CAAI;CAC1C,2BAA2B;EAAE,OAAO;EAAK,MAAM;CAAI;CACnD,qBAAqB;EAAE,OAAO;EAAI,MAAM;CAAI;CAC5C,mBAAmB;EAAE,OAAO;EAAI,MAAM;CAAI;CAC1C,YAAY;EAAE,OAAO;EAAG,MAAM;CAAI;CAClC,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"}
1
+ {"version":3,"file":"grpc.js","names":["SERVING","knob","t"],"sources":["../src/grpc/connection.ts","../src/grpc/meets.ts","../src/grpc/client.ts","../src/grpc/machine.ts","../src/grpc/starting.ts"],"sourcesContent":["import type { Factory } from \"../client/core.ts\";\n\n/** A state is the connectivity state of a channel of grpc-js, by the names of its enum `connectivityState`. */\nexport type GrpcState = \"IDLE\" | \"CONNECTING\" | \"READY\" | \"TRANSIENT_FAILURE\" | \"SHUTDOWN\";\n\n/** These states are in the sequence of the enum of grpc-js: the index of a state is its value. */\nexport const GRPC_STATES: readonly GrpcState[] = [\"IDLE\", \"CONNECTING\", \"READY\", \"TRANSIENT_FAILURE\", \"SHUTDOWN\"];\n\n/** A status is the end of one call: its code (0 is OK) and its details. */\nexport interface GrpcStatus {\n readonly code: number;\n readonly details: string;\n}\n\n/** A call handle stops one call in flight. The grpc-js driver then writes RST_STREAM with the code CANCEL. */\nexport interface GrpcCallHandle {\n cancel(): void;\n}\n\n/**\n * A channel is the part of a `Client` of grpc-js 1.14 that the wrapper uses. A fake for tests has\n * each part too. Thus the package depends on no type of grpc-js.\n */\nexport interface GrpcChannel {\n /** This method gives the state of the channel. True also starts a connect when the channel is IDLE. */\n state(connect: boolean): GrpcState;\n /** This method starts `changed` one time, when the state of the channel is no longer `current`. */\n watch(current: GrpcState, changed: () => void): void;\n /**\n * This method sends one unary call: the method path and the bytes of its request message. `done`\n * gets the status of the call, and the bytes of the response message when the status is OK. The\n * call ends at `timeout` milliseconds with DEADLINE_EXCEEDED, and grpc-js sends the header `grpc-timeout`.\n */\n unary(\n method: string,\n request: Buffer,\n metadata: Readonly<Record<string, string>>,\n timeout: number,\n done: (status: GrpcStatus, response: Buffer | undefined) => void,\n ): GrpcCallHandle;\n /** This method closes the channel. Its state becomes SHUTDOWN, and it does not connect again. */\n close(): void;\n}\n\n/**\n * These are the options of the channel that the wrapper gives `new Client(target, credentials, options)`.\n * Each time comes from the declaration, in milliseconds.\n */\nexport interface GrpcChannelOptions {\n /** The wrapper turns off the retries of grpc-js, the transparent retry too. Only the core decides a second send. */\n readonly \"grpc.enable_retries\": 0;\n /** The wrapper reads no service config from the resolver. Thus no record of DNS changes the policy of a call. */\n readonly \"grpc.service_config_disable_resolution\": 1;\n /** This time is the interval of the HTTP/2 PING of keepalive. Without it, grpc-js sends no PING. */\n readonly \"grpc.keepalive_time_ms\"?: number | undefined;\n /** This time bounds the ACK of each PING. Without an ACK in this time, grpc-js ends the transport. */\n readonly \"grpc.keepalive_timeout_ms\": number;\n /** 1 sends the PING with no call in flight too. The server must permit that, or it answers with GOAWAY too_many_pings (O26). */\n readonly \"grpc.keepalive_permit_without_calls\": 0 | 1;\n /** This time with no call puts the channel in IDLE, and closes its connection. */\n readonly \"grpc.client_idle_timeout_ms\": number;\n /** This time is the first delay of grpc-js before a new try to connect. */\n readonly \"grpc.initial_reconnect_backoff_ms\": number;\n /** This time is the most that one delay of grpc-js can be, before its jitter of 20 %. */\n readonly \"grpc.max_reconnect_backoff_ms\": number;\n}\n\n/** These are the arguments of `new Client(target, credentials, options)`. The credentials are insecure: the client speaks h2c. */\nexport interface GrpcConnectOptions {\n readonly target: string;\n readonly options: GrpcChannelOptions;\n}\n\n/** A channel factory makes one channel from its options. The channel connects later, when the wrapper asks it. */\nexport type GrpcFactory = Factory<GrpcConnectOptions, GrpcChannel>;\n\n/** This type is the part of a `Client` of grpc-js 1.14 that the adapter uses. */\ninterface GrpcDriverClient {\n getChannel(): {\n getConnectivityState(connect: boolean): number;\n watchConnectivityState(current: number, deadline: number, callback: (error?: Error) => void): void;\n };\n makeUnaryRequest(\n method: string,\n serialize: (value: Buffer) => Buffer,\n deserialize: (bytes: Buffer) => Buffer,\n argument: Buffer,\n metadata: unknown,\n options: { readonly deadline: number },\n callback: (error: { readonly code?: number; readonly details?: string; readonly message?: string } | null, value?: Buffer) => void,\n ): GrpcCallHandle;\n close(): void;\n}\n\n/** This type is the part of the module of grpc-js that the adapter uses. */\ninterface GrpcDriver {\n readonly Client: new (target: string, credentials: unknown, options: GrpcChannelOptions) => GrpcDriverClient;\n readonly credentials: { createInsecure(): unknown };\n readonly Metadata: new () => { add(key: string, value: string): void };\n}\n\n/** These functions give the bytes of a message as they are. The caller encodes and decodes its messages. */\nconst identity = (bytes: Buffer): Buffer => bytes;\n\n/** This function gives the state of a value of the enum of grpc-js. */\nconst stateOf = (value: number): GrpcState => GRPC_STATES[value] ?? \"SHUTDOWN\";\n\n/**\n * This function adapts a `Client` of grpc-js to a channel. The deadline of grpc-js is a time of the\n * wall clock, thus the adapter adds the timeout to `Date.now()`.\n */\nexport const adaptGrpc = (grpc: GrpcDriver, client: GrpcDriverClient): GrpcChannel => {\n const channel = client.getChannel();\n return {\n state: (connect) => stateOf(channel.getConnectivityState(connect)),\n watch(current, changed) {\n try {\n channel.watchConnectivityState(GRPC_STATES.indexOf(current), Number.POSITIVE_INFINITY, (error) => {\n if (error === undefined) changed();\n });\n } catch {\n // The grpc-js driver throws when the channel is shut down: no state comes after SHUTDOWN\n }\n },\n unary(method, request, metadata, timeout, done) {\n const sent = new grpc.Metadata();\n for (const [key, value] of Object.entries(metadata)) sent.add(key, value);\n const deadline = Number.isFinite(timeout) ? Date.now() + timeout : Number.POSITIVE_INFINITY;\n return client.makeUnaryRequest(method, identity, identity, request, sent, { deadline }, (error, value) => {\n if (error === null) done({ code: 0, details: \"\" }, value ?? Buffer.alloc(0));\n else done({ code: error.code ?? 2, details: error.details ?? error.message ?? \"\" }, undefined);\n });\n },\n close: () => client.close(),\n };\n};\n\n/**\n * This factory makes a `Client` of grpc-js. It loads grpc-js only when a client connects, thus a\n * service that does not use gRPC does not need it. The specifier is a value, thus the package needs no types of grpc-js.\n */\nexport const nodeGrpc: GrpcFactory = async ({ target, options }) => {\n const specifier = \"@grpc/grpc-js\";\n const loaded = (await import(specifier)) as Partial<GrpcDriver> & { readonly default?: GrpcDriver };\n const grpc = loaded.Client === undefined ? loaded.default : (loaded as GrpcDriver);\n if (grpc?.Client === undefined) throw new Error(\"@grpc/grpc-js gives no Client class\");\n return adaptGrpc(grpc, new grpc.Client(target, grpc.credentials.createInsecure(), options));\n};\n","import type { Detector, Meeting, Situation } from \"../client/meets.ts\";\nimport { NEVER, WHAT, immediate, kernelGiveUp } from \"../client/meets.ts\";\nimport { finiteMs } from \"../client/core.ts\";\nimport { heartbeatDetection } from \"../timing.ts\";\nimport type { GrpcKnobs } from \"./client.ts\";\n\n/**\n * This function gives the manifestations that a gRPC client can meet, and the detectors of each,\n * from its knobs. The gRPC cells measured them on grpc-js 1.14.6:\n * - At its defaults, grpc-js has no detector: no keepalive, no deadline, and no TCP keepalive.\n * - A reset gave each call ECONNRESET in 1.1 ms to 1.4 ms. The FIN of a stopped server ended an idle connection in 43 µs.\n * - The keepalive ended a silent transport at keepalive_time + keepalive_timeout: 80.012 s at 60 s\n * against etcd, and 320.005 s at 300 s against grpc-go (DP24).\n * - Without `keepaliveWithoutCalls`, grpc-js sends a PING only with a call in flight.\n * - At client_idle_timeout, the channel goes IDLE, and the client connects again. A server that does\n * not answer then keeps the channel out of READY.\n */\nexport const grpcMeetings = (name: string, knobs: GrpcKnobs, withoutCalls: boolean): Meeting[] => {\n const interval = finiteMs(knobs.keepalive_time);\n const detection = heartbeatDetection(knobs.keepalive_time, knobs.keepalive_timeout, 1);\n const keepalive = (situation: Situation): Detector => ({\n by: \"heartbeat_detection_time\",\n within: situation === \"idle\" && !withoutCalls ? NEVER : detection,\n situation,\n effect:\n situation === \"idle\" && !withoutCalls\n ? \"grpc-js sends no PING with no call in flight\"\n : `the PING gets no ACK in keepalive_timeout, the transport ends, each call in flight fails with UNAVAILABLE, and ${name} connects again`,\n });\n const deadline: Detector = {\n by: \"request_timeout\",\n within: knobs.request_timeout,\n situation: \"in flight\",\n effect: \"the deadline ends the call with DEADLINE_EXCEEDED as indeterminate, and the transport stays\",\n };\n // A new connection after client_idle_timeout meets the failure, and the channel does not become READY\n const reconnect: Detector = {\n by: \"client_idle_timeout\",\n within: knobs.client_idle_timeout,\n situation: \"idle\",\n effect: `the channel goes IDLE, ${name} connects again, and the new connection does not become ready`,\n };\n const giveUp = kernelGiveUp(knobs.retrans_giveup_time, \"each call in flight fails with UNAVAILABLE\");\n const silent = (manifestation: \"blackhole\" | \"freeze-host\"): Meeting => ({\n manifestation,\n what: WHAT[manifestation],\n detectors: [deadline, keepalive(\"in flight\"), giveUp, keepalive(\"idle\"), reconnect],\n });\n return [\n {\n manifestation: \"rst\",\n what: WHAT.rst,\n detectors: [\n immediate(\"in flight\", \"the reset arrives, each call fails with UNAVAILABLE as indeterminate, and the channel goes IDLE\"),\n {\n by: \"keepalive_time\",\n within: interval === undefined || !withoutCalls ? NEVER : knobs.keepalive_time,\n situation: \"idle\",\n effect: \"the next PING gets a reset, and the client connects again\",\n },\n { ...reconnect, effect: `the channel goes IDLE, ${name} connects again, and the server refuses the connect` },\n ],\n },\n {\n manifestation: \"fin\",\n what: WHAT.fin,\n detectors: [\n immediate(\"in flight\", \"the FIN arrives, and each call fails with UNAVAILABLE as indeterminate\"),\n immediate(\"idle\", \"the FIN arrives, the channel goes IDLE, 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 // The kernel of the server completes a new TCP connect, but its process sends no SETTINGS frame\n detectors: [deadline, keepalive(\"in flight\"), keepalive(\"idle\"), reconnect],\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: [\n deadline,\n { ...keepalive(\"idle\"), within: NEVER, effect: \"the library of the server still answers each PING with an ACK\" },\n { ...reconnect, within: NEVER, effect: \"the library of the server still takes a new connection\" },\n ],\n },\n ];\n};\n","import type { Extent, Quantity } from \"@mark1russell7/quantity\";\nimport type { CallContext } from \"../call-context.ts\";\nimport { realClock } from \"../clock.ts\";\nimport type {\n Attempt,\n CheckOptions,\n Client,\n ClientJoin,\n ClientKnobs,\n ClientOptions,\n ClientSpec,\n ClientStep,\n DialFn,\n RetryKnobs,\n SendOptions,\n Sent,\n} from \"../client/core.ts\";\nimport {\n ageProblems,\n attachClient,\n clientBounds,\n clientProblems,\n clientRecorder,\n dialCheck,\n finiteMs,\n idleCloseProblem,\n inFlight,\n localStateCheck,\n message,\n ms,\n notSent,\n operationTable,\n readyWait,\n retryProblems,\n roundTripCheck,\n sendWithReissue,\n socketEnds,\n stepChecks,\n timeProblems,\n wholeProblems,\n withinBound,\n wrapperTimerProblems,\n zeroProblems,\n} from \"../client/core.ts\";\nimport type { Judge } from \"../client/dial.ts\";\nimport { authority, helloDial } from \"../client/dial.ts\";\nimport { NEVER } from \"../client/meets.ts\";\nimport type { Dependency } from \"../description.ts\";\nimport type { DependencyHandle } from \"../lifecycle.ts\";\nimport type { Operation } from \"../operation.ts\";\nimport { heartbeatDetection } from \"../timing.ts\";\nimport type { GrpcCallHandle, GrpcChannel, GrpcConnectOptions, GrpcFactory, GrpcState, GrpcStatus } from \"./connection.ts\";\nimport { nodeGrpc } from \"./connection.ts\";\nimport { grpcMeetings } from \"./meets.ts\";\n\n/**\n * These are the knobs of the client, each a time, by the names of the ordering law and of the gRPC\n * cells. The runtime has no defaults, thus each knob is necessary. The constant\n * `GRPC_CLIENT_STARTING_KNOBS` gives a declaration from the gRPC cells. The knobs that each client has come from the core.\n */\nexport interface GrpcKnobs extends ClientKnobs, RetryKnobs {\n /** 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. */\n readonly connect_bound: Quantity;\n /** 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`. */\n readonly request_timeout: Quantity;\n /** 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. */\n readonly keepalive_time: Extent;\n /** This time bounds the ACK of each PING (`grpc.keepalive_timeout_ms`). With no ACK, grpc-js ends the transport. */\n readonly keepalive_timeout: Quantity;\n /** This time with no call puts the channel in IDLE and closes its connection (`grpc.client_idle_timeout_ms`). The client then connects again. */\n readonly client_idle_timeout: Quantity;\n /**\n * This time is the shortest interval of the PING that the server permits: `MinTime` of the\n * 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.\n */\n readonly server_keepalive_min_time: Quantity;\n /** This time is when the server or a proxy ends an idle connection with GOAWAY, or \"infinite\". The client must close first (O01). */\n readonly server_idle_close: Extent;\n /** This time is the first delay of grpc-js before a new try to connect (`grpc.initial_reconnect_backoff_ms`). */\n readonly retry_base: Quantity;\n /** This time is the most that one delay of grpc-js can be, before its jitter of 20 % (`grpc.max_reconnect_backoff_ms`). */\n readonly retry_cap: Quantity;\n /** 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\". */\n readonly keepalive_idle: Extent;\n /** The client does not replace its connection at an age, thus this knob must be \"infinite\". */\n readonly max_connection_age: Extent;\n /** This time bounds the close at the shutdown: the calls in flight. At the bound, the client cancels each call, then closes the channel. */\n readonly close_bound: Quantity;\n}\n\n/** A gRPC client spec is the declaration of one gRPC client: where it connects, and its knobs. */\nexport interface GrpcClientSpec extends ClientSpec<GrpcKnobs> {\n /**\n * True sends the PING of keepalive with no call in flight too (`grpc.keepalive_permit_without_calls`).\n * The server must permit that (`PermitWithoutStream` of grpc-go), or it answers with GOAWAY too_many_pings (O26).\n */\n readonly keepaliveWithoutCalls: boolean;\n /** These headers go with each call, for example `authorization`. The metadata of a call adds to them. */\n readonly metadata?: Readonly<Record<string, string>> | undefined;\n /** This name is the service that the round-trip check asks the health service about. The default is \"\", the whole server. */\n readonly healthService?: string | undefined;\n /**\n * These operations are the methods of the service, by their full path, with their idempotency. The\n * client sends again only a method that this table names as idempotent. `grpcOperations` makes the\n * table from the `idempotency_level` of each method in its proto.\n */\n readonly operations?: ClientSpec<GrpcKnobs>[\"operations\"];\n}\n\n/** These options make a client. Without them, it uses grpc-js, the real clock, and a dial with the HTTP/2 preface. */\nexport interface GrpcClientOptions extends ClientOptions<GrpcFactory> {\n /**\n * With this call context, each call gets the headers of the active context of its caller in its\n * metadata, for example `traceparent`. The metadata of the spec and of the call stays. `callContext` of the entry `/otel` gives one.\n */\n readonly callContext?: CallContext | undefined;\n}\n\n/**\n * A join is one generation of the client: each time that its channel becomes READY (D1, D2). The\n * grpc-js driver gives no socket of its transport, thus the ends of the socket are null.\n */\nexport interface GrpcJoin extends ClientJoin {\n /** This text is the target of the channel. */\n readonly target: string;\n}\n\n/** These options tell how the client sends one call. */\nexport interface GrpcCallOptions extends SendOptions {\n /** These headers go with this call, after the metadata of the spec. */\n readonly metadata?: Readonly<Record<string, string>> | undefined;\n}\n\n/** A serving status is the status of a HealthCheckResponse of the health service (grpc.health.v1). */\nexport type GrpcServingStatus = \"UNKNOWN\" | \"SERVING\" | \"NOT_SERVING\" | \"SERVICE_UNKNOWN\";\n\n/** A gRPC client is a dependency of a service: its declaration, its handle, its checks and its calls. */\nexport interface GrpcClient extends Client<ClientStep, GrpcJoin> {\n /** This text is the state of the client, as `GRPC_CLIENT_MACHINE` names it. */\n readonly status: string;\n /**\n * This method sends one unary call, and waits for its status. `request` holds the bytes of the\n * request message, and an OK status gives the bytes of the response message. The client sends again\n * only an idempotent method, one time at most, after an outcome that is not certain.\n */\n call(method: string, request: Buffer, options?: GrpcCallOptions): Promise<Sent<Buffer>>;\n /** This method sends one Check of the health service (grpc.health.v1), and gives the serving status of the reply. */\n health(service?: string, options?: SendOptions): Promise<Sent<GrpcServingStatus>>;\n}\n\n/** The names of the status codes of gRPC, by their value. */\nexport const GRPC_CODES = [\n \"OK\",\n \"CANCELLED\",\n \"UNKNOWN\",\n \"INVALID_ARGUMENT\",\n \"DEADLINE_EXCEEDED\",\n \"NOT_FOUND\",\n \"ALREADY_EXISTS\",\n \"PERMISSION_DENIED\",\n \"RESOURCE_EXHAUSTED\",\n \"FAILED_PRECONDITION\",\n \"ABORTED\",\n \"OUT_OF_RANGE\",\n \"UNIMPLEMENTED\",\n \"INTERNAL\",\n \"UNAVAILABLE\",\n \"DATA_LOSS\",\n \"UNAUTHENTICATED\",\n] as const;\n\n/**\n * These codes are certain errors: each one tells that the server or a proxy refused the call, and did\n * not apply it. A proxy that answers 401, 403 or 404 gives UNAUTHENTICATED, PERMISSION_DENIED or UNIMPLEMENTED.\n */\nconst CERTAIN = new Set([3, 5, 6, 7, 9, 10, 11, 12, 16]);\n\n/**\n * These statuses of grpc-js tell that the call did not leave the client. A status with another\n * details text of the same code can come after the send, thus it is indeterminate:\n * - UNAVAILABLE \"No connection established\": the pick of a channel in TRANSIENT_FAILURE (picker.ts:105).\n * - UNAVAILABLE \"Name resolution failed\": the resolver found no address (resolver-dns.ts:119).\n * - UNAVAILABLE \"Stream refused by server\": RST_STREAM REFUSED_STREAM. The server did not process the stream (RFC 9113 §8.7).\n * - INTERNAL \"Failed to start HTTP/2 stream\": the stream did not start (load-balancing-call.ts:281).\n * - DEADLINE_EXCEEDED with \"Waiting for LB pick\" or \"waiting for name resolution\": the deadline came before a stream.\n */\nconst NOT_SENT: ReadonlyArray<readonly [number, RegExp]> = [\n [14, /^No connection established/],\n [14, /^Name resolution failed/],\n [14, /^Stream refused by server$/],\n [13, /^Failed to start HTTP\\/2 stream/],\n [4, /(^|,)(Waiting for LB pick|waiting for name resolution)(,|$)/],\n];\n\n/** This function gives the name of a status code, for example \"UNAVAILABLE\". */\nexport const codeName = (code: number): string => GRPC_CODES[code] ?? `code ${code}`;\n\n/**\n * This function gives the outcome of one call from its status:\n * - OK is `ok`.\n * - A code that tells that the server refused the call is a certain error: `reply` is true.\n * - A status that tells that the call did not leave the client is a certain error with `reply` false.\n * - Each other status is indeterminate: CANCELLED, UNKNOWN, DEADLINE_EXCEEDED, RESOURCE_EXHAUSTED,\n * INTERNAL, UNAVAILABLE and DATA_LOSS can come after the server applied the call.\n */\nexport const grpcOutcome = (status: GrpcStatus, response: Buffer | undefined): Attempt<Buffer> => {\n if (status.code === 0) return { outcome: \"ok\", value: response ?? Buffer.alloc(0) };\n const error = `${codeName(status.code)}: ${status.details}`;\n if (CERTAIN.has(status.code)) return { outcome: \"error\", error, reply: true };\n if (NOT_SENT.some(([code, details]) => code === status.code && details.test(status.details))) return notSent(`${error} (the call did not leave the client)`);\n return { outcome: \"indeterminate\", error };\n};\n\n/** This method is the Check of the health service. Its request names a service, and its response gives a serving status. */\nexport const HEALTH_CHECK = \"/grpc.health.v1.Health/Check\";\n\n/** These operations are in each table: the Check of the health service has no side effects. */\nexport const GRPC_OPERATIONS: Readonly<Record<string, Operation>> = { [HEALTH_CHECK]: { idempotent: true } };\n\n/** An idempotency level is the option `idempotency_level` of a method in its proto (descriptor.proto). */\nexport type GrpcIdempotencyLevel = \"IDEMPOTENCY_UNKNOWN\" | \"NO_SIDE_EFFECTS\" | \"IDEMPOTENT\";\n\n/**\n * This function makes a table of operations from the idempotency level of each method, by its full\n * path. NO_SIDE_EFFECTS and IDEMPOTENT are idempotent. IDEMPOTENCY_UNKNOWN, the default of a proto, is not.\n */\nexport const grpcOperations = (levels: Readonly<Record<string, GrpcIdempotencyLevel>>): Record<string, Operation> =>\n Object.fromEntries(Object.entries(levels).map(([method, level]) => [method, { idempotent: level !== \"IDEMPOTENCY_UNKNOWN\" }]));\n\n/** This function gives the bytes of a varint of protobuf. */\nconst varint = (value: number): Buffer => {\n const bytes: number[] = [];\n let rest = value;\n while (rest > 0x7f) {\n bytes.push((rest & 0x7f) | 0x80);\n rest = Math.floor(rest / 128);\n }\n bytes.push(rest);\n return Buffer.from(bytes);\n};\n\n/** This function gives the bytes of a HealthCheckRequest. The service \"\" is the whole server, and its message is empty. */\nexport const healthRequest = (service: string): Buffer => {\n if (service === \"\") return Buffer.alloc(0);\n const name = Buffer.from(service, \"utf8\");\n return Buffer.concat([Buffer.from([0x0a]), varint(name.length), name]);\n};\n\nconst SERVING: readonly GrpcServingStatus[] = [\"UNKNOWN\", \"SERVING\", \"NOT_SERVING\", \"SERVICE_UNKNOWN\"];\n\n/** This function gives the status of a HealthCheckResponse, or null when the bytes are not one. An empty message is UNKNOWN. */\nexport const healthStatus = (bytes: Buffer): GrpcServingStatus | null => {\n let at = 0;\n let status = 0;\n const read = (): number | null => {\n let value = 0;\n for (let shift = 0; shift < 35; shift += 7) {\n const byte = bytes[at];\n if (byte === undefined) return null;\n at += 1;\n value += (byte & 0x7f) * 2 ** shift;\n if ((byte & 0x80) === 0) return value;\n }\n return null;\n };\n while (at < bytes.length) {\n const tag = read();\n if (tag === null) return null;\n const wire = tag & 7;\n if (wire === 0) {\n const value = read();\n if (value === null) return null;\n if (tag >> 3 === 1) status = value;\n } else if (wire === 2) {\n const length = read();\n if (length === null || at + length > bytes.length) return null;\n at += length;\n } else if (wire === 1 || wire === 5) {\n at += wire === 1 ? 8 : 4;\n if (at > bytes.length) return null;\n } else return null;\n }\n return SERVING[status] ?? null;\n};\n\n/** The longest timer of Node, in milliseconds. A longer delay starts at 1 ms, thus grpc-js cannot take it. */\nconst LONGEST_TIMER = 0x7fffffff;\n\n/** 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. */\nconst longestTimerProblems = (name: string, knobs: object, names: readonly string[]): string[] =>\n names.flatMap((knob) => {\n const amount = (knobs as Record<string, Extent>)[knob]!;\n return amount.value !== \"infinite\" && ms(amount) > LONGEST_TIMER ? [`${name}'s ${knob} is above ${LONGEST_TIMER} ms, the longest timer of Node`] : [];\n });\n\n/** This function gives the problems of a spec: the knobs that the client cannot use. */\nexport const specProblems = (name: string, spec: GrpcClientSpec): string[] => {\n const { knobs } = spec;\n const timers = [\"keepalive_time\", \"keepalive_timeout\", \"client_idle_timeout\", \"retry_base\", \"retry_cap\"];\n const problems = [\n ...timeProblems(name, knobs),\n // The grpc-js driver has no connect timeout, and gives a call no deadline: the wrapper gives both\n ...wrapperTimerProblems(name, knobs, { connect_bound: \"the wait of the startup for a ready channel\", request_timeout: \"a call\" }),\n ...zeroProblems(name, \"grpc-js\", knobs, { open: [\"keepalive_time\"] }),\n // The grpc-js driver takes each timer in whole milliseconds\n ...wholeProblems(name, knobs, { millis: timers }),\n ...longestTimerProblems(name, knobs, timers),\n ...retryProblems(name, knobs),\n ...ageProblems(name, knobs, \"grpc-js does not replace its connection at an age\"),\n ];\n for (const knob of [\"keepalive_timeout\", \"client_idle_timeout\", \"retry_base\", \"retry_cap\"] as const)\n if (finiteMs(knobs[knob]) === undefined || !(ms(knobs[knob]) > 0)) problems.push(`${name}'s ${knob} is not a finite time above zero`);\n // The grpc-js driver raises an idle timeout below 1 s to 1 s (internal-channel.ts:323-326)\n if (ms(knobs.client_idle_timeout) < 1000) problems.push(`${name}'s client_idle_timeout is below 1 s: grpc-js raises it to 1 s`);\n if (knobs.keepalive_idle.value !== \"infinite\")\n problems.push(`${name}'s keepalive_idle is not \"infinite\": grpc-js sets no TCP keepalive, and the PING of keepalive_time is its keepalive`);\n if (spec.password !== undefined) problems.push(`${name} takes no password: give the credentials in metadata, for example authorization`);\n return problems;\n};\n\n/** This function gives the target of a channel from a spec: the host and the port, for the DNS resolver of grpc-js. */\nexport const grpcTarget = (spec: Pick<GrpcClientSpec, \"host\" | \"port\">): string => authority(spec.host, spec.port);\n\n/**\n * This function gives the arguments of `new Client` from a spec. Each timer of grpc-js comes from the\n * declaration. The retries of grpc-js are off, and the resolver gives no service config.\n */\nexport const grpcOptions = (spec: GrpcClientSpec): GrpcConnectOptions => {\n const { knobs } = spec;\n const keepalive = finiteMs(knobs.keepalive_time);\n return {\n target: grpcTarget(spec),\n options: {\n \"grpc.enable_retries\": 0,\n \"grpc.service_config_disable_resolution\": 1,\n ...(keepalive === undefined ? {} : { \"grpc.keepalive_time_ms\": keepalive }),\n \"grpc.keepalive_timeout_ms\": ms(knobs.keepalive_timeout),\n \"grpc.keepalive_permit_without_calls\": spec.keepaliveWithoutCalls ? 1 : 0,\n \"grpc.client_idle_timeout_ms\": ms(knobs.client_idle_timeout),\n \"grpc.initial_reconnect_backoff_ms\": ms(knobs.retry_base),\n \"grpc.max_reconnect_backoff_ms\": ms(knobs.retry_cap),\n },\n };\n};\n\n/** These are the bytes of the dial: the connection preface of the client (RFC 9113 §3.4), and a SETTINGS frame with no setting. */\nexport const HTTP2_PREFACE: Buffer = Buffer.concat([Buffer.from(\"PRI * HTTP/2.0\\r\\n\\r\\nSM\\r\\n\\r\\n\", \"latin1\"), Buffer.from([0, 0, 0, 4, 0, 0, 0, 0, 0])]);\n\n/**\n * This judge reads the first frame of the server. Only a SETTINGS frame on stream 0, with no ACK,\n * 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.\n */\nexport const settingsJudge: Judge = (received) => {\n if (received.length < 9) return \"more\";\n const type = received[3];\n const flags = received[4]!;\n const stream = received.readUInt32BE(5) & 0x7fffffff;\n return type === 0x04 && (flags & 0x01) === 0 && stream === 0\n ? null\n : 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\")}`);\n};\n\n/** 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. */\nexport const grpcDial: DialFn = helloDial(HTTP2_PREFACE, settingsJudge);\n\n/**\n * This function makes a gRPC client, a dependency of a service over grpc-js 1.14.\n * - It has one channel for its life. Each time that the channel becomes READY is one generation.\n * - The grpc-js driver connects again by itself, after its own backoff. The client connects an IDLE channel again at once.\n * - A call is one unary call, until its status. Its deadline is the time that is left in `request_timeout`.\n * - It tells the outcome of a call in three values from its status code (C8).\n * - The retries of grpc-js are off, thus only the core sends a call again.\n * - Its keepalive is the HTTP/2 PING of grpc-js. It records the target of each generation (D1).\n *\n * These parts come from the core of the clients: the outcomes, the second try and the wait for a ready client.\n * 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.\n */\nexport const grpcClient = (name: string, spec: GrpcClientSpec, options: GrpcClientOptions = {}): GrpcClient => {\n const problems = specProblems(name, spec);\n if (problems.length > 0) throw new Error(problems.join(\"; \"));\n const { knobs } = spec;\n const clock = options.clock ?? realClock;\n const create = options.create ?? nodeGrpc;\n const dial = options.dial ?? grpcDial;\n const operations = operationTable(GRPC_OPERATIONS, spec.operations);\n const requestTimeout = ms(knobs.request_timeout);\n const target = grpcTarget(spec);\n\n let status = \"none\";\n let channel: GrpcChannel | null = null;\n // This function ends the wait of the startup, at the first READY or TRANSIENT_FAILURE\n let settled: (() => void) | null = null;\n const joins: GrpcJoin[] = [];\n const flight = inFlight();\n const readied = readyWait(clock, () => status === \"ready\");\n\n const emit = clientRecorder(options.record, clock, name);\n const record = (on: string, to: string = status, detail?: string): void => {\n const from = status;\n status = to;\n emit(from, to, on, detail);\n };\n const closing = (): boolean => status === \"closing\" || status === \"end\";\n\n /** This function follows one state of the channel. The grpc-js driver ends each call in flight by itself when its transport ends. */\n const follow = (c: GrpcChannel, state: GrpcState): void => {\n if (c !== channel || closing()) return;\n if (state === \"READY\") {\n if (status === \"ready\") return;\n const generation = joins.length + 1;\n joins.push({ generation, at: clock.now(), target, ...socketEnds(undefined) });\n record(\"join\", \"ready\", `generation ${generation}, ${target}`);\n readied.wake();\n settled?.();\n } else if (state === \"TRANSIENT_FAILURE\") {\n if (status === \"failing\") return;\n record(\"connect.failed\", \"failing\", \"the channel is in TRANSIENT_FAILURE: grpc-js connects again after its backoff\");\n settled?.();\n } else if (state === \"CONNECTING\") {\n if (status !== \"connecting\") record(\"channel.connecting\", \"connecting\", target);\n } else if (state === \"IDLE\") {\n if (status === \"ready\") record(\"connection.end\", \"idle\", \"the transport ended: a GOAWAY, a reset, a FIN, the keepalive, or client_idle_timeout\");\n else if (status !== \"idle\") record(\"channel.idle\", \"idle\", \"the channel is IDLE\");\n // An IDLE channel connects only for a call: the client connects at once, thus readiness is earned again\n c.state(true);\n }\n };\n\n /** This function watches the state of the channel. It watches again before it follows, thus no change goes away. */\n const watch = (c: GrpcChannel, current: GrpcState): void =>\n c.watch(current, () => {\n if (c !== channel || closing()) return;\n const next = c.state(false);\n if (next !== \"SHUTDOWN\") watch(c, next);\n follow(c, next);\n });\n\n /** This function gives the channel for a call, or the reason that the call does not leave the client. */\n const usable = (signal: AbortSignal | undefined): GrpcChannel | Attempt<never> => {\n if (status === \"none\") return notSent(`${name} has not connected`);\n if (status !== \"ready\" || channel === null) return notSent(`${name} is ${status}, not ready: the call did not leave the client`);\n if (signal?.aborted) return notSent(\"the caller aborted the call before it left the client\");\n return channel;\n };\n\n /** This function makes one try of a call: the unary call until its status, with the deadline that is left. */\n const attempt = (\n method: string,\n request: Buffer,\n metadata: Readonly<Record<string, string>>,\n timeout: number,\n signal: AbortSignal | undefined,\n ): Promise<Attempt<Buffer>> => {\n const c = usable(signal);\n if (\"outcome\" in c) return Promise.resolve(c);\n if (!(timeout > 0)) return Promise.resolve(notSent(\"no time is left in request_timeout\"));\n let handle: GrpcCallHandle | null = null;\n let ended = false;\n return flight.track<Buffer>(\n signal,\n \"the caller abandoned the call after it left the client\",\n (settle) => {\n try {\n handle = c.unary(method, request, metadata, timeout, (given, response) => {\n ended = true;\n settle(grpcOutcome(given, response));\n });\n } catch (error) {\n ended = true;\n settle(notSent(message(error)));\n }\n },\n // A call that the caller abandons, or that the close ends, gets RST_STREAM CANCEL\n () => {\n if (!ended) handle?.cancel();\n },\n );\n };\n\n const call = (method: string, request: Buffer, callOptions: GrpcCallOptions = {}): Promise<Sent<Buffer>> => {\n const started = clock.now();\n // the headers of the context of the caller, read now: each try of the call sends the same ones\n const metadata = { ...options.callContext?.headers(), ...spec.metadata, ...callOptions.metadata };\n return sendWithReissue({\n clock,\n bound: requestTimeout,\n operation: operations[method],\n options: callOptions,\n // The deadline of each try is the time that is left: a second try ends at the bound of the call\n attempt: (signal) => attempt(method, request, metadata, requestTimeout - (clock.now() - started), signal),\n // The grpc-js driver connects again by itself: the second try waits for a ready channel, in the time that is left\n beforeAgain: (left, signal) => readied.wait(left, signal),\n onReissue: () => record(\"command.reissue\", status, method),\n });\n };\n\n const health = async (service = \"\", sendOptions: SendOptions = {}): Promise<Sent<GrpcServingStatus>> => {\n const sent = await call(HEALTH_CHECK, healthRequest(service), sendOptions);\n if (sent.outcome !== \"ok\") return sent;\n const serving = healthStatus(sent.value);\n return serving === null\n ? { outcome: \"error\", error: \"the response is not a HealthCheckResponse\", reply: true, attempts: sent.attempts }\n : { outcome: \"ok\", value: serving, attempts: sent.attempts };\n };\n\n const handle: DependencyHandle = {\n async connect(signal) {\n if (signal.aborted) throw new Error(`${name}: the service stopped before the connect`);\n record(\"status.connecting\", \"connecting\", target);\n let c: GrpcChannel;\n try {\n c = await create(grpcOptions(spec));\n } catch (error) {\n record(\"connect.failed\", \"failing\", message(error));\n throw error;\n }\n if (closing()) {\n c.close();\n return;\n }\n channel = c;\n const first = new Promise<void>((resolve) => (settled = resolve));\n // A server that is down does not stop the startup: grpc-js connects again in the background,\n // and the checks keep readiness tripped until the channel is ready (readiness is earned)\n const now = c.state(true);\n watch(c, now);\n if (now !== \"IDLE\") follow(c, now);\n // The wait ends at the first READY or TRANSIENT_FAILURE, or at connect_bound. A connect into a black hole stays CONNECTING\n await withinBound(clock, ms(knobs.connect_bound), first);\n settled = null;\n },\n async close() {\n if (status === \"none\" || closing()) return;\n record(\"close.request\", \"closing\");\n settled?.();\n const c = channel;\n if (c !== null) {\n // The calls in flight end first. At the bound, each one gets RST_STREAM CANCEL, and then the channel closes\n if (!(await withinBound(clock, ms(knobs.close_bound), flight.idle()))) {\n record(\"close.bound\", \"closing\");\n record(\"close.destroy\", \"closing\", `${flight.size} calls in flight`);\n flight.settleAll(\"the client closed with the call in flight\");\n }\n c.close();\n }\n channel = null;\n flight.settleAll(\"the client closed with the call in flight\");\n record(\"status.end\", \"end\");\n },\n };\n\n const keepalive = finiteMs(knobs.keepalive_time);\n const declaration: Omit<Dependency, \"name\"> = {\n system: spec.system,\n knobs: {\n connect_bound: knobs.connect_bound,\n request_timeout: knobs.request_timeout,\n keepalive_time: knobs.keepalive_time,\n keepalive_timeout: knobs.keepalive_timeout,\n // One PING at a time, and the transport ends at its timeout: keepalive_time + keepalive_timeout\n heartbeat_detection_time: heartbeatDetection(knobs.keepalive_time, knobs.keepalive_timeout, 1),\n client_idle_timeout: knobs.client_idle_timeout,\n retry_base: knobs.retry_base,\n retry_cap: knobs.retry_cap,\n keepalive_idle: knobs.keepalive_idle,\n // A PING with no call in flight refreshes an idle flow (O03). Without it, nothing does\n idle_refresh_interval: spec.keepaliveWithoutCalls && keepalive !== undefined ? knobs.keepalive_time : NEVER,\n max_connection_age: knobs.max_connection_age,\n close_bound: knobs.close_bound,\n retrans_giveup_time: knobs.retrans_giveup_time,\n },\n operations,\n };\n\n /** The round-trip check passes only for SERVING: a health service that answers NOT_SERVING fails it, as a 5xx fails the HTTP check. */\n const roundTrip = async (sendOptions: SendOptions): Promise<Sent<unknown>> => {\n const sent = await health(spec.healthService ?? \"\", sendOptions);\n return sent.outcome === \"ok\" && sent.value !== \"SERVING\"\n ? { outcome: \"error\", error: `the health service answered ${sent.value}`, reply: true, attempts: sent.attempts }\n : sent;\n };\n\n const checks = (checkOptions: CheckOptions) =>\n stepChecks<ClientStep>(name, checkOptions, {\n // The state of the channel, without a round trip\n \"local-state\": localStateCheck(() => status === \"ready\"),\n // A Check of the health service on the channel of the application, until its status\n \"round-trip\": roundTripCheck(roundTrip),\n // A new connection each time, with the HTTP/2 preface\n dial: dialCheck(dial, spec.host, spec.port),\n });\n\n return {\n name,\n declaration,\n handle,\n meets: grpcMeetings(name, knobs, spec.keepaliveWithoutCalls),\n get status() {\n return status;\n },\n joins,\n call,\n health,\n checks,\n attach: (svc, checkOptions) => attachClient(svc, name, declaration, handle, checks(checkOptions)),\n problems(description) {\n const found = clientProblems(name, description, clientBounds(knobs));\n // O01: the channel must close an idle connection before the server or a proxy does\n const idle = idleCloseProblem(name, knobs.client_idle_timeout, knobs.server_idle_close, \"client_idle_timeout\");\n if (idle !== null) found.push(idle);\n // O26: a PING more often than the server permits gets GOAWAY too_many_pings\n if (keepalive !== undefined && keepalive < ms(knobs.server_keepalive_min_time))\n found.push(`${name}'s keepalive_time is below server_keepalive_min_time: the server answers with GOAWAY too_many_pings (O26)`);\n return found;\n },\n };\n};\n","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\", \"idle\", \"failing\"] as const;\nconst LIVE = [...SERVING, \"closing\"] as const;\n\n/**\n * The gRPC client of the service as a `mark1russell7.machine/1` document. It is one channel of\n * grpc-js 1.14 for the life of the client. Each READY of the channel is one generation. The states:\n * - `ready`: the channel is READY, and the client sends each call. The keepalive sends a PING each keepalive_time.\n * - `idle`: the transport ended, or the channel had no call in client_idle_timeout. The client connects again at once.\n * - `failing`: the channel is in TRANSIENT_FAILURE. The grpc-js driver connects again after its backoff.\n * - `closing`: the calls in flight, in `close_bound`. At the bound, each call gets RST_STREAM CANCEL.\n *\n * A test records the transitions of the client and replays them against this document.\n */\nexport const GRPC_CLIENT_MACHINE: Machine = {\n format: \"mark1russell7.machine/1\",\n id: \"service.machine.grpc-client\",\n title: \"The gRPC client of the service, over grpc-js 1.14\",\n layer: \"driver\",\n version: \"0.1.0\",\n sources: [{ ref: \"packages/service/src/grpc (the client implements this document)\", rung: \"implemented\" }],\n states: {\n none: { initial: true, note: \"the client exists, and its channel does not\" },\n connecting: { note: \"the channel is CONNECTING: the TCP connect and the HTTP/2 preface. The grpc-js driver has no connect timeout\" },\n ready: { note: \"the channel is READY. The deadline ends a call that waits, and the keepalive finds a silent transport\" },\n idle: { note: \"the channel is IDLE. The client asks it to connect at once\" },\n failing: { note: \"the channel is in TRANSIENT_FAILURE. The grpc-js driver connects again after its backoff, and each call fails as not sent\" },\n closing: { note: \"the calls in flight, in close_bound. At the bound, each call gets RST_STREAM CANCEL, then the channel closes\" },\n end: { final: true, note: \"the service closed the client\" },\n },\n events: {\n \"status.connecting\": { kind: \"local\" },\n join: { kind: \"rx\", note: \"the channel became READY: a new generation (D1)\" },\n \"connect.failed\": { kind: \"rx\", note: \"the channel went to TRANSIENT_FAILURE: a connect failed\" },\n \"channel.connecting\": { kind: \"rx\", note: \"the channel started a new connect\" },\n \"channel.idle\": { kind: \"rx\", note: \"the channel went to IDLE before it was READY\" },\n \"connection.end\": {\n kind: \"rx\",\n note: \"the transport ended: a GOAWAY, a reset, a FIN, the keepalive, or client_idle_timeout. The grpc-js driver ends each call in flight with UNAVAILABLE\",\n },\n \"command.reissue\": { kind: \"local\" },\n \"close.request\": { kind: \"local\" },\n \"close.bound\": { kind: \"timer\", note: \"the calls in flight did not end in close_bound\" },\n \"close.destroy\": { kind: \"local\", note: \"the client cancels each call in flight, then closes the channel\" },\n \"status.end\": { kind: \"local\" },\n },\n knobs: {\n keepalive_time: knob(\"grpc.keepalive_time_ms\"),\n keepalive_timeout: knob(\"grpc.keepalive_timeout_ms\"),\n client_idle_timeout: knob(\"grpc.client_idle_timeout_ms\"),\n retry_base: knob(\"grpc.initial_reconnect_backoff_ms\"),\n retry_cap: knob(\"grpc.max_reconnect_backoff_ms\"),\n close_bound: knob(\"close.bound\"),\n },\n timers: {\n keepalive: {\n duration: { expr: \"keepalive_time + keepalive_timeout\", unit: \"s\" },\n arms: [\"join\"],\n cancels: [\"connection.end\", \"close.request\"],\n fires: \"connection.end\",\n note: \"a timer of grpc-js: one PING each keepalive_time, and the end of the transport at keepalive_timeout with no ACK\",\n },\n idle: {\n duration: { knob: \"client_idle_timeout\", unit: \"s\" },\n arms: [\"join\"],\n cancels: [\"connection.end\", \"close.request\"],\n fires: \"connection.end\",\n note: \"a timer of grpc-js: client_idle_timeout with no call puts the channel in IDLE\",\n },\n retry: {\n duration: { expr: \"min(retry_cap, retry_base * pow(1.6, fired)) * 1.2\", unit: \"s\" },\n arms: [\"connect.failed\"],\n cancels: [\"close.request\"],\n fires: \"join\",\n backoff: { resets: [\"join\"] },\n note: \"a timer of grpc-js, the most delay: the backoff grows by 1.6 from retry_base to retry_cap, with a jitter of 20 %. The first delay has no jitter\",\n },\n close: closeTimer(),\n },\n transitions: [\n t(\"connect\", \"none\", \"status.connecting\", \"connecting\"),\n t(\"join\", [\"connecting\", \"idle\", \"failing\"], \"join\", \"ready\"),\n t(\"connect-failed\", [\"connecting\", \"idle\", \"ready\"], \"connect.failed\", \"failing\"),\n t(\"retry\", \"failing\", \"join\", \"ready\", { timer: \"retry\" }),\n t(\"channel-connecting\", [\"idle\", \"failing\"], \"channel.connecting\", \"connecting\"),\n t(\"channel-idle\", [\"connecting\", \"failing\"], \"channel.idle\", \"idle\"),\n t(\"connection-end\", \"ready\", \"connection.end\", \"idle\"),\n t(\"keepalive\", \"ready\", \"connection.end\", \"idle\", { timer: \"keepalive\" }),\n t(\"idle-timeout\", \"ready\", \"connection.end\", \"idle\", { timer: \"idle\" }),\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","import { STARTING_POLL } from \"../client/core.ts\";\nimport type { Poll } from \"../timing.ts\";\nimport type { GrpcKnobs } from \"./client.ts\";\n\n/**\n * This poll is the poll of the checks that `GRPC_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 GRPC_CLIENT_STARTING_POLL: Poll = STARTING_POLL;\n\n/**\n * This value tells if the keepalive sends a PING with no call in flight, to start from: false. The\n * grpc-go server refuses such a PING at its defaults (`PermitWithoutStream` false). It answers with GOAWAY too_many_pings (O26).\n */\nexport const GRPC_CLIENT_STARTING_WITHOUT_CALLS = false;\n\n/**\n * These knobs are a declaration to start from, from what the gRPC cells measured on grpc-js 1.14.6.\n * The runtime 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. The grpc-js driver has no connect timeout, thus this bounds the wait of the startup.\n * - `request_timeout` 9.5 s: in the slowest poll of 10 s (O13). In DP44 a deadline of 4 s ended each\n * call at 4.003 s to 4.004 s. The race of the two deadlines gave CANCELLED to 2 to 4 calls of 11.\n * - `keepalive_time` 300 s and `keepalive_timeout` 20 s: DP24. The PING must not come before the\n * `MinTime` of the server, 5 min at the defaults of grpc-go (O26). The transport ended at 320.005 s.\n * Against etcd, with a `MinTime` of 5 s, 60 s ended it at 80.012 s. A PING each 4 s against 5 s got GOAWAY at the 4th PING.\n * - `server_keepalive_min_time` 300 s: the `MinTime` of grpc-go v1.84.0 at its defaults.\n * - `client_idle_timeout` 60 s and `server_idle_close` 75 s: the proxies of the cells sent GOAWAY to an idle connection.\n * They did that at 75 s (nginx), 180 s (Traefik), 300 s (Caddy) and 1 h (Envoy). The client closes first (O01).\n * The default of grpc-js is 30 min.\n * - `retry_base` 1 s: the first backoff of grpc-js in T07, with no jitter. `retry_cap` 4 s: the most\n * delay is 4.8 s with the jitter of 20 %, in the slowest poll of 10 s. The default of grpc-js is 120 s.\n * - `keepalive_idle` \"infinite\": grpc-js sets no TCP keepalive, and the PING is its keepalive.\n * - `max_connection_age` \"infinite\": the client does not replace its connection at an age.\n * - `close_bound` 2 s: the calls in flight, then RST_STREAM CANCEL for each call that stays.\n * - `retrans_giveup_time` 924.6 s: the give-up of Linux at `tcp_retries2 = 15`.\n */\nexport const GRPC_CLIENT_STARTING_KNOBS: GrpcKnobs = {\n connect_bound: { value: 5, unit: \"s\" },\n request_timeout: { value: 9.5, unit: \"s\" },\n keepalive_time: { value: 300, unit: \"s\" },\n keepalive_timeout: { value: 20, unit: \"s\" },\n server_keepalive_min_time: { value: 300, unit: \"s\" },\n client_idle_timeout: { value: 60, unit: \"s\" },\n server_idle_close: { value: 75, unit: \"s\" },\n retry_base: { value: 1, 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":";;;;;AAMA,MAAa,cAAoC;CAAC;CAAQ;CAAc;CAAS;CAAqB;AAAU;;AAgGhH,MAAM,YAAY,UAA0B;;AAG5C,MAAM,WAAW,UAA6B,YAAY,UAAU;;;;;AAMpE,MAAa,aAAa,MAAkB,WAA0C;CACpF,MAAM,UAAU,OAAO,WAAW;CAClC,OAAO;EACL,QAAQ,YAAY,QAAQ,QAAQ,qBAAqB,OAAO,CAAC;EACjE,MAAM,SAAS,SAAS;GACtB,IAAI;IACF,QAAQ,uBAAuB,YAAY,QAAQ,OAAO,GAAG,OAAO,oBAAoB,UAAU;KAChG,IAAI,UAAU,KAAA,GAAW,QAAQ;IACnC,CAAC;GACH,QAAQ,CAER;EACF;EACA,MAAM,QAAQ,SAAS,UAAU,SAAS,MAAM;GAC9C,MAAM,OAAO,IA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AACF;;;;;;;AC1FA,MAAa,4BAAkC;;;;;AAM/C,MAAa,qCAAqC;;;;;;;;;;;;;;;;;;;;;AAsBlD,MAAa,6BAAwC;CACnD,eAAe;EAAE,OAAO;EAAG,MAAM;CAAI;CACrC,iBAAiB;EAAE,OAAO;EAAK,MAAM;CAAI;CACzC,gBAAgB;EAAE,OAAO;EAAK,MAAM;CAAI;CACxC,mBAAmB;EAAE,OAAO;EAAI,MAAM;CAAI;CAC1C,2BAA2B;EAAE,OAAO;EAAK,MAAM;CAAI;CACnD,qBAAqB;EAAE,OAAO;EAAI,MAAM;CAAI;CAC5C,mBAAmB;EAAE,OAAO;EAAI,MAAM;CAAI;CAC1C,YAAY;EAAE,OAAO;EAAG,MAAM;CAAI;CAClC,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"}
@@ -2,6 +2,7 @@ import { n as Clock } from "./clock-DpVgpY4h.js";
2
2
  import { N as Poll, ut as Operation } from "./logger-BN2BfPgU.js";
3
3
  import { C as MANIFESTATIONS, D as firstDetector, E as Situation, O as unwatched, S as Detector, T as Meeting, _ as Sent, a as ClientKnobs, c as ClientSpec, d as Factory, g as SendOptions, h as STARTING_POLL, i as ClientJoin, l as ClientStep, n as CheckOptions, o as ClientOptions, r as Client, s as ClientSocket, t as Attempt, u as DialFn, w as Manifestation } from "./core-Dt0HEVMq.js";
4
4
  import { t as Judge } from "./dial-CSQOl-yj.js";
5
+ import { t as CallContext } from "./call-context-gR8FhbF_.js";
5
6
  import { Extent, Quantity } from "@mark1russell7/quantity";
6
7
  import { Machine } from "@mark1russell7/algebra";
7
8
  //#region src/http-client/connection.d.ts
@@ -142,7 +143,13 @@ interface HttpClientSpec extends ClientSpec<HttpClientKnobs> {
142
143
  readonly operations?: Readonly<Record<string, Operation>> | undefined;
143
144
  }
144
145
  /** These options make a client. Without them, it uses the agent of Node, the real clock, and a dial with `OPTIONS *`. */
145
- type HttpClientOptions = ClientOptions<AgentFactory>;
146
+ interface HttpClientOptions extends ClientOptions<AgentFactory> {
147
+ /**
148
+ * With this call context, each request gets the headers of the active context of its caller, for
149
+ * example `traceparent`. A header of the call with the same name stays. `callContext` of the entry `/otel` gives one.
150
+ */
151
+ readonly callContext?: CallContext | undefined;
152
+ }
146
153
  /** An HTTP call is one request. A string body goes as UTF-8, with its `content-length`. */
147
154
  interface HttpCall {
148
155
  readonly method: string;
@@ -354,7 +354,14 @@ const httpClient = (name, spec, options = {}) => {
354
354
  if (value.outcome !== "ok") sent.abort(cause ?? new Error(value.error));
355
355
  });
356
356
  };
357
- const request = (call, sendOptions = {}) => {
357
+ const request = (given, sendOptions = {}) => {
358
+ const call = options.callContext === void 0 ? given : {
359
+ ...given,
360
+ headers: {
361
+ ...options.callContext.headers(),
362
+ ...given.headers
363
+ }
364
+ };
358
365
  const method = call.method.toUpperCase();
359
366
  const named = call.operation ?? method;
360
367
  return sendWithReissue({