connectrpc 0.2.1 → 0.3.0

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.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +57 -21
  3. data/docs/design.md +245 -52
  4. data/docs/development.md +102 -14
  5. data/docs/grpc-web.md +30 -13
  6. data/docs/grpc.md +98 -5
  7. data/docs/rbs.md +56 -19
  8. data/docs/streaming.md +80 -34
  9. data/docs/unary.md +269 -45
  10. data/lib/connectrpc/bindings/google_protobuf.rb +20 -7
  11. data/lib/connectrpc/client.rb +47 -22
  12. data/lib/connectrpc/deadline.rb +27 -6
  13. data/lib/connectrpc/error.rb +2 -2
  14. data/lib/connectrpc/generator/names.rb +17 -0
  15. data/lib/connectrpc/generator/rbs_renderer.rb +4 -3
  16. data/lib/connectrpc/generator/renderer.rb +35 -3
  17. data/lib/connectrpc/generator/runtime_names.rb +23 -5
  18. data/lib/connectrpc/generator/schema.rb +14 -7
  19. data/lib/connectrpc/grpc.rb +7 -4
  20. data/lib/connectrpc/grpc_client.rb +2 -2
  21. data/lib/connectrpc/grpc_server.rb +14 -14
  22. data/lib/connectrpc/grpc_web_cors.rb +12 -4
  23. data/lib/connectrpc/grpc_web_server.rb +19 -13
  24. data/lib/connectrpc/instrumentation.rb +47 -7
  25. data/lib/connectrpc/keepalive.rb +40 -0
  26. data/lib/connectrpc/method.rb +8 -8
  27. data/lib/connectrpc/metrics/connection_observer.rb +46 -17
  28. data/lib/connectrpc/metrics/definitions.rb +6 -2
  29. data/lib/connectrpc/protocol.rb +64 -11
  30. data/lib/connectrpc/proxy.rb +425 -0
  31. data/lib/connectrpc/server.rb +97 -13
  32. data/lib/connectrpc/streaming/client.rb +22 -25
  33. data/lib/connectrpc/streaming/client_execution.rb +2 -1
  34. data/lib/connectrpc/streaming/client_scope.rb +14 -7
  35. data/lib/connectrpc/streaming/server.rb +1 -0
  36. data/lib/connectrpc/streaming/server_terminal.rb +57 -14
  37. data/lib/connectrpc/streaming/session_messages.rb +12 -5
  38. data/lib/connectrpc/streaming/streams.rb +17 -6
  39. data/lib/connectrpc/streaming/terminal.rb +3 -5
  40. data/lib/connectrpc/transports/net_http.rb +512 -52
  41. data/lib/connectrpc/version.rb +1 -1
  42. data/lib/connectrpc.rb +1 -0
  43. data/sig/connectrpc.rbs +63 -17
  44. metadata +6 -2
data/docs/streaming.md CHANGED
@@ -39,11 +39,21 @@ propagation exclude actual chunked trailers, including `connect-timeout-ms`.
39
39
  H1 peer EOF does not synthesize Context cancellation.
40
40
 
41
41
  When original framed input is incomplete at response-head resolution, Falcon
42
- disables reuse and delivers the complete response before best-effort input
43
- hygiene. Hygiene has one absolute 100 ms allowance and a 256 KiB entity-byte cap,
44
- including the adapter remainder. Every additional framed read reserves a full
45
- 64 KiB, so retirement can stop below the cap. Progress never restarts the timer;
46
- Connect does not use `grpc-timeout`.
42
+ disables reuse and, since 0.3.0, reads the unread body before it writes the
43
+ response head, as Go's `net/http` server does (`maxPostHandlerReadBytes`). It
44
+ reads at most 256 KiB, though the last chunked read can pass that by less than
45
+ 64 KiB, and leaves a declared remainder of 256 KiB or more unread.
46
+ `request_body_timeout` bounds each read wait and the Connect deadline bounds the
47
+ whole read; progress never extends the deadline, and `grpc-timeout` does not
48
+ apply. A stalled, expired or malformed remainder still receives the response.
49
+ Only the connection task reads, once the original processor has stopped reading
50
+ input: it has finished, or it has produced response output, which core does
51
+ only after a handler's last input read. During the read a separate task drains
52
+ that output into memory, so processing never blocks on it; the drain never
53
+ waits for processing completion or lifecycle observers. A head published before
54
+ any output, such as headers sent during CS input reads, is written at once, and
55
+ the remainder is read before the first output chunk. A bidi 505 and an
56
+ unanswered `Expect: 100-continue` request skip the read.
47
57
 
48
58
  A successfully delivered response on a retiring connection uses one absolute
49
59
  final-close expiry at the actual final HTTP flush plus 500 ms. On a successful
@@ -55,12 +65,10 @@ observation. A response without a body anchors when the writer returns. Payload
55
65
  bytes cannot trigger it. Cancellation can also close the body without an error, but
56
66
  the response is then undelivered and ignores the expiry. Delayed callbacks
57
67
  consume the same total budget. After completed delivery, Falcon half-closes raw
58
- TCP writes and performs bounded discard. When discard stops,
59
- Falcon waits only the remaining part of that original 500 ms budget, without
60
- reading more. It does not add another 500 ms after discard. Earlier owner
61
- abort/shutdown can shorten either phase. Failed or incomplete delivery gets no
62
- success grace. Late hygiene/grace failures preserve completed processing and
63
- delivery facts.
68
+ TCP writes and waits for the rest of that budget without reading, like
69
+ `net/http`'s `rstAvoidanceDelay`. Earlier owner abort/shutdown can shorten
70
+ either phase. Failed or incomplete delivery gets no success grace. Late
71
+ hygiene/grace failures preserve completed processing and delivery facts.
64
72
 
65
73
  Admission and socket ownership remain held until retirement and original
66
74
  processing join. Retirement never parses or dispatches a pipelined request,
@@ -68,19 +76,21 @@ even if the original request finishes. Fully consumed nonretiring input retains
68
76
  persistence. Raw socket abort precedes framed/Finishable close on forced teardown.
69
77
  Both timers are cooperative and can overshoot under scheduler delay. Remaining
70
78
  grace retains resources and is best effort reset avoidance, not a guarantee of
71
- response delivery under arbitrary network or peer failure.
72
-
73
- The production official H1 profiles pass 174/174 identity and 160/160 gzip cases
74
- on both pinned Rubies, including the original oversized CS cases over TCP/TLS.
75
- No official assertion or inventory changed. This is a bounded, response-first variant of
76
- Go's conditional reset avoidance: connect-go may consume the full oversized
77
- declared message, and net/http may drain before flushing or reuse a connection.
78
- Literal Go parity is not claimed. Native H1 Web retains its separate policy:
79
- original input cleanup gates the staged Web terminal, and an incomplete upload
80
- also gates a rejection head to avoid stopping the client's upload. This Web-only
81
- gate never delays Connect response delivery. The historical Web TCP/TLS failures,
82
- diagnosis and separate baseline repair are recorded in the
83
- [conformance status](../conformance/README.md#connect-http11-server-profiles).
79
+ response delivery under arbitrary network or peer failure. The
80
+ [support contract](support.md#falcon-connect-h1-retirement) promises this
81
+ behavior and treats its budgets as provisional tuning values.
82
+
83
+ CI requires the production official H1 profiles to pass all 174 identity and 160
84
+ gzip cases on both pinned Rubies, including the original oversized CS cases over
85
+ TCP/TLS.
86
+ No official assertion or inventory changed. Unlike `net/http`, Falcon never
87
+ reuses a connection after incomplete input, and it also reads when the client
88
+ sent `Connection: close`. Native H1 Web retains its separate policy: original
89
+ input cleanup gates the staged Web terminal, and an incomplete upload also gates
90
+ a rejection head to avoid stopping the client's upload, with its own 100 ms
91
+ allowance. The historical Web TCP/TLS failures, diagnosis and separate baseline
92
+ repair are recorded in the [conformance
93
+ status](../conformance/README.md#connect-http11-server-profiles).
84
94
 
85
95
  ## Completion policy
86
96
 
@@ -90,7 +100,10 @@ is a protocol error. A stalled tail is `unavailable`, including with `timeout: n
90
100
  A shorter real RPC deadline or explicit cancellation can win first. Otherwise
91
101
  valid responses with late EOF or slow intermediaries can be rejected. This is
92
102
  this library's interoperability policy, not a Connect requirement, RPC deadline,
93
- wire timeout header or general stream watchdog.
103
+ wire timeout header or general stream watchdog. The
104
+ [support contract](support.md#native-client-completion) classifies it as
105
+ provisional, and [#102](https://github.com/jimeh/connectrpc-ruby/issues/102)
106
+ evaluates relaxing it.
94
107
 
95
108
  An incidental send I/O failure permits terminal-only recovery of at most 262,144
96
109
  additional wire body bytes in one absolute 100 ms, including response headers,
@@ -100,7 +113,7 @@ steal a live reader or resume normal reading after discarding data. Only a valid
100
113
  remote error with verified HTTP tail can replace the generic write failure.
101
114
  Remote success cannot erase an unhandled send failure; an application may handle
102
115
  a send failure and complete its normal response path. Recovery and the existing
103
- 100 ms destructive cleanup stage are separate, up to 200 ms together. Native or
116
+ 1-second destructive cleanup allowance are separate allowances. Native or
104
117
  application code that blocks the reactor remains outside hard timing guarantees.
105
118
 
106
119
  ## Clients and declarations
@@ -129,9 +142,13 @@ end # => nil
129
142
  ```
130
143
 
131
144
  Generated mixed-service wrappers preserve these blocks, all options, actual nil
132
- timeouts and cancellation tokens. The same configured `Client(use_get: true)`
145
+ timeouts and cancellation tokens. Since 0.3.0, each operation also accepts
146
+ `deadline:`, and a stream uses the earlier of it and `timeout:`, as a
147
+ [unary call](unary.md#deadlines) does. A handler passes `deadline:
148
+ context.deadline` to bound a downstream stream by its own deadline. The same configured `Client(use_get: true)`
133
149
  uses GET for eligible unary calls and POST for streaming, without mode changes,
134
- retry, fallback or resend. Legacy `mode: :unary` remains accepted.
150
+ retry, fallback or resend. `mode:` defaults to `:unary`, its only accepted
151
+ value, so streaming needs no mode change.
135
152
 
136
153
  `send_message` returns nil after bounded local ownership transfer, not wire
137
154
  flush or peer receipt. Nil is forbidden as a streaming message. `receive` returns
@@ -162,11 +179,23 @@ violations are `unimplemented`. `context.request_metadata` stays mutable; reader
162
179
  and duplex `headers` return a frozen snapshot taken at the first read, which
163
180
  later Context writes do not change.
164
181
 
182
+ Since 0.3.0, a generated service's `handlers_for(impl)` registers an object's
183
+ public methods with these same arguments, such as `def watch(request, writer,
184
+ context)`, beside unary methods. RPCs the object lacks are left out, so they
185
+ answer `unimplemented`:
186
+
187
+ ```ruby
188
+ server = ConnectRPC::Server.new(services: [service::SERVICE],
189
+ handlers: service.handlers_for(MixedService.new, strict: true))
190
+ ```
191
+
165
192
  `context.send_headers(metadata: {})`, also delegated by response writers and
166
193
  server duplexes, publishes once. It can precede a handler delay or CS input.
167
194
  First payload/terminal implicitly publishes. Leading metadata is deeply frozen
168
195
  at publication; trailers remain mutable until terminal serialization, then freeze.
169
- There is no synthetic nil message for publishing headers.
196
+ There is no synthetic nil message for publishing headers. Core invokes the host
197
+ publisher at most once per call. If publication fails, the call raises and the
198
+ host aborts the response; core never finishes a stream with a terminal but no head.
170
199
 
171
200
  The original processor task owns authenticated peer identity, cancellation and
172
201
  instrumentation through handlers, codecs and cleanup. A separate publication
@@ -309,6 +338,14 @@ including a failure after dispatch started but before the stream opened.
309
338
  `FrozenError`, so add headers before `yield` or from a wrapper before the
310
339
  first `send_message`. Trailers stay writable until the terminal, so trailers
311
340
  written after `yield`, including after a handler error, reach it.
341
+ - A handler error's `metadata` joins the head while the head is unpublished.
342
+ Once the head is published, the terminal carries it instead: Connect
343
+ end-stream metadata, or gRPC and gRPC-Web trailers. There it follows the
344
+ context trailers and precedes the error's own `trailers`, as in connect-go
345
+ 1.21.1. Each value appears in exactly one place. In the terminal it counts
346
+ toward the terminal byte limits, so large error metadata after the head is
347
+ published can turn the terminal into the bounded `resource_exhausted`
348
+ replacement.
312
349
  - Client server-streaming and bidi interceptors read response `headers` and
313
350
  `trailers` through the endpoint. A client-streaming interceptor reads them
314
351
  from the `Response` that `yield` returns.
@@ -334,8 +371,10 @@ including a failure after dispatch started but before the stream opened.
334
371
  Each direction retains at most one queued 16,384-byte output fragment and one
335
372
  writer-owned in-flight fragment. One current encoded and decoded message,
336
373
  5-byte prefix and at most one 16 KiB input remainder are separate allocations.
337
- Native ingress retains at most 65,536 bytes in at most five entries, with chunks
338
- at most 16,384 bytes. Stream credit follows consumption/discard; connection credit
374
+ Native ingress retains at most one stream receive window, with chunks at most
375
+ 16,384 bytes: by default 65,536 bytes in at most five entries on a server and
376
+ 4 MiB on an Async HTTP/2 client; see
377
+ [flow-control windows](../gems/connectrpc-async/README.md#flow-control-windows). Stream credit follows consumption/discard; connection credit
339
378
  allows healthy siblings/control traffic to advance. These are payload accounting
340
379
  bounds, not RSS, CPU, HPACK, socket/TLS, caller retention or native codec guarantees.
341
380
 
@@ -354,8 +393,15 @@ request framing/truncation/gzip is `invalid_argument`; malformed responses are
354
393
  `internal`. Bounds remain `resource_exhausted`. Per-message gzip state is independent.
355
394
 
356
395
  Bounded tolerant terminal input accepts `error: null`, and maps absent/null/unknown
357
- string codes to `unknown`, preserving valid message/details. Numeric codes,
358
- nonobjects, malformed details and metadata containers fail. Invalid individual
396
+ string codes to `unknown`, preserving valid message/details. Terminals and unary
397
+ error bodies share one normalization that follows connect-go 1.21.1: a null
398
+ message reads as empty, null details as none, an absent or null detail value as
399
+ empty bytes, and a detail type URL keeps the name after its last `/`. Numeric
400
+ codes, non-string messages, nonobjects, non-object details, invalid base64 and
401
+ metadata containers fail. Unlike connect-go, a detail type that is missing, null,
402
+ empty or not a valid protobuf name after that step also fails the whole error,
403
+ because `ErrorDetail` requires a valid type name. A failed terminal is
404
+ `internal`; a failed unary body uses the HTTP status fallback. Invalid individual
359
405
  metadata fields are omitted. Output always uses valid Connect terminal errors.
360
406
  A terminal is only a candidate until its HTTP tail and transport cleanup succeed.
361
407
 
@@ -403,7 +449,7 @@ error; the transport does not decode terminals or invent early success.
403
449
  Unhandled send failures still win over remote success under core's policy.
404
450
 
405
451
  The supplied completion timeout and original RPC deadline also cover cleanup;
406
- cleanup has at most its existing 100 ms allowance. Destructive retirement closes
452
+ cleanup has at most its existing 1-second allowance. Destructive retirement closes
407
453
  raw TCP before canceling/joining writers/readers and buffered/TLS cleanup. Abort
408
454
  after successful finish is harmless; abandonment otherwise retires the lease.
409
455
  TLS offers only `http/1.1` and accepts absent ALPN as legacy H1, with peer and