connectrpc-async 0.3.0 → 0.3.1
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.
- checksums.yaml +4 -4
- data/README.md +736 -581
- data/lib/connectrpc/async/application.rb +14 -1
- data/lib/connectrpc/async/completion_join.rb +49 -217
- data/lib/connectrpc/async/connection.rb +180 -6
- data/lib/connectrpc/async/internal.rb +11 -5
- data/lib/connectrpc/async/server_session.rb +1 -1
- data/lib/connectrpc/async/stream_exchange.rb +23 -4
- data/lib/connectrpc/async/threaded_stream.rb +53 -13
- data/lib/connectrpc/async/transport.rb +1 -6
- data/lib/connectrpc/async/upstream_contract.rb +2 -246
- data/lib/connectrpc/async/version.rb +1 -1
- metadata +2 -2
data/README.md
CHANGED
|
@@ -44,33 +44,568 @@ and adoption gates.
|
|
|
44
44
|
gem "connectrpc-async", "~> 0.3.0"
|
|
45
45
|
```
|
|
46
46
|
|
|
47
|
+
Code that `protoc-gen-connectrpc-ruby` generates, including the demo code the
|
|
48
|
+
quick start below loads, uses the Google protobuf binding, so add it too:
|
|
49
|
+
|
|
50
|
+
```ruby
|
|
51
|
+
gem "google-protobuf", ">= 4.36.2", "< 5"
|
|
52
|
+
```
|
|
53
|
+
|
|
47
54
|
## Quick start
|
|
48
55
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
56
|
+
This example serves the demo schema's unary `Greet` RPC. It starts a host on an
|
|
57
|
+
ephemeral port, calls it over h2c and closes both ends:
|
|
58
|
+
|
|
59
|
+
```ruby
|
|
60
|
+
require "async"
|
|
61
|
+
require "connectrpc/async"
|
|
62
|
+
require "demo/v1/demo_connect" # Generated from examples/proto/demo/v1/demo.proto.
|
|
63
|
+
|
|
64
|
+
class Greeter
|
|
65
|
+
def greet(request, _context) = Demo::V1::GreetResponse.new(greeting: "Hello, #{request.name}!")
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
server = ConnectRPC::Server.new(services: [Demo::V1::DemoService::SERVICE],
|
|
69
|
+
handlers: Demo::V1::DemoService.handlers_for(Greeter.new))
|
|
70
|
+
|
|
71
|
+
Sync do
|
|
72
|
+
host = ConnectRPC::Async::Host.new(server: server).start # h2c on an ephemeral localhost port.
|
|
73
|
+
origin = "http://127.0.0.1:#{host.port}"
|
|
74
|
+
transport = ConnectRPC::Async::Transport.new(origin: origin)
|
|
75
|
+
client = Demo::V1::DemoService::Client.new(client: ConnectRPC::Client.new(base_url: origin, transport: transport))
|
|
76
|
+
puts client.greet(Demo::V1::GreetRequest.new(name: "Ada")).message.greeting # Hello, Ada!
|
|
77
|
+
ensure
|
|
78
|
+
transport&.close
|
|
79
|
+
host&.close
|
|
80
|
+
end
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
It uses the repository's [demo schema](../../examples/proto/demo/v1/demo.proto),
|
|
84
|
+
whose generated Ruby lives in `examples/gen`. From a repository checkout with
|
|
85
|
+
the gems installed, save it as `quickstart.rb` and run
|
|
86
|
+
`ruby -I examples/gen quickstart.rb`. With your own schema, generate code as
|
|
87
|
+
the [unary guide](../../docs/unary.md#generate-services-from-protobuf)
|
|
88
|
+
describes. The application owns the Async reactor that `Sync` starts here; see
|
|
89
|
+
[Reactor ownership](#reactor-ownership).
|
|
90
|
+
|
|
91
|
+
In this repository, `mise run async:example` runs the generated localhost
|
|
92
|
+
example. The [runnable examples](../../examples/README.md) include Async
|
|
93
|
+
servers and HTTP/1.1 and HTTP/2 clients, with mutual TLS.
|
|
94
|
+
|
|
95
|
+
## Host
|
|
96
|
+
|
|
97
|
+
`Host.new(server:, host: "127.0.0.1", port: 0, tls: nil, tls_provider: nil,
|
|
98
|
+
max_connections: 1024, max_requests: 128, max_concurrent_streams: 100,
|
|
99
|
+
request_body_timeout: 60, response_body_timeout: 60,
|
|
100
|
+
frame_write_timeout: 60, handshake_timeout: 10, idle_timeout: 60,
|
|
101
|
+
refresh_interval: 60, refresh_jitter: 0.1, refresh_timeout: 10,
|
|
102
|
+
on_tls_error: nil, keepalive: ServerKeepalive.new, fallback: nil,
|
|
103
|
+
stream_receive_window: 65_536, connection_receive_window: 16_777_216,
|
|
104
|
+
dynamic_receive_windows: true, max_receive_window: 1_048_576)` returns a host.
|
|
105
|
+
`fallback:`, `max_concurrent_streams:`, `request_body_timeout:`,
|
|
106
|
+
`response_body_timeout:`, `frame_write_timeout:`, `stream_receive_window:`,
|
|
107
|
+
`connection_receive_window:`, `dynamic_receive_windows:` and
|
|
108
|
+
`max_receive_window:` are available since 0.3.0. The receive windows size
|
|
109
|
+
request uploads; see [Flow-control windows](#flow-control-windows).
|
|
110
|
+
|
|
111
|
+
- `start` binds/listens before returning self; `port` and `addresses` expose the
|
|
112
|
+
actual binding. Since 0.3.0, every address `host` resolves to listens on one
|
|
113
|
+
port. With `port: 0` the kernel picks it for the first address; if a later
|
|
114
|
+
address already has that port in use, the Host closes what it bound and
|
|
115
|
+
retries the whole bind up to 5 times before raising. Listeners are
|
|
116
|
+
close-on-exec, so exec'd child processes do not keep them open.
|
|
117
|
+
- States are new/running/closing/closed; hosts cannot restart.
|
|
118
|
+
- Connection admission happens before TLS/preface; see
|
|
119
|
+
[Connection capacity](#connection-capacity). Request admission is
|
|
120
|
+
described in [Stream admission](#stream-admission).
|
|
121
|
+
- Setup has one combined cooperative timeout.
|
|
122
|
+
- `idle_timeout` counts from when a connection's last stream and handler
|
|
123
|
+
finished, or from its start, and then drains the connection gracefully; see
|
|
124
|
+
[Server keepalive](#server-keepalive). PINGs do not extend it. Nil disables it.
|
|
125
|
+
The 60-second default frees the connection slots that idle clients hold, in
|
|
126
|
+
the range of nginx's `keepalive_timeout` (75 seconds). TLS session resumption
|
|
127
|
+
is off, so an idle gRPC client reconnects with a full TLS handshake after 60
|
|
128
|
+
seconds. grpc-go's `MaxConnectionIdle` defaults to infinity; for long-lived
|
|
129
|
+
gRPC clients, raise `idle_timeout` or set it to nil and rely on
|
|
130
|
+
[server keepalive](#server-keepalive) PINGs to find dead peers.
|
|
131
|
+
|
|
132
|
+
The Host serves HTTP/2 only. There is no HTTP/1 listener or automatic replay.
|
|
133
|
+
For TLS options, see [TLS and client authentication](#tls-and-client-authentication).
|
|
134
|
+
|
|
135
|
+
[Host behavior](#host-behavior) describes the Host's connection and stream
|
|
136
|
+
limits, accept errors, startup failures and keepalive.
|
|
137
|
+
|
|
138
|
+
### Fallback application
|
|
139
|
+
|
|
140
|
+
Since 0.3.0, the Host accepts a fallback application.
|
|
141
|
+
|
|
142
|
+
`fallback:` takes a native Protocol::HTTP callable, `call(request)` returning a
|
|
143
|
+
`Protocol::HTTP::Response`, like [Application](#application)'s fallback. It is
|
|
144
|
+
not a Rack app. Core keeps whole registered service prefixes, including unknown
|
|
145
|
+
methods under them, so RPC traffic never reaches the fallback; every other
|
|
146
|
+
request goes to it with its method, path and query intact. Without `fallback:`,
|
|
147
|
+
unrelated paths get a bare 404. A non-callable fallback raises `ArgumentError`.
|
|
148
|
+
|
|
149
|
+
Fallback requests share the Host's [stream admission](#stream-admission),
|
|
150
|
+
including the request body bound, and connection lifetime. An exception from the
|
|
151
|
+
fallback fails only its own stream. The Host owns no tunnels or socket handoff,
|
|
152
|
+
so no `CONNECT` request reaches the fallback. An extended CONNECT (`:protocol`)
|
|
153
|
+
request gets a bare 501. A plain CONNECT has no `:path`, so the Host resets its
|
|
154
|
+
stream, with or without a fallback. A fallback response with status 101 or a
|
|
155
|
+
`protocol` is closed and replaced by 501.
|
|
156
|
+
|
|
157
|
+
The fallback inherits the Host's HTTP/2-only listener, so it serves only
|
|
158
|
+
HTTP/2 clients: h2c with prior knowledge, or TLS with ALPN `h2`. For example,
|
|
159
|
+
one Host can serve RPCs and Prometheus metrics:
|
|
160
|
+
|
|
161
|
+
```ruby
|
|
162
|
+
require "prometheus/client/formats/text"
|
|
163
|
+
|
|
164
|
+
metrics_app = lambda do |request|
|
|
165
|
+
next Protocol::HTTP::Response[404, {}, nil] unless request.path == "/metrics"
|
|
166
|
+
|
|
167
|
+
Protocol::HTTP::Response[200, { "content-type" => Prometheus::Client::Formats::Text::CONTENT_TYPE },
|
|
168
|
+
[Prometheus::Client::Formats::Text.marshal(Prometheus::Client.registry)]]
|
|
169
|
+
end
|
|
170
|
+
host = ConnectRPC::Async::Host.new(server: server, tls: tls, fallback: metrics_app).start
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
Prometheus scrapes a TLS Host over h2. A cleartext h2c Host is not reachable by
|
|
174
|
+
HTTP/1.1 clients, so those still need a separate listener or the
|
|
175
|
+
[Falcon package](../connectrpc-falcon/README.md), which serves HTTP/1.1 and
|
|
176
|
+
HTTP/2.
|
|
177
|
+
|
|
178
|
+
### Supervise with `wait`
|
|
179
|
+
|
|
180
|
+
`Host#wait` supports application supervision:
|
|
181
|
+
|
|
182
|
+
```ruby
|
|
183
|
+
Async do
|
|
184
|
+
host = ConnectRPC::Async::Host.new(server: server).start
|
|
185
|
+
begin
|
|
186
|
+
host.wait # Ordinary listener stop returns nil; terminal failure raises.
|
|
187
|
+
ensure
|
|
188
|
+
host.close # Await session drain separately from ordinary listener stop.
|
|
189
|
+
end
|
|
190
|
+
end.wait
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
`wait` returns nil once the listeners stop normally, and raises the original
|
|
194
|
+
exception after a terminal listener failure. Like other lifecycle operations,
|
|
195
|
+
it requires the owning reactor and thread.
|
|
196
|
+
[Waiting for the Host](#waiting-for-the-host) describes its full results.
|
|
197
|
+
|
|
198
|
+
## Transport
|
|
199
|
+
|
|
200
|
+
`Transport.new(origin:, ca_file: nil, certificate_chain: nil, private_key: nil,
|
|
201
|
+
connection_limit: 1, max_requests: 128, connect_timeout: 10,
|
|
202
|
+
connection_policy: ConnectionPolicy.new, connection_observer: nil,
|
|
203
|
+
stream_receive_window: 4_194_304, connection_receive_window: 16_777_216,
|
|
204
|
+
dynamic_receive_windows: true, max_receive_window: 16_777_216,
|
|
205
|
+
proxy: :environment)` implements core's transport seam for HTTP/2. Since 0.3.0,
|
|
206
|
+
the receive windows size response downloads; see
|
|
207
|
+
[Flow-control windows](#flow-control-windows), and connections go through an
|
|
208
|
+
`http://` proxy chosen by `proxy:`; see [Proxies](#proxies).
|
|
209
|
+
|
|
210
|
+
Without generated code, pass core objects to the client directly. The example
|
|
211
|
+
assumes existing core `server`, `binding`, `method` and `message` objects, as
|
|
212
|
+
shown in the repository unary examples.
|
|
213
|
+
|
|
214
|
+
```ruby
|
|
215
|
+
require "async"
|
|
216
|
+
require "connectrpc/async"
|
|
217
|
+
|
|
218
|
+
Async do
|
|
219
|
+
host = ConnectRPC::Async::Host.new(server: server).start
|
|
220
|
+
origin = "http://127.0.0.1:#{host.port}"
|
|
221
|
+
transport = ConnectRPC::Async::Transport.new(origin: origin)
|
|
222
|
+
client = ConnectRPC::Client.new(base_url: origin, binding: binding, transport: transport)
|
|
223
|
+
begin
|
|
224
|
+
client.call(method, message)
|
|
225
|
+
ensure
|
|
226
|
+
transport.close
|
|
227
|
+
host.close
|
|
228
|
+
end
|
|
229
|
+
end.wait
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
- Origins contain only scheme/host/port; a bare trailing `/` is accepted.
|
|
233
|
+
Request paths, including core's base prefix, remain intact.
|
|
234
|
+
- One connection multiplexes requests. Admission fails with unavailable:
|
|
235
|
+
`HTTP/2 transport admission is full` at `max_requests` or
|
|
236
|
+
`max_pending_bytes`, and `HTTP/2 transport admission is closed` once closing.
|
|
237
|
+
Acquisition waits honor finite RPC deadlines.
|
|
238
|
+
- Nil RPC deadlines remain unbounded, while each connection attempt has its own
|
|
239
|
+
`connect_timeout`.
|
|
240
|
+
- An enclosing Async `with_timeout` around a call or stream operation ends it
|
|
241
|
+
with that same `Async::TimeoutError`, not a ConnectRPC error. The stream is
|
|
242
|
+
reset and its admission released as for any interrupted call. An already
|
|
243
|
+
expired RPC deadline or cancellation still wins.
|
|
244
|
+
- Connection and transport failures raise unavailable
|
|
245
|
+
`HTTP/2 transport failed: <reason>`, keeping the original exception as
|
|
246
|
+
`cause`. The reason is one of `connection refused`, `name resolution
|
|
247
|
+
failed`, `host unreachable`, `timed out`, `TLS verification failed`,
|
|
248
|
+
`ALPN negotiation failed`, `TLS error`, `connection closed` or `HTTP/2
|
|
249
|
+
protocol error`; an unclassified failure has no reason. Messages never
|
|
250
|
+
include the origin, addresses or certificate details. `HTTP1Transport` uses
|
|
251
|
+
the same reasons with `HTTP/1`, plus `malformed response`. Since 0.3.0, a
|
|
252
|
+
proxy hop adds the fixed [proxy](#proxies) reasons.
|
|
253
|
+
- No redirects or HTTP/1 fallback.
|
|
254
|
+
- The transport carries opaque encoded bytes; core owns compression and
|
|
255
|
+
negotiation.
|
|
256
|
+
|
|
257
|
+
[Client connection management](#client-connection-management) describes
|
|
258
|
+
reconnection, backoff, GOAWAY replacement, admission, rerouting of unsent calls
|
|
259
|
+
and the single resend of a refused Connect unary call. For TLS options, see
|
|
260
|
+
[TLS and client authentication](#tls-and-client-authentication).
|
|
261
|
+
|
|
262
|
+
### Safe unary GET
|
|
263
|
+
|
|
264
|
+
Safe unary GET uses core `Client.new(use_get: true)` and declared
|
|
265
|
+
`:no_side_effects` methods. Native HTTP/2 requests carry HEADERS with END_STREAM
|
|
266
|
+
and a nil body; core owns query encoding, parsing and independent URL/payload
|
|
267
|
+
limits. The transport never falls back to POST; a refused GET is resent only
|
|
268
|
+
under the refused-stream rule in
|
|
269
|
+
[Client connection management](#client-connection-management).
|
|
270
|
+
|
|
271
|
+
## Ordinary threads
|
|
272
|
+
|
|
273
|
+
`ThreadedTransport` lets threaded programs such as Puma, Sidekiq or plain
|
|
274
|
+
threads share one client without an application reactor. It supports Connect
|
|
275
|
+
unary (POST and safe GET) and server streaming, and native gRPC unary and server
|
|
276
|
+
streaming. `streaming_capabilities` is `[:server_stream]` and
|
|
277
|
+
`grpc_capabilities` is `[:unary, :server_stream]`, so core rejects client and
|
|
278
|
+
bidi streaming before any I/O. Client and bidi streaming from ordinary threads
|
|
279
|
+
are tracked in [issue #29](https://github.com/jimeh/connectrpc-ruby/issues/29).
|
|
280
|
+
|
|
281
|
+
```ruby
|
|
282
|
+
require "connectrpc/async"
|
|
283
|
+
|
|
284
|
+
# Boot, for example in an initializer. No thread or socket starts here.
|
|
285
|
+
RPC = ConnectRPC::Async::ThreadedTransport.new(origin: "https://rpc.internal:8443")
|
|
286
|
+
client = ConnectRPC::Client.new(base_url: "https://rpc.internal:8443", binding: binding, transport: RPC)
|
|
287
|
+
|
|
288
|
+
client.call(method, message, timeout: 2) # Any thread.
|
|
289
|
+
client.server_stream(watch, message) { |reader| reader.each { ... } } # The block runs on this thread.
|
|
290
|
+
RPC.close(grace: 5) # Shutdown, for example in on_worker_shutdown.
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
It takes the same options as `Transport`, and they behave the same, including
|
|
294
|
+
the [connection policy](#client-connection-management). The constructor
|
|
295
|
+
validates them and compiles the TLS snapshot on the calling thread, so
|
|
296
|
+
configuration errors raise at boot. Since 0.3.0, the constructor also takes the
|
|
297
|
+
[proxy](#proxies) environment snapshot on the calling thread; every owner
|
|
298
|
+
thread, including one that replaces a stopped owner or starts after fork,
|
|
299
|
+
reuses it and never reads the environment itself. `call`, `open_stream`, `open_grpc_stream`,
|
|
300
|
+
`close(grace: 5)`, `connection_state` and `inspect` work from any thread,
|
|
301
|
+
including an Async task on a reactor thread such as a Falcon handler's, where
|
|
302
|
+
each wait suspends only that task. For calls inside a reactor, `Transport` or
|
|
303
|
+
`PerCallTransport` avoid the hop to the owner thread.
|
|
304
|
+
|
|
305
|
+
[ThreadedTransport behavior](#threadedtransport-behavior) describes its owner
|
|
306
|
+
thread, admission, interrupts, streams and closing.
|
|
307
|
+
|
|
308
|
+
## One-off calls
|
|
309
|
+
|
|
310
|
+
Since 0.3.0, `PerCallTransport` opens one HTTP/2 connection per call, runs the
|
|
311
|
+
exchange and closes the connection before the call returns. It suits a process
|
|
312
|
+
that calls many origins occasionally, such as a Rails action that makes one
|
|
313
|
+
gRPC call to one of hundreds of devices, where pooled connections, keepalive
|
|
314
|
+
and an owner thread per origin cost more than a connection setup per call. For
|
|
315
|
+
repeated calls to a few origins, use `ThreadedTransport` or `Transport`, which
|
|
316
|
+
reuse their connections.
|
|
317
|
+
|
|
318
|
+
```ruby
|
|
319
|
+
require "connectrpc/async"
|
|
320
|
+
|
|
321
|
+
# Boot, for example in an initializer. No thread or socket starts here.
|
|
322
|
+
DEVICES = ConnectRPC::Async::PerCallTransport.new(ca_file: "devices-ca.pem")
|
|
323
|
+
|
|
324
|
+
client = ConnectRPC::Client.new(base_url: "https://device-17.internal:8443", binding: binding,
|
|
325
|
+
transport: DEVICES, protocol: :grpc)
|
|
326
|
+
client.call(method, message, timeout: 2) # Any thread, or inside an Async task.
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
`PerCallTransport.new(ca_file: nil, certificate_chain: nil, private_key: nil,
|
|
330
|
+
connect_timeout: 10, proxy: :environment)` validates its options, compiles one
|
|
331
|
+
TLS snapshot at construction, with the system roots plus the optional
|
|
332
|
+
`ca_file`, takes its [proxy](#proxies) snapshot and holds only frozen
|
|
333
|
+
configuration. It has no `origin:` and no `close`: every call dials the scheme,
|
|
334
|
+
host and port of its request URL, or tunnels to them through a proxy, so one
|
|
335
|
+
instance serves every origin from any number of threads. `http` URLs use h2c
|
|
336
|
+
with prior knowledge and `https` URLs use TLS with ALPN `h2`. The request URL,
|
|
337
|
+
including core's path
|
|
338
|
+
prefix and a GET query, reaches the server unchanged. A URL that is not HTTP(S),
|
|
339
|
+
has no host or carries userinfo, and TLS options with an `http` URL, raise
|
|
340
|
+
`ArgumentError` before any socket opens; the transport never falls back to
|
|
341
|
+
plaintext.
|
|
342
|
+
|
|
343
|
+
It supports Connect unary (POST and safe GET) and server streaming, and native
|
|
344
|
+
gRPC unary and server streaming: `streaming_capabilities` is `[:server_stream]`
|
|
345
|
+
and `grpc_capabilities` is `[:unary, :server_stream]`, so core rejects client
|
|
346
|
+
and bidi streaming before any I/O.
|
|
347
|
+
|
|
348
|
+
[PerCallTransport behavior](#percalltransport-behavior) describes how each
|
|
349
|
+
call runs, resends, closes its connection and handles interrupts.
|
|
350
|
+
|
|
351
|
+
## Explicit HTTP/1.1 client
|
|
352
|
+
|
|
353
|
+
```ruby
|
|
354
|
+
Async do
|
|
355
|
+
transport = ConnectRPC::Async::HTTP1Transport.new(origin: "https://rpc.example.com")
|
|
356
|
+
client = ConnectRPC::Client.new(base_url: "https://rpc.example.com", binding: binding,
|
|
357
|
+
transport: transport, use_get: true)
|
|
358
|
+
begin
|
|
359
|
+
client.call(method, message)
|
|
360
|
+
# Existing generated clients and core server_stream/client_stream use it too.
|
|
361
|
+
ensure
|
|
362
|
+
transport.close
|
|
363
|
+
end
|
|
364
|
+
end.wait
|
|
365
|
+
```
|
|
366
|
+
|
|
367
|
+
`HTTP1Transport.new(origin:, ca_file: nil, certificate_chain: nil, private_key:
|
|
368
|
+
nil, connection_limit: 4, max_requests: 128, connect_timeout: 10, proxy:
|
|
369
|
+
:environment)` is a Connect client over HTTP/1.1 that you select explicitly.
|
|
370
|
+
Since 0.3.0 it reaches its origin through an `http://` proxy chosen by
|
|
371
|
+
`proxy:`; see [Proxies](#proxies). Pass it as the `transport:` option of an
|
|
372
|
+
existing core or generated client, inside an Async reactor that your
|
|
373
|
+
application owns. Through core, it supports safe unary GET, both codecs
|
|
374
|
+
(protobuf and ProtoJSON) and identity or gzip encoding. Through the existing
|
|
375
|
+
streaming SPI, it supports server streaming and client streaming. It has no
|
|
376
|
+
gRPC or bidi capability. The standalone Async Host remains HTTP/2 only, and
|
|
377
|
+
Falcon owns Ruby HTTP/1.1 hosting. For ordinary threads, see
|
|
378
|
+
[`ThreadedTransport`](#ordinary-threads).
|
|
379
|
+
|
|
380
|
+
[HTTP1Transport behavior](#http1transport-behavior) describes its leases,
|
|
381
|
+
capacity, deadlines, reuse, TLS and upload failures.
|
|
382
|
+
|
|
383
|
+
## TLS and client authentication
|
|
384
|
+
|
|
385
|
+
Applications load their own files. Host TLS is a complete hash:
|
|
386
|
+
|
|
387
|
+
```ruby
|
|
388
|
+
tls = {
|
|
389
|
+
certificate_chain: [File.read("leaf.pem"), File.read("intermediate.pem")],
|
|
390
|
+
private_key: File.read("key.pem"),
|
|
391
|
+
client_ca: nil # Or a nonempty array of explicit trust-anchor PEM certificates.
|
|
392
|
+
}
|
|
393
|
+
```
|
|
394
|
+
|
|
395
|
+
Instead of a static `tls:` hash, a Host can take a `tls_provider:` that it
|
|
396
|
+
polls for renewed certificates; see
|
|
397
|
+
[Managed TLS providers](#managed-tls-providers).
|
|
398
|
+
|
|
399
|
+
### Certificates and verification
|
|
400
|
+
|
|
401
|
+
Each certificate element contains exactly one PEM certificate, and the chain
|
|
402
|
+
lists the leaf first. Keys are unencrypted PEM private keys. The library copies
|
|
403
|
+
and parses the inputs without password prompts. It checks key possession (the
|
|
404
|
+
key matches the leaf), leaf validity, and the signature between each pair of
|
|
405
|
+
adjacent certificates in the chain. A snapshot is the validated TLS state that
|
|
406
|
+
new connections use. Snapshots keep their parsed objects private, redact
|
|
407
|
+
them from `inspect` output and errors, and compile fresh TLS contexts before
|
|
408
|
+
they are published. Explicit intermediates, including an empty array, stop
|
|
409
|
+
OpenSSL from building the chain on its own (auto-chaining) through the
|
|
410
|
+
client-auth trust store.
|
|
411
|
+
|
|
412
|
+
Both the server and the client require TLS 1.2 or later, and check after the
|
|
413
|
+
handshake that ALPN selected `h2`. Clients always verify the peer certificate
|
|
414
|
+
and hostname, including for localhost, using the system roots plus the optional
|
|
415
|
+
`ca_file`. A client certificate chain and private key must be given together.
|
|
416
|
+
TLS options are invalid for h2c (HTTP/2 without TLS). An origin whose host is an
|
|
417
|
+
IP literal sends no server name (RFC 6066 section 3), and the certificate must
|
|
418
|
+
still match the address.
|
|
419
|
+
|
|
420
|
+
Client TLS inputs differ in kind: `ca_file` is a filesystem path to a PEM CA
|
|
421
|
+
bundle, `certificate_chain` is an array of PEM certificate strings, leaf first,
|
|
422
|
+
and `private_key` is a PEM string. An invalid input raises `ArgumentError`
|
|
423
|
+
naming the input, such as `Invalid TLS client configuration: ca_file`, without
|
|
424
|
+
its value or a cause.
|
|
425
|
+
|
|
426
|
+
### Client authentication
|
|
427
|
+
|
|
428
|
+
A nonempty `client_ca` requires verified client certificates using only those
|
|
429
|
+
anchors, with partial-chain trust enabled deliberately. A scoped intermediate
|
|
430
|
+
can be the boundary; sibling issuers under its root are not trusted. Nil means
|
|
431
|
+
server-only TLS and no client authentication. There is no optional-client mode.
|
|
432
|
+
|
|
433
|
+
`host.peer_certificate` returns a detached authenticated client leaf only within
|
|
434
|
+
that host's exact handler task; outside/child/other-host/plain/server-only TLS
|
|
435
|
+
returns nil. It does not expose or claim a verified chain and does not change
|
|
436
|
+
core Context. Applications own authorization based on that identity.
|
|
437
|
+
|
|
438
|
+
### Reload and drain
|
|
439
|
+
|
|
440
|
+
`host.reload_tls(certificate_chain:, private_key:, client_ca:)` replaces the
|
|
441
|
+
complete TLS snapshot that the same listener uses for newly accepted sockets.
|
|
442
|
+
Each snapshot has a generation number. The generation starts at 1 and
|
|
443
|
+
increments only after a candidate passes validation; an invalid candidate
|
|
444
|
+
leaves the last good snapshot in place. Existing connections keep their
|
|
445
|
+
earlier identity and authentication. Every generation has a fresh TLS context
|
|
446
|
+
and session ID, with OP_NO_TICKET and SESSION_CACHE_OFF set. TLS session reuse
|
|
447
|
+
is disabled; this does not claim that OpenSSL sends zero TLS 1.3 tickets. To
|
|
448
|
+
change a client's identity, replace its transport.
|
|
449
|
+
|
|
450
|
+
`host.drain_tls(grace: 5)` records the current generation and retires (takes out
|
|
451
|
+
of service) only connections accepted under older generations, including those
|
|
452
|
+
still in their TLS handshake. Old connections get the two-phase GOAWAY drain
|
|
453
|
+
with debug data `tls_rotation`. A drain already running on a connection keeps
|
|
454
|
+
its debug data and cutoff. GOAWAY is the HTTP/2 frame that tells a client to
|
|
455
|
+
stop opening streams on a connection. Each old connection sets its own stream
|
|
456
|
+
cutoff during the drain, as [Server keepalive](#server-keepalive) describes.
|
|
457
|
+
Streams opened before that cutoff are served, later ones are refused with
|
|
458
|
+
`REFUSED_STREAM`, and admitted streams finish. Pending handshakes abort
|
|
459
|
+
immediately. A persistent retirement floor, the oldest generation still allowed
|
|
460
|
+
to go live, prevents old pending sockets from becoming live. The listener and
|
|
461
|
+
the current and newer generations survive reloads and drains that run
|
|
462
|
+
concurrently. A close supersedes any drain. Renewing a certificate alone does
|
|
463
|
+
not instantly revoke existing peers. There are no file watchers, ACME, secret
|
|
464
|
+
services or authentication policy DSLs.
|
|
465
|
+
|
|
466
|
+
## Native streaming
|
|
467
|
+
|
|
468
|
+
The core [streaming guide](../../docs/streaming.md) documents all three Connect
|
|
469
|
+
stream kinds in scope (server, client and bidirectional streaming), typed
|
|
470
|
+
generated clients and handlers, early headers, per-message limits and bounded
|
|
471
|
+
ownership. Native HTTP/2 on Async and Falcon supports both codecs and identity
|
|
472
|
+
or gzip encoding, over h2c (HTTP/2 without TLS), TLS and mTLS. Over HTTP/1.1,
|
|
473
|
+
Falcon also serves Connect server and client streaming, with protobuf or
|
|
474
|
+
ProtoJSON and identity or gzip encoding, over TCP, TLS and mTLS. The standalone
|
|
475
|
+
Async Host and the original Async Transport remain HTTP/2 only. Use the
|
|
476
|
+
separate [`HTTP1Transport`](#explicit-http11-client) client for Connect unary
|
|
477
|
+
calls, server streaming and client streaming.
|
|
478
|
+
|
|
479
|
+
Over HTTP/2, when a server ends its response with END_STREAM while the request
|
|
480
|
+
body is still open and does not reset the stream, the client resets it with
|
|
481
|
+
`RST_STREAM(NO_ERROR)`, as grpc-go's client does. This applies to every HTTP/2
|
|
482
|
+
client stream, Connect and gRPC alike, and to unary uploads. The upload stops at
|
|
483
|
+
the next frame boundary, a later or blocked write raises `unavailable`, and the
|
|
484
|
+
response's messages and status stay readable. Core then reports the server's
|
|
485
|
+
error status. A client or bidi stream keeps a failed write's `unavailable` over
|
|
486
|
+
an OK status; a gRPC unary or server-streaming call, whose request core writes
|
|
487
|
+
itself, reports the response's outcome, so a server that answered OK before it
|
|
488
|
+
read the whole request still returns its reply, as with grpc-go and connect-go.
|
|
489
|
+
A request that `close_send` ended first finishes with END_STREAM and no reset.
|
|
490
|
+
HTTP/1.1 is unchanged.
|
|
491
|
+
|
|
492
|
+
The streaming guide's [Falcon HTTP/1.1
|
|
493
|
+
server](../../docs/streaming.md#falcon-http11-server) section describes how
|
|
494
|
+
Falcon reads up to 256 KiB of unread HTTP/1.1 input before it writes its
|
|
495
|
+
response, or before the first output chunk when the headers were published
|
|
496
|
+
early, with the exceptions to that limit. It also describes the cooperative 500
|
|
497
|
+
ms budget for the final close. The client applies a provisional HTTP tail
|
|
498
|
+
policy: after the terminal envelope that ends the stream, the response must
|
|
499
|
+
reach HTTP EOF and the transport must complete within one absolute second. The
|
|
500
|
+
policy applies even with a nil RPC deadline, and it can reject an otherwise
|
|
501
|
+
valid EOF that arrives late or a slow intermediary. See the [support
|
|
502
|
+
contract](../../docs/support.md#native-client-completion).
|
|
503
|
+
|
|
504
|
+
Use `async:conformance` for the exact official native client and server
|
|
505
|
+
inventories, and `async:interop:streaming` for the independent pinned Go
|
|
506
|
+
streaming matrix. Both belong to `async:verify`. The original unary
|
|
507
|
+
interoperability checks remain separate.
|
|
508
|
+
|
|
509
|
+
## Native gRPC
|
|
510
|
+
|
|
511
|
+
Native HTTP/2 supports unary, server streaming, client streaming and bidi gRPC
|
|
512
|
+
with protobuf, identity/gzip, h2c, verified TLS and mTLS. Configure the core
|
|
513
|
+
Client with `protocol: :grpc` and the Server with `:grpc` or `:auto`. Generated
|
|
514
|
+
clients and handlers reuse the existing declarations. Portable HTTP/1 execution
|
|
515
|
+
retains its early rejection guard. See the [gRPC guide](../../docs/grpc.md) for
|
|
516
|
+
status codecs, actual final HEADERS, independent status bounds and native field
|
|
517
|
+
retention limits. Connect's one-second terminal tail policy remains Connect-only.
|
|
518
|
+
|
|
519
|
+
Use `async:conformance:grpc` for exact official inventories and
|
|
520
|
+
`async:interop:grpc` for generated official grpc-go peer checks. Both belong
|
|
521
|
+
to the owning verify task. `async:interop:grpc` first reproduces the official Go
|
|
522
|
+
and Ruby peer outputs through the Async bundle, the same check root
|
|
523
|
+
`grpc:generation:check` runs through the core bundle. `grpc:status:check`
|
|
524
|
+
reproduces private Any/Status descriptors. `async:interop:grpc` also checks
|
|
525
|
+
that the `Transport` and `ThreadedTransport` clients decode the peer's rich
|
|
526
|
+
status, typed details and metadata from a unary error sent after headers and
|
|
527
|
+
from trailers-only unary and server-stream errors. A raw HTTP/2 client first
|
|
528
|
+
checks that grpc-go sends each trailers-only error as one HEADERS frame with
|
|
529
|
+
END_HEADERS and END_STREAM.
|
|
530
|
+
|
|
531
|
+
## gRPC-Web
|
|
532
|
+
|
|
533
|
+
The native H2 server supports explicitly enabled binary/text unary and
|
|
534
|
+
server-stream gRPC-Web. Browser incremental delivery uses text. See the
|
|
535
|
+
[Web guide](../../docs/grpc-web.md) for protocol, CORS, bounds and completion
|
|
536
|
+
rules.
|
|
537
|
+
|
|
538
|
+
## Explicit unary cancellation
|
|
539
|
+
|
|
540
|
+
Pass `cancellation: source.token` to core or generated client calls, where
|
|
541
|
+
`source = ConnectRPC::CancellationSource.new`. A source cannot be reset and can
|
|
542
|
+
be shared between calls. Only `source.cancel` starts cancellation.
|
|
543
|
+
`timeout: nil` without `deadline:` sets no RPC deadline and sends no wire
|
|
544
|
+
timeout. Context offers cooperative checks: `cancelled?`,
|
|
545
|
+
`cancellation_reason` and `check!`. See the
|
|
546
|
+
[unary guide](../../docs/unary.md#cancellation) for listener, arbitration and
|
|
547
|
+
registration lifetime rules.
|
|
548
|
+
|
|
549
|
+
The Async transport accepts cancellation from another thread through a
|
|
550
|
+
Promise. Only the reactor that owns the transport stops the private SDK tasks
|
|
551
|
+
and cleans up the stream. Cancellation, an expired deadline or a stopped
|
|
552
|
+
caller task resets the call's stream with `RST_STREAM(CANCEL)`, including
|
|
553
|
+
while its upload waits for flow-control credit. Healthy calls multiplexed on
|
|
554
|
+
the same connection keep running. A stuck frame still gets the one
|
|
555
|
+
[cleanup allowance](#cleanup-allowance), and the fallback that fails the whole
|
|
556
|
+
connection, raw socket first. On a native HTTP/2 host, Context observes only
|
|
557
|
+
an actual RST_STREAM(CANCEL) from the peer, and observes it before input
|
|
558
|
+
teardown. Other resets, a normal half-close, connection loss and host shutdown
|
|
559
|
+
do not create an explicit cancellation. When processing completes, the source
|
|
560
|
+
is detached, whether or not the response has been delivered.
|
|
561
|
+
|
|
562
|
+
## Interceptors
|
|
563
|
+
|
|
564
|
+
Server interceptors configured on the core Server cover every RPC the native
|
|
565
|
+
host serves: [unary](../../docs/unary.md#interceptors) calls through
|
|
566
|
+
`server_unary`, and server, client and bidi
|
|
567
|
+
[streams](../../docs/streaming.md#interceptors) through `server_stream`, on
|
|
568
|
+
Connect and native gRPC, plus unary and server-stream gRPC-Web. They run after
|
|
569
|
+
core decodes a unary or server-streaming request, around the handler, with the
|
|
570
|
+
first interceptor listed outermost. They run in the per-request processing
|
|
571
|
+
task, so `host.peer_certificate` returns the authenticated client leaf inside an
|
|
572
|
+
interceptor, the same as in the handler. Stream wrapper methods see it only when
|
|
573
|
+
called from that task; a child task gets nil, so read the certificate in the
|
|
574
|
+
interceptor before starting child work. A continuation called from a child task
|
|
575
|
+
fails with `InterceptorStateError`.
|
|
576
|
+
|
|
577
|
+
Client interceptors run on the calling task or thread for `Transport`,
|
|
578
|
+
`HTTP1Transport` and `ThreadedTransport`, before core encodes the request.
|
|
579
|
+
|
|
580
|
+
## RPC observation
|
|
52
581
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
582
|
+
Configure `instrumentation:` on the core Client/Server to enable the fixed
|
|
583
|
+
neutral per-call lifecycle or the optional
|
|
584
|
+
[OpenTelemetry adapter](../connectrpc-otel/README.md). Native hosts create
|
|
585
|
+
explicit handles before a request's handler starts, activate the actual handler
|
|
586
|
+
tasks, and finish after full-write/reset/cleanup evidence. An HTTP/2 stream
|
|
587
|
+
refused while its HEADERS are read, because host admission is full, gets its
|
|
588
|
+
handle in a separate task after the refusal. That handle is never activated and
|
|
589
|
+
finishes once the reset is written, or as not delivered if the connection ends
|
|
590
|
+
first. Shared H2 client connection attempts run outside every RPC lifecycle, so
|
|
591
|
+
tracing never parents connection setup to the call that triggered it. Use the
|
|
592
|
+
transport's `connection_observer` for connection events. Since 0.3.0, the
|
|
593
|
+
Application passes the request authority (HTTP/1 `Host` or HTTP/2
|
|
594
|
+
`:authority`) to core as the reserved `host` field, so the server call records
|
|
595
|
+
the address the client used; handler metadata never contains it. Like the
|
|
596
|
+
`Host` field a Rack server passes, it counts toward the gRPC and gRPC-Web
|
|
597
|
+
request field limits, as `:authority` counts toward an HTTP/2 header list.
|
|
56
598
|
|
|
57
|
-
|
|
58
|
-
host = ConnectRPC::Async::Host.new(server: server).start
|
|
59
|
-
origin = "http://127.0.0.1:#{host.port}"
|
|
60
|
-
transport = ConnectRPC::Async::Transport.new(origin: origin)
|
|
61
|
-
client = ConnectRPC::Client.new(base_url: origin, binding: binding, transport: transport)
|
|
62
|
-
begin
|
|
63
|
-
client.call(method, message)
|
|
64
|
-
ensure
|
|
65
|
-
transport.close
|
|
66
|
-
host.close
|
|
67
|
-
end
|
|
68
|
-
end.wait
|
|
69
|
-
```
|
|
599
|
+
## Static signatures
|
|
70
600
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
601
|
+
This package owns `sig/` and its discovery manifest. Add `library "connectrpc"`
|
|
602
|
+
and `library "connectrpc-async"` to a strict Steep target with this gem
|
|
603
|
+
installed. The manifest lists only standard libraries, so name each connectrpc
|
|
604
|
+
library explicitly; this also works with `rbs collection`. See the
|
|
605
|
+
[RBS guide](../../docs/rbs.md) for supported APIs, extension contracts, partial
|
|
606
|
+
records, runtime validation and framework-signature limits. `mise run rbs:check`
|
|
607
|
+
checks application callers for this package; strict core source checking is a
|
|
608
|
+
separate target from backend implementation checking.
|
|
74
609
|
|
|
75
610
|
## Reactor ownership
|
|
76
611
|
|
|
@@ -124,45 +659,11 @@ waiting for its reply reopened interrupts for every task, so the signal could
|
|
|
124
659
|
land in another task's code instead of at Async's loop
|
|
125
660
|
([#201](https://github.com/jimeh/connectrpc-ruby/issues/201)).
|
|
126
661
|
|
|
127
|
-
## Host
|
|
128
|
-
|
|
129
|
-
`Host.new(server:, host: "127.0.0.1", port: 0, tls: nil, tls_provider: nil,
|
|
130
|
-
max_connections: 1024, max_requests: 128, max_concurrent_streams: 100,
|
|
131
|
-
request_body_timeout: 60, response_body_timeout: 60,
|
|
132
|
-
frame_write_timeout: 60, handshake_timeout: 10, idle_timeout: 60,
|
|
133
|
-
refresh_interval: 60, refresh_jitter: 0.1, refresh_timeout: 10,
|
|
134
|
-
on_tls_error: nil, keepalive: ServerKeepalive.new, fallback: nil,
|
|
135
|
-
stream_receive_window: 65_536, connection_receive_window: 16_777_216,
|
|
136
|
-
dynamic_receive_windows: true, max_receive_window: 1_048_576)` returns a host.
|
|
137
|
-
`fallback:`, `max_concurrent_streams:`, `request_body_timeout:`,
|
|
138
|
-
`response_body_timeout:`, `frame_write_timeout:`, `stream_receive_window:`,
|
|
139
|
-
`connection_receive_window:`, `dynamic_receive_windows:` and
|
|
140
|
-
`max_receive_window:` are available since 0.3.0. The receive windows size
|
|
141
|
-
request uploads; see [Flow-control windows](#flow-control-windows).
|
|
142
|
-
|
|
143
|
-
- `start` binds/listens before returning self; `port` and `addresses` expose the
|
|
144
|
-
actual binding. Since 0.3.0, every address `host` resolves to listens on one
|
|
145
|
-
port. With `port: 0` the kernel picks it for the first address; if a later
|
|
146
|
-
address already has that port in use, the Host closes what it bound and
|
|
147
|
-
retries the whole bind up to 5 times before raising. Listeners are
|
|
148
|
-
close-on-exec, so exec'd child processes do not keep them open.
|
|
149
|
-
- States are new/running/closing/closed; hosts cannot restart.
|
|
150
|
-
- Connection admission happens before TLS/preface; see
|
|
151
|
-
[Connection capacity](#connection-capacity). Request admission is
|
|
152
|
-
described in [Stream admission](#stream-admission).
|
|
153
|
-
- Setup has one combined cooperative timeout.
|
|
154
|
-
- `idle_timeout` counts from when a connection's last stream and handler
|
|
155
|
-
finished, or from its start, and then drains the connection gracefully; see
|
|
156
|
-
[Server keepalive](#server-keepalive). PINGs do not extend it. Nil disables it.
|
|
157
|
-
The 60-second default frees the connection slots that idle clients hold, in
|
|
158
|
-
the range of nginx's `keepalive_timeout` (75 seconds). TLS session resumption
|
|
159
|
-
is off, so an idle gRPC client reconnects with a full TLS handshake after 60
|
|
160
|
-
seconds. grpc-go's `MaxConnectionIdle` defaults to infinity; for long-lived
|
|
161
|
-
gRPC clients, raise `idle_timeout` or set it to nil and rely on
|
|
162
|
-
[server keepalive](#server-keepalive) PINGs to find dead peers.
|
|
662
|
+
## Host behavior
|
|
163
663
|
|
|
164
|
-
The Host
|
|
165
|
-
|
|
664
|
+
The Host's connection and stream limits, accept and startup failure handling,
|
|
665
|
+
and server keepalive work with their defaults, so the common cases above do
|
|
666
|
+
not need this section.
|
|
166
667
|
|
|
167
668
|
### Connection capacity
|
|
168
669
|
|
|
@@ -301,79 +802,6 @@ These limits do not bound every way to hold a slot:
|
|
|
301
802
|
`send_timeout`. A call deadline, `max_connection_age` with
|
|
302
803
|
`max_connection_age_grace`, or `close` ends it.
|
|
303
804
|
|
|
304
|
-
### Fallback application
|
|
305
|
-
|
|
306
|
-
Since 0.3.0, the Host accepts a fallback application.
|
|
307
|
-
|
|
308
|
-
`fallback:` takes a native Protocol::HTTP callable, `call(request)` returning a
|
|
309
|
-
`Protocol::HTTP::Response`, like [Application](#application)'s fallback. It is
|
|
310
|
-
not a Rack app. Core keeps whole registered service prefixes, including unknown
|
|
311
|
-
methods under them, so RPC traffic never reaches the fallback; every other
|
|
312
|
-
request goes to it with its method, path and query intact. Without `fallback:`,
|
|
313
|
-
unrelated paths get a bare 404. A non-callable fallback raises `ArgumentError`.
|
|
314
|
-
|
|
315
|
-
Fallback requests share the Host's [stream admission](#stream-admission),
|
|
316
|
-
including the request body bound, and connection lifetime. An exception from the
|
|
317
|
-
fallback fails only its own stream. The Host owns no tunnels or socket handoff,
|
|
318
|
-
so no `CONNECT` request reaches the fallback. An extended CONNECT (`:protocol`)
|
|
319
|
-
request gets a bare 501. A plain CONNECT has no `:path`, so the Host resets its
|
|
320
|
-
stream, with or without a fallback. A fallback response with status 101 or a
|
|
321
|
-
`protocol` is closed and replaced by 501.
|
|
322
|
-
|
|
323
|
-
The fallback inherits the Host's HTTP/2-only listener, so it serves only
|
|
324
|
-
HTTP/2 clients: h2c with prior knowledge, or TLS with ALPN `h2`. For example,
|
|
325
|
-
one Host can serve RPCs and Prometheus metrics:
|
|
326
|
-
|
|
327
|
-
```ruby
|
|
328
|
-
require "prometheus/client/formats/text"
|
|
329
|
-
|
|
330
|
-
metrics_app = lambda do |request|
|
|
331
|
-
next Protocol::HTTP::Response[404, {}, nil] unless request.path == "/metrics"
|
|
332
|
-
|
|
333
|
-
Protocol::HTTP::Response[200, { "content-type" => Prometheus::Client::Formats::Text::CONTENT_TYPE },
|
|
334
|
-
[Prometheus::Client::Formats::Text.marshal(Prometheus::Client.registry)]]
|
|
335
|
-
end
|
|
336
|
-
host = ConnectRPC::Async::Host.new(server: server, tls: tls, fallback: metrics_app).start
|
|
337
|
-
```
|
|
338
|
-
|
|
339
|
-
Prometheus scrapes a TLS Host over h2. A cleartext h2c Host is not reachable by
|
|
340
|
-
HTTP/1.1 clients, so those still need a separate listener or the
|
|
341
|
-
[Falcon package](../connectrpc-falcon/README.md), which serves HTTP/1.1 and
|
|
342
|
-
HTTP/2.
|
|
343
|
-
|
|
344
|
-
### Supervise with `wait`
|
|
345
|
-
|
|
346
|
-
`Host#wait` supports application supervision:
|
|
347
|
-
|
|
348
|
-
```ruby
|
|
349
|
-
Async do
|
|
350
|
-
host = ConnectRPC::Async::Host.new(server: server).start
|
|
351
|
-
begin
|
|
352
|
-
host.wait # Ordinary listener stop returns nil; terminal failure raises.
|
|
353
|
-
ensure
|
|
354
|
-
host.close # Await session drain separately from ordinary listener stop.
|
|
355
|
-
end
|
|
356
|
-
end.wait
|
|
357
|
-
```
|
|
358
|
-
|
|
359
|
-
Before start it raises `LifecycleError`, unless the Host was already closed.
|
|
360
|
-
Ordinary shutdown returns nil after all listener tasks stop and their listening
|
|
361
|
-
sockets close; session retirement may still be running. External
|
|
362
|
-
`close(grace:)` callers await the session's boolean drain outcome;
|
|
363
|
-
resource-owned calls can return nil while shutdown is pending, as described in
|
|
364
|
-
[Close results](#close-results). Terminal listener
|
|
365
|
-
failure instead makes `wait` raise the identical original exception after
|
|
366
|
-
cooperative session abort, listener joins and actual finalization of its stored
|
|
367
|
-
private exit task. A failure in that cleanup is written as a warning and never
|
|
368
|
-
replaces the cause, as described in
|
|
369
|
-
[Terminal failure and startup](#terminal-failure-and-startup).
|
|
370
|
-
Repeated/concurrent waits share that outcome; cancelling a waiter does not
|
|
371
|
-
close the Host. Since 0.3.0 a waiter that is cancelled, times out or is
|
|
372
|
-
otherwise interrupted while it waits for that cleanup gets its exception at
|
|
373
|
-
once, and the exit task finishes cleanup on its own; a later `wait` raises the
|
|
374
|
-
cause once it has. Like other lifecycle operations, `wait`
|
|
375
|
-
requires the owning reactor and thread.
|
|
376
|
-
|
|
377
805
|
### Accept errors
|
|
378
806
|
|
|
379
807
|
Since 0.3.0, accept errors that come from exhausted resources never stop a
|
|
@@ -393,6 +821,26 @@ Admitted RPCs and other listeners keep running during a delay, and `close`
|
|
|
393
821
|
ends it. Other accept errors and unexpected listener errors are terminal, as
|
|
394
822
|
described below. No RPC is replayed and no retry policy knobs are exposed.
|
|
395
823
|
|
|
824
|
+
### Waiting for the Host
|
|
825
|
+
|
|
826
|
+
Before start it raises `LifecycleError`, unless the Host was already closed.
|
|
827
|
+
Ordinary shutdown returns nil after all listener tasks stop and their listening
|
|
828
|
+
sockets close; session retirement may still be running. External
|
|
829
|
+
`close(grace:)` callers await the session's boolean drain outcome;
|
|
830
|
+
resource-owned calls can return nil while shutdown is pending, as described in
|
|
831
|
+
[Close results](#close-results). Terminal listener
|
|
832
|
+
failure instead makes `wait` raise the identical original exception once
|
|
833
|
+
cooperative session abort, listener joins and the rest of the cleanup in its
|
|
834
|
+
stored private exit task have completed. A failure in that cleanup is written
|
|
835
|
+
as a warning and never replaces the cause, as described in
|
|
836
|
+
[Terminal failure and startup](#terminal-failure-and-startup).
|
|
837
|
+
Repeated/concurrent waits share that outcome; cancelling a waiter does not
|
|
838
|
+
close the Host. Since 0.3.0 a waiter that is cancelled, times out or is
|
|
839
|
+
otherwise interrupted while it waits for that cleanup gets its exception at
|
|
840
|
+
once, and the exit task finishes cleanup on its own; a later `wait` raises the
|
|
841
|
+
cause once it has. Like other lifecycle operations, `wait`
|
|
842
|
+
requires the owning reactor and thread.
|
|
843
|
+
|
|
396
844
|
### Terminal failure and startup
|
|
397
845
|
|
|
398
846
|
The first terminal listener cause stops every listener and forces raw-first
|
|
@@ -400,10 +848,10 @@ session abort with zero drain time, then cooperative cancellation and joins.
|
|
|
400
848
|
Server abort has no cleanup deadline and cannot forcibly interrupt nonyielding
|
|
401
849
|
or cancellation-resistant application code. The stored exit task runs outside
|
|
402
850
|
the session lifetime under the application owner and survives ordinary owner
|
|
403
|
-
cancellation; `wait`
|
|
404
|
-
Ordinary owner cancellation stops accepting and resolves ordinary waits
|
|
405
|
-
listener
|
|
406
|
-
retains its drain result and does not raise the stored listener cause.
|
|
851
|
+
cancellation; `wait` reports the cause once that cleanup has completed.
|
|
852
|
+
Ordinary owner cancellation stops accepting and resolves ordinary waits once
|
|
853
|
+
every listener has stopped, while session retirement may still be running.
|
|
854
|
+
`close` retains its drain result and does not raise the stored listener cause.
|
|
407
855
|
Since 0.3.0 listener shutdown cancels and joins every accept loop before it
|
|
408
856
|
closes each listening socket once, so no accept loop is still waiting on a
|
|
409
857
|
socket as it closes, and concurrent shutdown steps run one at a time. Before
|
|
@@ -572,57 +1020,6 @@ stream window, never past the default 1 MiB ceiling. It belongs to `async:verify
|
|
|
572
1020
|
every 10 seconds, so the run takes about 45 seconds. `falcon:interop:grpc`
|
|
573
1021
|
runs the age drain and the BDP case through real Falcon workers.
|
|
574
1022
|
|
|
575
|
-
## Transport
|
|
576
|
-
|
|
577
|
-
`Transport.new(origin:, ca_file: nil, certificate_chain: nil, private_key: nil,
|
|
578
|
-
connection_limit: 1, max_requests: 128, connect_timeout: 10,
|
|
579
|
-
connection_policy: ConnectionPolicy.new, connection_observer: nil,
|
|
580
|
-
stream_receive_window: 4_194_304, connection_receive_window: 16_777_216,
|
|
581
|
-
dynamic_receive_windows: true, max_receive_window: 16_777_216,
|
|
582
|
-
proxy: :environment)` implements core's transport seam for HTTP/2. Since 0.3.0,
|
|
583
|
-
the receive windows size response downloads; see
|
|
584
|
-
[Flow-control windows](#flow-control-windows), and connections go through an
|
|
585
|
-
`http://` proxy chosen by `proxy:`; see [Proxies](#proxies).
|
|
586
|
-
|
|
587
|
-
- Origins contain only scheme/host/port; a bare trailing `/` is accepted.
|
|
588
|
-
Request paths, including core's base prefix, remain intact.
|
|
589
|
-
- One connection multiplexes requests. Admission fails with unavailable:
|
|
590
|
-
`HTTP/2 transport admission is full` at `max_requests` or
|
|
591
|
-
`max_pending_bytes`, and `HTTP/2 transport admission is closed` once closing.
|
|
592
|
-
Acquisition waits honor finite RPC deadlines.
|
|
593
|
-
- Nil RPC deadlines remain unbounded, while each connection attempt has its own
|
|
594
|
-
`connect_timeout`.
|
|
595
|
-
- An enclosing Async `with_timeout` around a call or stream operation ends it
|
|
596
|
-
with that same `Async::TimeoutError`, not a ConnectRPC error. The stream is
|
|
597
|
-
reset and its admission released as for any interrupted call. An already
|
|
598
|
-
expired RPC deadline or cancellation still wins.
|
|
599
|
-
- Connection and transport failures raise unavailable
|
|
600
|
-
`HTTP/2 transport failed: <reason>`, keeping the original exception as
|
|
601
|
-
`cause`. The reason is one of `connection refused`, `name resolution
|
|
602
|
-
failed`, `host unreachable`, `timed out`, `TLS verification failed`,
|
|
603
|
-
`ALPN negotiation failed`, `TLS error`, `connection closed` or `HTTP/2
|
|
604
|
-
protocol error`; an unclassified failure has no reason. Messages never
|
|
605
|
-
include the origin, addresses or certificate details. `HTTP1Transport` uses
|
|
606
|
-
the same reasons with `HTTP/1`, plus `malformed response`. Since 0.3.0, a
|
|
607
|
-
proxy hop adds the fixed [proxy](#proxies) reasons.
|
|
608
|
-
- No redirects or HTTP/1 fallback.
|
|
609
|
-
- The transport carries opaque encoded bytes; core owns compression and
|
|
610
|
-
negotiation.
|
|
611
|
-
|
|
612
|
-
[Client connection management](#client-connection-management) describes
|
|
613
|
-
reconnection, backoff, GOAWAY replacement, admission, rerouting of unsent calls
|
|
614
|
-
and the single resend of a refused Connect unary call. For TLS options, see
|
|
615
|
-
[TLS and client authentication](#tls-and-client-authentication).
|
|
616
|
-
|
|
617
|
-
### Safe unary GET
|
|
618
|
-
|
|
619
|
-
Safe unary GET uses core `Client.new(use_get: true)` and declared
|
|
620
|
-
`:no_side_effects` methods. Native HTTP/2 requests carry HEADERS with END_STREAM
|
|
621
|
-
and a nil body; core owns query encoding, parsing and independent URL/payload
|
|
622
|
-
limits. The transport never falls back to POST; a refused GET is resent only
|
|
623
|
-
under the refused-stream rule in
|
|
624
|
-
[Client connection management](#client-connection-management).
|
|
625
|
-
|
|
626
1023
|
## Client connection management
|
|
627
1024
|
|
|
628
1025
|
Each H2 `Transport` owns a private connection manager on its reactor. Its policy
|
|
@@ -833,41 +1230,13 @@ servers do not answer it with `too_many_pings`.
|
|
|
833
1230
|
- `connection_state` is a published observation, not a promise that the next
|
|
834
1231
|
call succeeds. `close` additionally stops admission, fails waiting calls with
|
|
835
1232
|
`unavailable`, and cancels the backoff timer and any attempt, raw socket
|
|
836
|
-
first.
|
|
837
|
-
|
|
838
|
-
##
|
|
839
|
-
|
|
840
|
-
`ThreadedTransport`
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
streaming. `streaming_capabilities` is `[:server_stream]` and
|
|
844
|
-
`grpc_capabilities` is `[:unary, :server_stream]`, so core rejects client and
|
|
845
|
-
bidi streaming before any I/O. Client and bidi streaming from ordinary threads
|
|
846
|
-
are tracked in [issue #29](https://github.com/jimeh/connectrpc-ruby/issues/29).
|
|
847
|
-
|
|
848
|
-
```ruby
|
|
849
|
-
require "connectrpc/async"
|
|
850
|
-
|
|
851
|
-
# Boot, for example in an initializer. No thread or socket starts here.
|
|
852
|
-
RPC = ConnectRPC::Async::ThreadedTransport.new(origin: "https://rpc.internal:8443")
|
|
853
|
-
client = ConnectRPC::Client.new(base_url: "https://rpc.internal:8443", binding: binding, transport: RPC)
|
|
854
|
-
|
|
855
|
-
client.call(method, message, timeout: 2) # Any thread.
|
|
856
|
-
client.server_stream(watch, message) { |reader| reader.each { ... } } # The block runs on this thread.
|
|
857
|
-
RPC.close(grace: 5) # Shutdown, for example in on_worker_shutdown.
|
|
858
|
-
```
|
|
859
|
-
|
|
860
|
-
It takes the same options as `Transport`, and they behave the same, including
|
|
861
|
-
the [connection policy](#client-connection-management). The constructor
|
|
862
|
-
validates them and compiles the TLS snapshot on the calling thread, so
|
|
863
|
-
configuration errors raise at boot. Since 0.3.0, the constructor also takes the
|
|
864
|
-
[proxy](#proxies) environment snapshot on the calling thread; every owner
|
|
865
|
-
thread, including one that replaces a stopped owner or starts after fork,
|
|
866
|
-
reuses it and never reads the environment itself. `call`, `open_stream`, `open_grpc_stream`,
|
|
867
|
-
`close(grace: 5)`, `connection_state` and `inspect` work from any thread,
|
|
868
|
-
including an Async task on a reactor thread such as a Falcon handler's, where
|
|
869
|
-
each wait suspends only that task. For calls inside a reactor, `Transport` or
|
|
870
|
-
`PerCallTransport` avoid the hop to the owner thread.
|
|
1233
|
+
first.
|
|
1234
|
+
|
|
1235
|
+
## ThreadedTransport behavior
|
|
1236
|
+
|
|
1237
|
+
This section covers how `ThreadedTransport` runs its owner thread, admits,
|
|
1238
|
+
bounds and interrupts calls, streams, closes and behaves under CPU load; the
|
|
1239
|
+
[Ordinary threads](#ordinary-threads) example does not need it.
|
|
871
1240
|
|
|
872
1241
|
### The owner thread
|
|
873
1242
|
|
|
@@ -938,12 +1307,22 @@ each `response_head`, `read`, `write`, `close_send`, `finish` and, for gRPC,
|
|
|
938
1307
|
and each chunk is a new string the caller owns.
|
|
939
1308
|
- An operation's wait is bounded by the deadline and by its own timeout, each
|
|
940
1309
|
plus the 1-second allowance. If the owner is stalled past that, the operation
|
|
941
|
-
fails with `deadline_exceeded`, or with `unavailable` for its own timeout
|
|
942
|
-
the stream is reset when the owner resumes.
|
|
1310
|
+
fails with `deadline_exceeded`, or with `unavailable` for its own timeout
|
|
1311
|
+
while the deadline is live, and the stream is reset when the owner resumes.
|
|
1312
|
+
An accepted cancellation keeps its `canceled`.
|
|
943
1313
|
- A normal block exit waits for the owner's actual outcome, bounded only by the
|
|
944
|
-
deadline as unary calls are.
|
|
945
|
-
|
|
946
|
-
|
|
1314
|
+
deadline as unary calls are. Since 0.3.1, once an operation's wait has
|
|
1315
|
+
ended past the deadline without the owner's answer, at the deadline or its
|
|
1316
|
+
own timeout, each plus the allowance, and the operation failed with
|
|
1317
|
+
`deadline_exceeded`, every other wait on the stream ends by the deadline
|
|
1318
|
+
plus the allowance. That includes the block exit's wait, even one already
|
|
1319
|
+
in progress. An operation that fails with another error, such as an
|
|
1320
|
+
accepted cancellation, shares nothing. A block that rescues the operation's
|
|
1321
|
+
`deadline_exceeded` and returns therefore adds no second allowance for a
|
|
1322
|
+
stalled owner, and still takes an outcome the owner has already published.
|
|
1323
|
+
A gRPC cleanup failure after the block returns reaches the caller as
|
|
1324
|
+
`unavailable`; the caller never reports success without the owner's
|
|
1325
|
+
outcome.
|
|
947
1326
|
- An exception, `Timeout`, `Thread#raise`, `Thread#kill`, `break` or `throw`
|
|
948
1327
|
out of the block, or interrupting an operation, fires the stream's
|
|
949
1328
|
cancellation before the owner is told to stop. A read or write blocked on the
|
|
@@ -1001,45 +1380,11 @@ MRI hands the GVL to a thread waking from I/O only after the running thread's
|
|
|
1001
1380
|
time slice, 100 ms by default, so CPU-bound threads delay the owner thread.
|
|
1002
1381
|
Lowering `RUBY_THREAD_TIMESLICE`, for example to 10, reduces that latency.
|
|
1003
1382
|
|
|
1004
|
-
##
|
|
1005
|
-
|
|
1006
|
-
Since 0.3.0, `PerCallTransport` opens one HTTP/2 connection per call, runs the
|
|
1007
|
-
exchange and closes the connection before the call returns. It suits a process
|
|
1008
|
-
that calls many origins occasionally, such as a Rails action that makes one
|
|
1009
|
-
gRPC call to one of hundreds of devices, where pooled connections, keepalive
|
|
1010
|
-
and an owner thread per origin cost more than a connection setup per call. For
|
|
1011
|
-
repeated calls to a few origins, use `ThreadedTransport` or `Transport`, which
|
|
1012
|
-
reuse their connections.
|
|
1013
|
-
|
|
1014
|
-
```ruby
|
|
1015
|
-
require "connectrpc/async"
|
|
1016
|
-
|
|
1017
|
-
# Boot, for example in an initializer. No thread or socket starts here.
|
|
1018
|
-
DEVICES = ConnectRPC::Async::PerCallTransport.new(ca_file: "devices-ca.pem")
|
|
1019
|
-
|
|
1020
|
-
client = ConnectRPC::Client.new(base_url: "https://device-17.internal:8443", binding: binding,
|
|
1021
|
-
transport: DEVICES, protocol: :grpc)
|
|
1022
|
-
client.call(method, message, timeout: 2) # Any thread, or inside an Async task.
|
|
1023
|
-
```
|
|
1024
|
-
|
|
1025
|
-
`PerCallTransport.new(ca_file: nil, certificate_chain: nil, private_key: nil,
|
|
1026
|
-
connect_timeout: 10, proxy: :environment)` validates its options, compiles one
|
|
1027
|
-
TLS snapshot at construction, with the system roots plus the optional
|
|
1028
|
-
`ca_file`, takes its [proxy](#proxies) snapshot and holds only frozen
|
|
1029
|
-
configuration. It has no `origin:` and no `close`: every call dials the scheme,
|
|
1030
|
-
host and port of its request URL, or tunnels to them through a proxy, so one
|
|
1031
|
-
instance serves every origin from any number of threads. `http` URLs use h2c
|
|
1032
|
-
with prior knowledge and `https` URLs use TLS with ALPN `h2`. The request URL,
|
|
1033
|
-
including core's path
|
|
1034
|
-
prefix and a GET query, reaches the server unchanged. A URL that is not HTTP(S),
|
|
1035
|
-
has no host or carries userinfo, and TLS options with an `http` URL, raise
|
|
1036
|
-
`ArgumentError` before any socket opens; the transport never falls back to
|
|
1037
|
-
plaintext.
|
|
1383
|
+
## PerCallTransport behavior
|
|
1038
1384
|
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
and bidi streaming before any I/O.
|
|
1385
|
+
This section covers how `PerCallTransport` runs, resends, closes and
|
|
1386
|
+
interrupts each call; the [One-off calls](#one-off-calls) example does not
|
|
1387
|
+
need it.
|
|
1043
1388
|
|
|
1044
1389
|
- Inside an Async task, the call runs inline on the caller's reactor, as with
|
|
1045
1390
|
`Transport`, and starts no thread. Its connection tasks belong to a private
|
|
@@ -1092,14 +1437,17 @@ and bidi streaming before any I/O.
|
|
|
1092
1437
|
start, and the close always gives the owner at least one allowance from
|
|
1093
1438
|
its start. An owner that responds is therefore joined even when the close
|
|
1094
1439
|
starts long after the deadline, for example after a stream block that
|
|
1095
|
-
kept working past it. A
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1440
|
+
kept working past it. A stream's terminal wait ends sooner once one of its
|
|
1441
|
+
operations has waited past the deadline without the owner's answer, and
|
|
1442
|
+
failed with `deadline_exceeded`: it ends by the deadline plus the
|
|
1443
|
+
allowance. A stalled owner, for example blocked in
|
|
1444
|
+
native code, holds the call one allowance past the deadline for each such
|
|
1445
|
+
wait: two for a unary call, or for a stream whose block ends when its
|
|
1446
|
+
deadline error arrives, whether the block lets that error propagate or
|
|
1447
|
+
rescues it and returns at once. The owner exits once it resumes. Beyond
|
|
1448
|
+
those bounds, an owner that has already published its outcome and is
|
|
1449
|
+
exiting, for example while it waits for the GVL, is still joined, which
|
|
1450
|
+
can take up to another allowance. With a custom `Deadline`
|
|
1103
1451
|
clock, each wait converts the remaining time it reads when it starts to
|
|
1104
1452
|
monotonic time, so the bounds hold against that reading rather than the
|
|
1105
1453
|
custom clock.
|
|
@@ -1112,7 +1460,80 @@ and bidi streaming before any I/O.
|
|
|
1112
1460
|
Instrumentation reports `PerCallTransport` as the transport class, with the
|
|
1113
1461
|
same call facts, outcomes and completions as the other HTTP/2 clients.
|
|
1114
1462
|
|
|
1115
|
-
|
|
1463
|
+
## HTTP1Transport behavior
|
|
1464
|
+
|
|
1465
|
+
This section covers the leases, capacity, deadlines, reuse, TLS and upload
|
|
1466
|
+
failures of `HTTP1Transport`; the [Explicit HTTP/1.1 client](#explicit-http11-client)
|
|
1467
|
+
example does not need it.
|
|
1468
|
+
|
|
1469
|
+
### Leases and capacity
|
|
1470
|
+
|
|
1471
|
+
A lease is one operation's exclusive use of a connection. Each connection has
|
|
1472
|
+
one lease at a time, held through setup, the upload, the full HTTP EOF and
|
|
1473
|
+
cleanup. Pending dials and retiring connections count toward the hard cap
|
|
1474
|
+
(`connection_limit`). Operations waiting for a lease count toward admission
|
|
1475
|
+
(`max_requests`). With the defaults, four long streams can occupy every slot.
|
|
1476
|
+
Configure the capacity, or give waiting operations cancellation or deadlines;
|
|
1477
|
+
the transport does not promise fairness.
|
|
1478
|
+
|
|
1479
|
+
`close(grace: 5)` stops admitting new operations and drains the admitted ones,
|
|
1480
|
+
including those still waiting for a lease. It returns false if it had to force
|
|
1481
|
+
teardown. When the owner exits, the transport aborts the resources it owns.
|
|
1482
|
+
Forced teardown shuts down a connection's raw TCP socket at once, and keeps
|
|
1483
|
+
its lease and file descriptor until its tasks have joined. Admission fails with
|
|
1484
|
+
`HTTP/1 transport admission is full` once `max_requests` operations are
|
|
1485
|
+
admitted, and with `HTTP/1 transport admission is closed` once the transport
|
|
1486
|
+
is closing.
|
|
1487
|
+
|
|
1488
|
+
The transport has no hidden thread, pipelining, replay or fallback, and it
|
|
1489
|
+
makes one kind of resend. A server may close an idle keep-alive connection
|
|
1490
|
+
while the next request is on its way. So a unary GET whose reused connection
|
|
1491
|
+
closed before the final response head arrived is sent once more on another
|
|
1492
|
+
connection, unless it was cancelled, its deadline expired or the transport
|
|
1493
|
+
started closing. Call observers see no failure from the attempt that was
|
|
1494
|
+
resent. POST and streams are never resent.
|
|
1495
|
+
|
|
1496
|
+
### Deadlines and reuse
|
|
1497
|
+
|
|
1498
|
+
A finite RPC deadline covers every wait, including cleanup. A nil RPC deadline
|
|
1499
|
+
adds no watchdog, but setup still has its own combined connect timeout
|
|
1500
|
+
(`connect_timeout`). Cancellation from another thread only signals the
|
|
1501
|
+
reactor. A connection can be reused after a full native EOF, a successful
|
|
1502
|
+
joined writer and successful cleanup. Any abandoned or failed exchange retires
|
|
1503
|
+
its connection, so the transport does not reuse it. A unary response that the
|
|
1504
|
+
server ends cleanly by closing the connection (close-delimited) is supported.
|
|
1505
|
+
Without Content-Length, though, the client cannot detect a truncation that
|
|
1506
|
+
still leaves an otherwise valid response. On TLS, an unexpected EOF without
|
|
1507
|
+
close_notify remains a transport error.
|
|
1508
|
+
|
|
1509
|
+
### TLS
|
|
1510
|
+
|
|
1511
|
+
TLS offers only `http/1.1`, accepts absent or H1 ALPN, and rejects every other
|
|
1512
|
+
negotiation before request bytes. Peer/hostname verification and mTLS remain
|
|
1513
|
+
enabled. TCP rejects TLS options. Replace the transport to change TLS identity.
|
|
1514
|
+
|
|
1515
|
+
### Upload failures
|
|
1516
|
+
|
|
1517
|
+
Response reads are independent of a blocked upload. A complete unary non-200
|
|
1518
|
+
response stops pending output destructively so core can validate its error;
|
|
1519
|
+
HTTP 200 requires writer success. For streaming, `write` alone reports a writer
|
|
1520
|
+
failure. Core may then recover a remote error through its bounded terminal-only
|
|
1521
|
+
policy. An unreported upload-tail failure returns unavailable even if a remote
|
|
1522
|
+
error terminal arrived, masking that error. `close_send` never raises writer
|
|
1523
|
+
failure; `finish` requires full HTTP EOF and joined cleanup under the supplied
|
|
1524
|
+
completion budget. A write-only caller without a deadline can still block when
|
|
1525
|
+
a peer neither consumes nor closes. See
|
|
1526
|
+
[streaming](../../docs/streaming.md#explicit-http11-client).
|
|
1527
|
+
|
|
1528
|
+
### HTTP/1.1 evidence
|
|
1529
|
+
|
|
1530
|
+
`async:conformance:http1` runs separate strict official 1.0.6 native H1 CLIENT
|
|
1531
|
+
inventories: 386 identity and 352 gzip cases, including safe GET, both codecs,
|
|
1532
|
+
TCP/TLS and client certificates. `async:interop:http1` runs independent pinned
|
|
1533
|
+
connect-go H1-only TCP/TLS/mTLS listeners, with actual HTTP/1.1 and ALPN evidence.
|
|
1534
|
+
Existing H2, NetHTTP and Falcon server inventories remain separate.
|
|
1535
|
+
|
|
1536
|
+
## Proxies
|
|
1116
1537
|
|
|
1117
1538
|
Since 0.3.0, every client transport can reach its origins through an `http://`
|
|
1118
1539
|
proxy. `Transport`, `ThreadedTransport`, `HTTP1Transport` and
|
|
@@ -1199,88 +1620,6 @@ ConnectRPC::Async::PerCallTransport.new # proxy: :environmen
|
|
|
1199
1620
|
when they arrive with the end of the reply. Later ones fail the TLS
|
|
1200
1621
|
handshake instead, as `TLS error`.
|
|
1201
1622
|
|
|
1202
|
-
## Explicit HTTP/1.1 client
|
|
1203
|
-
|
|
1204
|
-
```ruby
|
|
1205
|
-
Async do
|
|
1206
|
-
transport = ConnectRPC::Async::HTTP1Transport.new(origin: "https://rpc.example.com")
|
|
1207
|
-
client = ConnectRPC::Client.new(base_url: "https://rpc.example.com", binding: binding,
|
|
1208
|
-
transport: transport, use_get: true)
|
|
1209
|
-
begin
|
|
1210
|
-
client.call(method, message)
|
|
1211
|
-
# Existing generated clients and core server_stream/client_stream use it too.
|
|
1212
|
-
ensure
|
|
1213
|
-
transport.close
|
|
1214
|
-
end
|
|
1215
|
-
end.wait
|
|
1216
|
-
```
|
|
1217
|
-
|
|
1218
|
-
`HTTP1Transport.new(origin:, ca_file: nil, certificate_chain: nil, private_key:
|
|
1219
|
-
nil, connection_limit: 4, max_requests: 128, connect_timeout: 10, proxy:
|
|
1220
|
-
:environment)` is an explicit Connect H1 client. Since 0.3.0 it reaches its
|
|
1221
|
-
origin through an `http://` proxy chosen by `proxy:`; see [Proxies](#proxies). Pass it through the existing core/generated client's
|
|
1222
|
-
`transport:` option inside an application-owned Async reactor. It supports safe
|
|
1223
|
-
unary GET, both codecs and identity/gzip through core, and SS/CS through the
|
|
1224
|
-
existing streaming SPI. It has no gRPC or bidi capability. Standalone Async Host
|
|
1225
|
-
remains H2-only; Falcon owns Ruby H1 hosting. For ordinary threads, see
|
|
1226
|
-
[`ThreadedTransport`](#ordinary-threads).
|
|
1227
|
-
|
|
1228
|
-
### Leases and capacity
|
|
1229
|
-
|
|
1230
|
-
Each connection has one exclusive lease through setup, upload, full HTTP EOF
|
|
1231
|
-
and cleanup. Pending dials and retiring connections count toward the hard cap;
|
|
1232
|
-
lease waits count toward admission. Four long streams can occupy every default
|
|
1233
|
-
slot. Configure capacity or give waiters cancellation/deadlines; fairness is not
|
|
1234
|
-
promised. `close(grace: 5)` stops admission and drains admitted operations,
|
|
1235
|
-
including waiters, returning false on forced teardown. Owner exit aborts owned
|
|
1236
|
-
resources. Forced teardown shuts a connection's raw TCP down at once and keeps
|
|
1237
|
-
its lease and descriptor until its tasks have joined. Admission fails with
|
|
1238
|
-
`HTTP/1 transport admission is full` at `max_requests` and
|
|
1239
|
-
`HTTP/1 transport admission is closed` once closing. There
|
|
1240
|
-
is no hidden thread, pipelining, replay or fallback, and one resend: a server
|
|
1241
|
-
may close an idle keep-alive connection while the next request crosses it, so
|
|
1242
|
-
a unary GET whose reused connection closed before any response head is sent
|
|
1243
|
-
once more on another connection, unless it was cancelled, its deadline expired
|
|
1244
|
-
or the transport started closing. Call observers see no failure from the
|
|
1245
|
-
attempt that was resent. POST and streams are never resent.
|
|
1246
|
-
|
|
1247
|
-
### Deadlines and reuse
|
|
1248
|
-
|
|
1249
|
-
Finite RPC deadlines cover every wait including cleanup. Nil RPC deadlines add
|
|
1250
|
-
no watchdog; setup still has its own combined connect timeout. Foreign-thread
|
|
1251
|
-
cancellation only signals the reactor. Full native EOF, a successful joined
|
|
1252
|
-
writer and successful cleanup permit reuse. Any abandoned/failed exchange
|
|
1253
|
-
retires its connection. Clean close-delimited unary EOF is supported, but
|
|
1254
|
-
cannot detect an otherwise valid semantic truncation without Content-Length.
|
|
1255
|
-
TLS unexpected EOF without close_notify remains a transport error.
|
|
1256
|
-
|
|
1257
|
-
### TLS
|
|
1258
|
-
|
|
1259
|
-
TLS offers only `http/1.1`, accepts absent or H1 ALPN, and rejects every other
|
|
1260
|
-
negotiation before request bytes. Peer/hostname verification and mTLS remain
|
|
1261
|
-
enabled. TCP rejects TLS options. Replace the transport to change TLS identity.
|
|
1262
|
-
|
|
1263
|
-
### Upload failures
|
|
1264
|
-
|
|
1265
|
-
Response reads are independent of a blocked upload. A complete unary non-200
|
|
1266
|
-
response stops pending output destructively so core can validate its error;
|
|
1267
|
-
HTTP 200 requires writer success. For streaming, `write` alone reports a writer
|
|
1268
|
-
failure. Core may then recover a remote error through its bounded terminal-only
|
|
1269
|
-
policy. An unreported upload-tail failure returns unavailable even if a remote
|
|
1270
|
-
error terminal arrived, masking that error. `close_send` never raises writer
|
|
1271
|
-
failure; `finish` requires full HTTP EOF and joined cleanup under the supplied
|
|
1272
|
-
completion budget. A write-only caller without a deadline can still block when
|
|
1273
|
-
a peer neither consumes nor closes. See
|
|
1274
|
-
[streaming](../../docs/streaming.md#explicit-http11-client).
|
|
1275
|
-
|
|
1276
|
-
### HTTP/1.1 evidence
|
|
1277
|
-
|
|
1278
|
-
`async:conformance:http1` runs separate strict official 1.0.6 native H1 CLIENT
|
|
1279
|
-
inventories: 386 identity and 352 gzip cases, including safe GET, both codecs,
|
|
1280
|
-
TCP/TLS and client certificates. `async:interop:http1` runs independent pinned
|
|
1281
|
-
connect-go H1-only TCP/TLS/mTLS listeners, with actual HTTP/1.1 and ALPN evidence.
|
|
1282
|
-
Existing H2, NetHTTP and Falcon server inventories remain separate.
|
|
1283
|
-
|
|
1284
1623
|
## Close and cleanup
|
|
1285
1624
|
|
|
1286
1625
|
Both `Host` and `Transport` provide `close(grace: 5)`. `Host` stops accepting
|
|
@@ -1370,16 +1709,19 @@ retirement is joined.
|
|
|
1370
1709
|
|
|
1371
1710
|
### Forced teardown and retirement
|
|
1372
1711
|
|
|
1373
|
-
Forced teardown invalidates the connection immediately.
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1712
|
+
Forced teardown invalidates the connection immediately. Retirement is the
|
|
1713
|
+
cleanup that then disposes of the connection. An external caller, one that is
|
|
1714
|
+
not a task the connection or session owns, can call the private connection
|
|
1715
|
+
abort or the server session's `abort` or `close`. It then waits for the owned
|
|
1716
|
+
tasks, the cleanup tasks they start, and the final disposal of buffered data
|
|
1717
|
+
and TLS state. An owned task that starts an abort, or calls it again during
|
|
1718
|
+
one, only requests retirement. It does not wait, because that cleanup must
|
|
1719
|
+
join the same task. Each external caller joining a private connection abort
|
|
1720
|
+
keeps its own first interruption, such as a cancellation, until cleanup
|
|
1721
|
+
completes. Server session callers that are interrupted leave at once, as
|
|
1722
|
+
described next. A retirement step that fails is reported by the task that ran
|
|
1723
|
+
it, as described in [Close and cleanup](#close-and-cleanup), and every other
|
|
1724
|
+
connection is still retired.
|
|
1383
1725
|
|
|
1384
1726
|
### Interrupted server close
|
|
1385
1727
|
|
|
@@ -1467,81 +1809,22 @@ finished, leaves the result true.
|
|
|
1467
1809
|
|
|
1468
1810
|
### Task joins
|
|
1469
1811
|
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
tls = {
|
|
1487
|
-
certificate_chain: [File.read("leaf.pem"), File.read("intermediate.pem")],
|
|
1488
|
-
private_key: File.read("key.pem"),
|
|
1489
|
-
client_ca: nil # Or a nonempty array of explicit trust-anchor PEM certificates.
|
|
1490
|
-
}
|
|
1491
|
-
```
|
|
1492
|
-
|
|
1493
|
-
### Certificates and verification
|
|
1494
|
-
|
|
1495
|
-
Each certificate element contains exactly one PEM certificate, leaf first.
|
|
1496
|
-
Keys are unencrypted PEM private keys. Inputs are copied and parsed without
|
|
1497
|
-
password prompts; key possession, leaf validity and adjacent chain signatures
|
|
1498
|
-
are checked. Snapshots retain private parsed objects, redact inspection/errors,
|
|
1499
|
-
and compile fresh contexts before publication. Explicit intermediates, including
|
|
1500
|
-
an empty array, prevent auto-chaining through the client-auth trust store.
|
|
1501
|
-
|
|
1502
|
-
Both roles require TLS >=1.2 and post-check ALPN `h2`. Clients always verify
|
|
1503
|
-
peer/hostname, including localhost, using system roots plus optional `ca_file`.
|
|
1504
|
-
Client chain/key must appear together; TLS options are invalid for h2c. IP
|
|
1505
|
-
literal origins send no server name (RFC 6066 section 3), and the certificate
|
|
1506
|
-
must still match the address.
|
|
1507
|
-
|
|
1508
|
-
Client TLS inputs differ in kind: `ca_file` is a filesystem path to a PEM CA
|
|
1509
|
-
bundle, `certificate_chain` is an array of PEM certificate strings, leaf first,
|
|
1510
|
-
and `private_key` is a PEM string. An invalid input raises `ArgumentError`
|
|
1511
|
-
naming the input, such as `Invalid TLS client configuration: ca_file`, without
|
|
1512
|
-
its value or a cause.
|
|
1513
|
-
|
|
1514
|
-
### Client authentication
|
|
1515
|
-
|
|
1516
|
-
A nonempty `client_ca` requires verified client certificates using only those
|
|
1517
|
-
anchors, with partial-chain trust enabled deliberately. A scoped intermediate
|
|
1518
|
-
can be the boundary; sibling issuers under its root are not trusted. Nil means
|
|
1519
|
-
server-only TLS and no client authentication. There is no optional-client mode.
|
|
1520
|
-
|
|
1521
|
-
`host.peer_certificate` returns a detached authenticated client leaf only within
|
|
1522
|
-
that host's exact handler task; outside/child/other-host/plain/server-only TLS
|
|
1523
|
-
returns nil. It does not expose or claim a verified chain and does not change
|
|
1524
|
-
core Context. Applications own authorization based on that identity.
|
|
1525
|
-
|
|
1526
|
-
### Reload and drain
|
|
1527
|
-
|
|
1528
|
-
`host.reload_tls(certificate_chain:, private_key:, client_ca:)` replaces the
|
|
1529
|
-
complete snapshot for newly accepted sockets on the same listener. Generation
|
|
1530
|
-
starts at 1 and increments only after successful validation; invalid candidates
|
|
1531
|
-
leave the last good snapshot intact. Existing connections retain their prior
|
|
1532
|
-
identity and authentication. Every generation has a fresh context/session ID,
|
|
1533
|
-
OP_NO_TICKET and SESSION_CACHE_OFF. Reuse is disabled; this does not claim that
|
|
1534
|
-
OpenSSL emits zero TLS 1.3 tickets. Replace a transport to change client identity.
|
|
1535
|
-
|
|
1536
|
-
`host.drain_tls(grace: 5)` captures the current generation cutoff and retires
|
|
1537
|
-
only older accepted connections, including pending handshakes. Old connections
|
|
1538
|
-
get the two-phase GOAWAY drain with debug data `tls_rotation`: streams opened
|
|
1539
|
-
before its cutoff are served, later ones are refused with `REFUSED_STREAM`, and
|
|
1540
|
-
admitted streams finish. Pending handshakes abort immediately.
|
|
1541
|
-
A persistent retirement floor prevents old pending sockets from becoming live.
|
|
1542
|
-
The listener and current/newer generations survive concurrent reloads/drains.
|
|
1543
|
-
Close supersedes drains. Renewal alone does not instantly revoke existing peers.
|
|
1544
|
-
There are no file watchers, ACME, secret services or authentication policy DSLs.
|
|
1812
|
+
The library's private task joins wait until a task and its non-transient
|
|
1813
|
+
descendants have settled. A task has settled when its block,
|
|
1814
|
+
`ensure` included, has returned. Once a join has seen a child, it keeps
|
|
1815
|
+
joining it, even if the child moves to another parent or gains a transient
|
|
1816
|
+
flag. The join walks the task tree again after each wake-up, so it also joins
|
|
1817
|
+
a task created while the tree unwinds. Async may still be stopping a settled
|
|
1818
|
+
task's children or clearing its fiber, but that work runs no application code.
|
|
1819
|
+
A chance for other tasks to run after a raw socket failure does not mark
|
|
1820
|
+
completion. Disposal and the publication of retirement still wait for every
|
|
1821
|
+
retained task join.
|
|
1822
|
+
|
|
1823
|
+
These joins require cooperative tasks, which yield to the scheduler, and a live
|
|
1824
|
+
application reactor. A handler or native operation that never yields can delay
|
|
1825
|
+
them indefinitely. Cleanup survives ordinary cancellation of the owner while an
|
|
1826
|
+
external waiter or a lifetime guard keeps the task tree alive. If the reactor
|
|
1827
|
+
terminates, completion cannot be guaranteed.
|
|
1545
1828
|
|
|
1546
1829
|
## Native application and managed TLS
|
|
1547
1830
|
|
|
@@ -1908,29 +2191,18 @@ RPC cancellation; credit accounting adds no lifecycle instrumentation.
|
|
|
1908
2191
|
|
|
1909
2192
|
### Upstream contract guard
|
|
1910
2193
|
|
|
1911
|
-
This package replaces or calls a few async-http and protocol-http2 hooks
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
`#consume` after it clears a finished task's fiber (on normal return, failure
|
|
1918
|
-
and cancellation). It must also call the parent's `#consume` when the last
|
|
1919
|
-
child leaves, and `Fiber.scheduler.push` must run a pushed object on a later
|
|
1920
|
-
iteration.
|
|
1921
|
-
|
|
1922
|
-
If any check fails, require raises one error that names each broken contract,
|
|
1923
|
-
the installed gem version and the versions the package was verified with.
|
|
1924
|
-
That replaces a hang or misbehavior at runtime. There is no switch to skip the
|
|
1925
|
-
check. The finalization probe has a 5 s budget, including the time to stop it.
|
|
1926
|
-
If it runs out, the error lists the failures already found and the step that
|
|
1927
|
-
stalled. When the broken contract also stops Async from tearing down the
|
|
1928
|
-
probe's reactor, the probe thread stays asleep for the rest of the process.
|
|
2194
|
+
This package replaces or calls a few async-http and protocol-http2 hooks.
|
|
2195
|
+
`require "connectrpc/async"` checks each hook's owner, visibility and parameter
|
|
2196
|
+
shape once per process, in about a millisecond. If any check fails, require
|
|
2197
|
+
raises one error that names each broken contract, the installed gem version
|
|
2198
|
+
and the versions the package was verified with. That replaces a hang or
|
|
2199
|
+
misbehavior at runtime. There is no switch to skip the check.
|
|
1929
2200
|
`connectrpc/falcon` checks its async-http `Endpoint` hooks the same way. The
|
|
1930
|
-
guards cover the patch-pinned async-http and protocol-http2 hooks
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
2201
|
+
guards cover the patch-pinned async-http and protocol-http2 hooks. Async itself
|
|
2202
|
+
is not patch-pinned: the retirement joins use only its public task API
|
|
2203
|
+
(`Task#wait`, the task state predicates, `children` and `transient?`), so the
|
|
2204
|
+
gemspec allows `async >= 2.46.0, < 3`, the floor-and-cap tier in the
|
|
2205
|
+
[dependency policy](../../docs/development.md#gem-dependency-constraints).
|
|
1934
2206
|
async-http and protocol-http2 stay patch-pinned because the semantics their
|
|
1935
2207
|
replaced hooks depend on cannot be proven at boot; the daily
|
|
1936
2208
|
[pins-lifted canary](../../docs/development.md#pins-lifted-canary) runs these
|
|
@@ -1954,123 +2226,6 @@ exercised under that activation. Focused combined
|
|
|
1954
2226
|
specs cover actual gzip bytes over h2c/TLS in both codecs and independent host
|
|
1955
2227
|
wire/inflated and transport wire/client inflated caps. Nothing is published.
|
|
1956
2228
|
|
|
1957
|
-
## Explicit unary cancellation
|
|
1958
|
-
|
|
1959
|
-
Pass `cancellation: source.token` to core or generated client calls, where
|
|
1960
|
-
`source = ConnectRPC::CancellationSource.new`. The source is permanent and
|
|
1961
|
-
shareable; only `source.cancel` initiates cancellation. `timeout: nil` without
|
|
1962
|
-
`deadline:` keeps no RPC deadline or wire timeout. Context offers cooperative `cancelled?`,
|
|
1963
|
-
`cancellation_reason` and `check!`. See the
|
|
1964
|
-
[unary guide](../../docs/unary.md#cancellation) for listener, arbitration and
|
|
1965
|
-
registration lifetime rules.
|
|
1966
|
-
|
|
1967
|
-
The Async transport accepts foreign-thread cancellation through a Promise;
|
|
1968
|
-
only the owner reactor stops private SDK tasks and performs stream cleanup.
|
|
1969
|
-
Cancellation, an expired deadline or a stopped caller task resets the call's
|
|
1970
|
-
stream with `RST_STREAM(CANCEL)`, including while its upload waits for
|
|
1971
|
-
flow-control credit. Healthy multiplexed siblings survive. A stuck frame retains the one
|
|
1972
|
-
[cleanup allowance](#cleanup-allowance) and raw-first whole-connection fallback. Native HTTP/2 Context observes
|
|
1973
|
-
only an actual peer RST_STREAM(CANCEL), before input teardown. Other resets,
|
|
1974
|
-
normal half-close, connection loss and host shutdown do not fabricate explicit
|
|
1975
|
-
cancellation. Processing completion detaches the source independently of delivery.
|
|
1976
|
-
|
|
1977
|
-
## Native streaming
|
|
1978
|
-
|
|
1979
|
-
The core [streaming guide](../../docs/streaming.md) documents all three scoped
|
|
1980
|
-
Connect streaming shapes, typed generated clients/handlers, early headers,
|
|
1981
|
-
per-message limits and bounded ownership. Native Async/Falcon HTTP/2 supports
|
|
1982
|
-
both codecs and identity/gzip over h2c/TLS/mTLS. Falcon additionally serves
|
|
1983
|
-
Connect server and client streaming over HTTP/1.1, with protobuf/ProtoJSON and
|
|
1984
|
-
identity/gzip over TCP/TLS/mTLS. The standalone Async Host and original Async
|
|
1985
|
-
Transport remain H2-only. Use the independent
|
|
1986
|
-
[`HTTP1Transport`](#explicit-http11-client) for Connect unary, server streaming
|
|
1987
|
-
and client streaming. See the streaming guide for Falcon's cooperative 500 ms
|
|
1988
|
-
total final-close budget and unchanged 100 ms / 256 KiB discard limits. The
|
|
1989
|
-
client's provisional one-second absolute HTTP tail policy applies even with a
|
|
1990
|
-
nil RPC deadline and can reject otherwise valid late EOF or slow intermediaries.
|
|
1991
|
-
See the [support contract](../../docs/support.md#native-client-completion).
|
|
1992
|
-
|
|
1993
|
-
Use `async:conformance` and `async:interop:streaming` for the exact official
|
|
1994
|
-
native client/server inventories and independent pinned Go streaming matrix.
|
|
1995
|
-
Both belong to `async:verify`; original unary interoperability remains separate.
|
|
1996
|
-
|
|
1997
|
-
## Native gRPC
|
|
1998
|
-
|
|
1999
|
-
Native HTTP/2 supports unary, server streaming, client streaming and bidi gRPC
|
|
2000
|
-
with protobuf, identity/gzip, h2c, verified TLS and mTLS. Configure the core
|
|
2001
|
-
Client with `protocol: :grpc` and the Server with `:grpc` or `:auto`. Generated
|
|
2002
|
-
clients and handlers reuse the existing declarations. Portable HTTP/1 execution
|
|
2003
|
-
retains its early rejection guard. See the [gRPC guide](../../docs/grpc.md) for
|
|
2004
|
-
status codecs, actual final HEADERS, independent status bounds and native field
|
|
2005
|
-
retention limits. Connect's one-second terminal tail policy remains Connect-only.
|
|
2006
|
-
|
|
2007
|
-
Use `async:conformance:grpc` for exact official inventories and
|
|
2008
|
-
`async:interop:grpc` for generated official grpc-go peer checks. Both belong
|
|
2009
|
-
to the owning verify task. `async:interop:grpc` first reproduces the official Go
|
|
2010
|
-
and Ruby peer outputs through the Async bundle, the same check root
|
|
2011
|
-
`grpc:generation:check` runs through the core bundle. `grpc:status:check`
|
|
2012
|
-
reproduces private Any/Status descriptors. `async:interop:grpc` also checks
|
|
2013
|
-
that the `Transport` and `ThreadedTransport` clients decode the peer's rich
|
|
2014
|
-
status, typed details and metadata from a unary error sent after headers and
|
|
2015
|
-
from trailers-only unary and server-stream errors. A raw HTTP/2 client first
|
|
2016
|
-
checks that grpc-go sends each trailers-only error as one HEADERS frame with
|
|
2017
|
-
END_HEADERS and END_STREAM.
|
|
2018
|
-
|
|
2019
|
-
## gRPC-Web
|
|
2020
|
-
|
|
2021
|
-
The native H2 server supports explicitly enabled binary/text unary and
|
|
2022
|
-
server-stream gRPC-Web. Browser incremental delivery uses text. See the
|
|
2023
|
-
[Web guide](../../docs/grpc-web.md) for protocol, CORS, bounds and completion
|
|
2024
|
-
rules.
|
|
2025
|
-
|
|
2026
|
-
## Interceptors
|
|
2027
|
-
|
|
2028
|
-
Server interceptors configured on the core Server cover every RPC the native
|
|
2029
|
-
host serves: [unary](../../docs/unary.md#interceptors) calls through
|
|
2030
|
-
`server_unary`, and server, client and bidi
|
|
2031
|
-
[streams](../../docs/streaming.md#interceptors) through `server_stream`, on
|
|
2032
|
-
Connect and native gRPC, plus unary and server-stream gRPC-Web. They run after
|
|
2033
|
-
core decodes a unary or server-streaming request, around the handler, with the
|
|
2034
|
-
first interceptor listed outermost. They run in the per-request processing
|
|
2035
|
-
task, so `host.peer_certificate` returns the authenticated client leaf inside an
|
|
2036
|
-
interceptor, the same as in the handler. Stream wrapper methods see it only when
|
|
2037
|
-
called from that task; a child task gets nil, so read the certificate in the
|
|
2038
|
-
interceptor before starting child work. A continuation called from a child task
|
|
2039
|
-
fails with `InterceptorStateError`.
|
|
2040
|
-
|
|
2041
|
-
Client interceptors run on the calling task or thread for `Transport`,
|
|
2042
|
-
`HTTP1Transport` and `ThreadedTransport`, before core encodes the request.
|
|
2043
|
-
|
|
2044
|
-
## RPC observation
|
|
2045
|
-
|
|
2046
|
-
Configure `instrumentation:` on the core Client/Server to enable the fixed
|
|
2047
|
-
neutral per-call lifecycle or the optional
|
|
2048
|
-
[OpenTelemetry adapter](../connectrpc-otel/README.md). Native hosts create
|
|
2049
|
-
explicit handles before a request's handler starts, activate the actual handler
|
|
2050
|
-
tasks, and finish after full-write/reset/cleanup evidence. An HTTP/2 stream
|
|
2051
|
-
refused while its HEADERS are read, because host admission is full, gets its
|
|
2052
|
-
handle in a separate task after the refusal. That handle is never activated and
|
|
2053
|
-
finishes once the reset is written, or as not delivered if the connection ends
|
|
2054
|
-
first. Shared H2 client connection attempts run outside every RPC lifecycle, so
|
|
2055
|
-
tracing never parents connection setup to the call that triggered it. Use the
|
|
2056
|
-
transport's `connection_observer` for connection events. Since 0.3.0, the
|
|
2057
|
-
Application passes the request authority (HTTP/1 `Host` or HTTP/2
|
|
2058
|
-
`:authority`) to core as the reserved `host` field, so the server call records
|
|
2059
|
-
the address the client used; handler metadata never contains it. Like the
|
|
2060
|
-
`Host` field a Rack server passes, it counts toward the gRPC and gRPC-Web
|
|
2061
|
-
request field limits, as `:authority` counts toward an HTTP/2 header list.
|
|
2062
|
-
|
|
2063
|
-
## Static signatures
|
|
2064
|
-
|
|
2065
|
-
This package owns `sig/` and its discovery manifest. Add `library "connectrpc"`
|
|
2066
|
-
and `library "connectrpc-async"` to a strict Steep target with this gem
|
|
2067
|
-
installed. The manifest lists only standard libraries, so name each connectrpc
|
|
2068
|
-
library explicitly; this also works with `rbs collection`. See the
|
|
2069
|
-
[RBS guide](../../docs/rbs.md) for supported APIs, extension contracts, partial
|
|
2070
|
-
records, runtime validation and framework-signature limits. `mise run rbs:check`
|
|
2071
|
-
checks application callers for this package; strict core source checking is a
|
|
2072
|
-
separate target from backend implementation checking.
|
|
2073
|
-
|
|
2074
2229
|
## Development
|
|
2075
2230
|
|
|
2076
2231
|
Discover `async:setup`, `async:test`, `async:check`, `async:build`,
|