connectrpc 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/docs/design.md +20 -5
- data/docs/development.md +11 -8
- data/docs/grpc-web.md +10 -11
- data/docs/grpc.md +7 -2
- data/docs/streaming.md +293 -112
- data/lib/connectrpc/instrumentation.rb +32 -3
- data/lib/connectrpc/streaming/client_execution.rb +1 -2
- data/lib/connectrpc/streaming/session_io.rb +3 -0
- data/lib/connectrpc/streaming/session_messages.rb +52 -1
- data/lib/connectrpc/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0e6d441ea027e908d1e29338ea779a36496a8cdc40005f0dd540521ef189e2db
|
|
4
|
+
data.tar.gz: bc35641eac644f34517d582c9a83e0e227859ec4375367131b0cf0dc40859cde
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: dc7aabc26bd8d6a6bde1b269d4b8b508fe487efa79550dfbd555bd347d0b9857f0b11ca0e7d9debebafeec38e4fe971962365c564635598a3604ef0f26bc49c7
|
|
7
|
+
data.tar.gz: 54f3f001f2565007b305b3854a9bff0b3181f54b3414fc75da4810437ef75c820c6802f36bf1695cf08f78b2635350dde85170b1896fc5c4d0b269cea8402be5
|
data/docs/design.md
CHANGED
|
@@ -479,8 +479,9 @@ net/http does. Successfully delivered retiring responses half-close raw TCP
|
|
|
479
479
|
writes, then wait only the remaining total budget without further reads.
|
|
480
480
|
Admission/socket ownership joins original processing and
|
|
481
481
|
retirement; owner shutdown can shorten either phase. These cooperative timers
|
|
482
|
-
can overshoot under scheduler delay and do not guarantee peer receipt.
|
|
483
|
-
|
|
482
|
+
can overshoot under scheduler delay and do not guarantee peer receipt. Rejected
|
|
483
|
+
Web input and early unary responses use the same read, but keep a connection
|
|
484
|
+
whose read reaches EOF, as `net/http` does. Only explicit Rack fallback
|
|
484
485
|
receives Falcon's generic encoding/cache middleware. Native Connect streaming hosts
|
|
485
486
|
select explicit core shape capabilities. See the package guide for source failure, expiry, worker
|
|
486
487
|
stop and unsupported socket-ownership transfer policies.
|
|
@@ -604,8 +605,19 @@ ends and leaves the remaining connections to `Close`.
|
|
|
604
605
|
retirement. Whether a drain succeeded should depend on whether its streams
|
|
605
606
|
finished in time, not on how the peer left afterwards.
|
|
606
607
|
|
|
607
|
-
Rule 3
|
|
608
|
-
|
|
608
|
+
Rule 3 sets the private completion join's boundary. Async resolves a
|
|
609
|
+
cancelled task's promise, which wakes `Task#wait`, before it stops that task's
|
|
610
|
+
children and clears its fiber, and `Task#finished?` then turns true with no
|
|
611
|
+
signal to wait on. A wait on one subtree is not enough either: client frame
|
|
612
|
+
writers and outputs run under caller tasks, the connection reader is transient,
|
|
613
|
+
and `wait_all` takes a snapshot, so it misses a task created while the subtree
|
|
614
|
+
unwinds. The join instead walks the task, its non-transient descendants and
|
|
615
|
+
every task it has already seen until each has settled, meaning its block,
|
|
616
|
+
`ensure` included, has returned. Only Async's own bookkeeping remains after
|
|
617
|
+
that: `stop_children` raising into children the walk still joins, then
|
|
618
|
+
`finish!`. That runs no application code and touches no descriptor, so the
|
|
619
|
+
descriptor can close. Retirement loops test the same settled state, since a
|
|
620
|
+
loop that waited for `finished?` could spin without yielding.
|
|
609
621
|
|
|
610
622
|
## RPC lifecycle observation
|
|
611
623
|
|
|
@@ -785,7 +797,10 @@ same operation after a wake without a pending interrupt, so `Thread#raise`,
|
|
|
785
797
|
repeating a side effect. Rust never calls Ruby from a worker thread. A
|
|
786
798
|
process-wide tokio runtime with two workers is created lazily and checked
|
|
787
799
|
against the owning PID, so a forked child builds its own runtime and
|
|
788
|
-
connections and closes the inherited connection sockets it can identify.
|
|
800
|
+
connections and closes the inherited connection sockets it can identify. The
|
|
801
|
+
first use waits for the runtime's start, holding the GVL, for at most 5 s per
|
|
802
|
+
attempt; a start that fails or takes longer raises, and a later use retries or
|
|
803
|
+
uses the runtime of a start that finished late.
|
|
789
804
|
|
|
790
805
|
One admitting HTTP/2 connection per origin is shared by every thread; GOAWAY
|
|
791
806
|
retires it while a new connection admits, and reconnection is lazy, without
|
data/docs/development.md
CHANGED
|
@@ -56,6 +56,8 @@ Mise owns setup ordering and verification composition.
|
|
|
56
56
|
| `mise run test -- spec/connectrpc_spec.rb` | Run focused RSpec examples; accepts `file:line` and RSpec options. |
|
|
57
57
|
| `mise run test` | Run all specs and generate coverage. |
|
|
58
58
|
| `mise run lint:workflows` | Run actionlint and offline zizmor. |
|
|
59
|
+
| `mise run ci:scope -- BASE HEAD` | Print the CI jobs and lowest-allowed leaves a commit range selects, with each file's class; see [scoped jobs](ci.md#scoped-jobs). In CI it reads the event range instead. |
|
|
60
|
+
| `mise run ci:result` | CI only: decide the aggregate `CI result` check from `NEEDS` and the run's job list. |
|
|
59
61
|
| `mise run check:static` | Run format, lint, and workflow checks once. |
|
|
60
62
|
| `mise run check` | Run static checks and Ruby syntax checks. |
|
|
61
63
|
| `mise run build` | Build `pkg/connectrpc-<version>.gem`. |
|
|
@@ -87,7 +89,9 @@ for final handoff; moved middleware specs have their own canonical gate.
|
|
|
87
89
|
canonical component tasks into nine core, three Rails, four optional HTTP/2,
|
|
88
90
|
two optional Rack, two optional testing, two optional RBS and four optional Falcon
|
|
89
91
|
checks, plus the optional OTel, metrics, health, Sentry and hyper leaves, with syntax, specs, package isolation,
|
|
90
|
-
interop and official conformance on both Rubies.
|
|
92
|
+
interop and official conformance on both Rubies. A `CI scope` job runs only the
|
|
93
|
+
checks a change can affect, and the single `CI result` check fails unless every
|
|
94
|
+
selected check passed. Hosted clean-environment and
|
|
91
95
|
matrix results remain CI evidence; a local pass cannot establish them.
|
|
92
96
|
|
|
93
97
|
Markdown is maintained manually: check relative links, commands, and fenced
|
|
@@ -295,8 +299,8 @@ into one of three tiers, and internal gems follow the train:
|
|
|
295
299
|
|
|
296
300
|
1. **Floor and cap.** For dependencies whose public API is all we use, the
|
|
297
301
|
floor is the release the project currently tests, for example
|
|
298
|
-
`rack >= 3.2.7
|
|
299
|
-
1, and 1.x+ gems below their next major.
|
|
302
|
+
`rack >= 3.2.7`, `falcon >= 0.57.0` or `async >= 2.46.0`. Pre-1.0
|
|
303
|
+
dependencies are capped below 1, and 1.x+ gems below their next major.
|
|
300
304
|
2. **Guarded coupling.** A dependency whose internals we rely on may take a
|
|
301
305
|
floor-and-cap range only when all of the following hold:
|
|
302
306
|
- `require` detects the coupling at boot. A contract check runs before any
|
|
@@ -309,11 +313,8 @@ into one of three tiers, and internal gems follow the train:
|
|
|
309
313
|
Coupling does not qualify when a boot check cannot observe it: ordering
|
|
310
314
|
under concurrency, flow-control accounting or eager-start races. Neither do
|
|
311
315
|
replaced methods whose failure mode is a hang or silent misbehavior under
|
|
312
|
-
load, nor anything checked only by its shape.
|
|
313
|
-
|
|
314
|
-
`ConnectRPC::Async::Internal::UpstreamContract` finalization probe proves at
|
|
315
|
-
require that Async still calls the per-instance `#consume` the completion
|
|
316
|
-
joins depend on.
|
|
316
|
+
load, nor anything checked only by its shape. No dependency is in this tier
|
|
317
|
+
today; the criteria stand for future use.
|
|
317
318
|
3. **Patch-pinned.** Everything else coupled to private internals keeps a
|
|
318
319
|
patch-only `~> x.y.z` requirement, named with its reason in the gemspec
|
|
319
320
|
comment:
|
|
@@ -760,6 +761,8 @@ including `extconf.rb`, cross builds and the source gem's install. Update it
|
|
|
760
761
|
only with `hyper:cargo:update`, and check that each new crate release is at
|
|
761
762
|
least seven days old, as for tools; the daily
|
|
762
763
|
[canary](ci.md#pins-lifted-canary) shows whether the newest crates still pass.
|
|
764
|
+
A hyper or h2 update also rereads the internals that D16 in the
|
|
765
|
+
[hyper plan](plans/hyper.md) lists, as no spec guards all of them.
|
|
763
766
|
`deny.toml` limits licenses and sources. `THIRD_PARTY_NOTICES.md` lists every
|
|
764
767
|
crate linked on any target with its license texts and ships in the gem; a
|
|
765
768
|
stale file fails `hyper:check` and `hyper:package`.
|
data/docs/grpc-web.md
CHANGED
|
@@ -172,17 +172,16 @@ discards the candidate terminal and aborts delivery. Admission includes original
|
|
|
172
172
|
processing and wire/callback completion. H1 has explicit resources, not fake H2
|
|
173
173
|
streams. Only an actual H2 CANCEL reset signals Context cancellation. H1 EOF,
|
|
174
174
|
disconnect and host shutdown do not. There is no Connect one-second tail policy.
|
|
175
|
-
Falcon native H1
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
and owner abort. Each
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
[
|
|
185
|
-
[Falcon guide](../gems/connectrpc-falcon/README.md#grpc-web).
|
|
175
|
+
Since 0.3.1, Falcon native H1 reads rejected input as it reads unread Connect
|
|
176
|
+
H1 input: up to 256 KiB before the rejection head, with `request_body_timeout`
|
|
177
|
+
bounding each read wait and the original valid grpc-timeout the whole read,
|
|
178
|
+
subject to earlier cancellation, drain and owner abort. Each read is at most
|
|
179
|
+
64 KiB and a following request is never consumed. A read that reaches EOF keeps
|
|
180
|
+
the connection. A remainder above the limit, or a stalled, expired or malformed
|
|
181
|
+
one, still receives the rejection with `Connection: close`, and the connection
|
|
182
|
+
closes after the reply. The read limit and close delay are provisional budgets
|
|
183
|
+
in the [support contract](support.md#falcon-connect-h1-retirement). See the
|
|
184
|
+
[Falcon guide](../gems/connectrpc-falcon/README.md#rejected-http1-web-input).
|
|
186
185
|
|
|
187
186
|
`Server#cors_response(path:, http_method:, headers:, response: nil)` is a pure
|
|
188
187
|
typed host SPI for early decisions and idempotent decoration, including admission
|
data/docs/grpc.md
CHANGED
|
@@ -163,8 +163,13 @@ nil waits retain their existing behavior. There is no one-second gRPC tail timer
|
|
|
163
163
|
Send-I/O terminal recovery has one absolute 100ms budget and allows at most
|
|
164
164
|
262,144 additional body bytes, with separate finite header limits. It skips
|
|
165
165
|
messages without decoding or inflating them and cannot take over an active
|
|
166
|
-
reader. Only a validated remote error can replace an unhandled send failure
|
|
167
|
-
|
|
166
|
+
reader. Only a validated remote error can replace an unhandled send failure of
|
|
167
|
+
a client-streaming or bidi call; remote success cannot. A unary or
|
|
168
|
+
server-streaming call, whose one request core sends itself, instead reads the
|
|
169
|
+
response after a send failure and reports its outcome, OK included, as grpc-go's
|
|
170
|
+
`clientStreamWrapper.SendMsg` and connect-go's `callUnary` do (see the
|
|
171
|
+
[completion policy](streaming.md#completion-policy)). The existing destructive
|
|
172
|
+
cleanup has a separate 1-second
|
|
168
173
|
[allowance](../gems/connectrpc-async/README.md#cleanup-allowance). A stuck frame
|
|
169
174
|
can fail its connection and siblings during that cleanup.
|
|
170
175
|
|
data/docs/streaming.md
CHANGED
|
@@ -3,118 +3,141 @@
|
|
|
3
3
|
The [supported 0.x contract](support.md) defines the target compatibility
|
|
4
4
|
boundary and the remaining adoption gates.
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
same dependency-free core engine. The optional Async transport and Async/Falcon
|
|
8
|
-
native HTTP/2 hosts support protobuf and ProtoJSON, identity/gzip, h2c, verified
|
|
9
|
-
TLS and mTLS. Falcon also serves Connect server and client streaming over
|
|
10
|
-
HTTP/1.1 with both codecs and identity/gzip over TCP/TLS/mTLS. The explicit
|
|
11
|
-
`ConnectRPC::Async::HTTP1Transport` provides unary, SS and CS on the owning
|
|
12
|
-
reactor. The standalone Async Host and original Async Transport remain H2-only. NetHTTP, Rack, Rails and Testing remain unary.
|
|
13
|
-
Unsupported clients reject a streaming operation before encoding or I/O. Native
|
|
14
|
-
listeners explicitly select their actual protocol capabilities. Portable adapters reject streaming
|
|
15
|
-
media before reading input or invoking handlers, including Rails callbacks.
|
|
6
|
+
## Quick start
|
|
16
7
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
HEADERS, status codec and independent bounds are described in [gRPC](grpc.md).
|
|
20
|
-
The Connect terminal envelope and one-second tail policy below apply to Connect.
|
|
8
|
+
This program serves the demo schema's server-streaming `Countdown` RPC on a
|
|
9
|
+
local HTTP/2 port, calls it and prints each message:
|
|
21
10
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
The original processor retains handlers, codecs, authenticated peer identity,
|
|
35
|
-
trace activation and application cleanup. Response consumers transmit prepared
|
|
36
|
-
bytes. Headers can publish during input reads, but successful HTTP terminal
|
|
37
|
-
chunk delivery waits for original application cleanup. Leading metadata and
|
|
38
|
-
propagation exclude actual chunked trailers, including `connect-timeout-ms`.
|
|
39
|
-
H1 peer EOF does not synthesize Context cancellation.
|
|
11
|
+
```ruby
|
|
12
|
+
require "async"
|
|
13
|
+
require "connectrpc/async"
|
|
14
|
+
require "demo/v1/demo_connect" # Generated from examples/proto/demo/v1/demo.proto.
|
|
15
|
+
|
|
16
|
+
class Countdown
|
|
17
|
+
# Server streaming: one request in, any number of messages out.
|
|
18
|
+
def countdown(request, writer, _context)
|
|
19
|
+
request.from.downto(1) { |number| writer.send_message(Demo::V1::CountdownResponse.new(number: number)) }
|
|
20
|
+
end
|
|
21
|
+
end
|
|
40
22
|
|
|
41
|
-
|
|
42
|
-
|
|
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.
|
|
23
|
+
server = ConnectRPC::Server.new(services: [Demo::V1::DemoService::SERVICE],
|
|
24
|
+
handlers: Demo::V1::DemoService.handlers_for(Countdown.new))
|
|
57
25
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
after EOF or a HEAD response, before the body's close callbacks or lifecycle
|
|
64
|
-
observation. A response without a body anchors when the writer returns. Payload
|
|
65
|
-
bytes cannot trigger it. Cancellation can also close the body without an error, but
|
|
66
|
-
the response is then undelivered and ignores the expiry. Delayed callbacks
|
|
67
|
-
consume the same total budget. After completed delivery, Falcon half-closes raw
|
|
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.
|
|
26
|
+
Sync do
|
|
27
|
+
host = ConnectRPC::Async::Host.new(server: server).start # h2c on an ephemeral localhost port.
|
|
28
|
+
origin = "http://127.0.0.1:#{host.port}"
|
|
29
|
+
transport = ConnectRPC::Async::Transport.new(origin: origin)
|
|
30
|
+
client = Demo::V1::DemoService::Client.new(client: ConnectRPC::Client.new(base_url: origin, transport: transport))
|
|
72
31
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
behavior and treats its budgets as provisional tuning values.
|
|
32
|
+
client.countdown(Demo::V1::CountdownRequest.new(from: 3)) do |reader|
|
|
33
|
+
reader.each { |message| puts message.number } # Prints 3, 2, 1.
|
|
34
|
+
end
|
|
35
|
+
ensure
|
|
36
|
+
transport&.close
|
|
37
|
+
host&.close
|
|
38
|
+
end
|
|
39
|
+
```
|
|
82
40
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
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).
|
|
41
|
+
It uses the repository's [demo schema](../examples/proto/demo/v1/demo.proto),
|
|
42
|
+
whose generated Ruby lives in `examples/gen`. From a repository checkout with
|
|
43
|
+
`connectrpc-async` and `google-protobuf` installed, save it as `quickstart.rb`
|
|
44
|
+
and run `ruby -I examples/gen quickstart.rb`. Code generated for your own
|
|
45
|
+
service has the same shape; see
|
|
46
|
+
[Generate services from protobuf](unary.md#generate-services-from-protobuf).
|
|
47
|
+
Native streaming needs a native host and client, here the `Host` and
|
|
48
|
+
`Transport` of [connectrpc-async](../gems/connectrpc-async/README.md).
|
|
94
49
|
|
|
95
|
-
|
|
50
|
+
The [runnable examples](../examples/README.md) run a streaming server and
|
|
51
|
+
client in two terminals. After `mise run async:setup`:
|
|
96
52
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
A shorter real RPC deadline or explicit cancellation can win first. Otherwise
|
|
101
|
-
valid responses with late EOF or slow intermediaries can be rejected. This is
|
|
102
|
-
this library's interoperability policy, not a Connect requirement, RPC deadline,
|
|
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.
|
|
53
|
+
```sh
|
|
54
|
+
# Terminal 1
|
|
55
|
+
mise run example:server -- async
|
|
107
56
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
57
|
+
# Terminal 2
|
|
58
|
+
mise run example:client -- async-h2 countdown 3
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Stream kinds
|
|
62
|
+
|
|
63
|
+
Each streaming kind has its own handler signature and generated client call.
|
|
64
|
+
This object implements the demo schema's three streaming RPCs, and the client
|
|
65
|
+
calls below use them. To run it, replace the quick start's `Countdown` class
|
|
66
|
+
and `server` with the first part, and its `client.countdown` call inside the
|
|
67
|
+
`Sync` block with the client calls:
|
|
68
|
+
|
|
69
|
+
```ruby
|
|
70
|
+
class DemoStreams
|
|
71
|
+
# Server streaming: one request in, any number of messages out. The return value is ignored.
|
|
72
|
+
def countdown(request, writer, _context)
|
|
73
|
+
request.from.downto(1) { |number| writer.send_message(Demo::V1::CountdownResponse.new(number: number)) }
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
# Client streaming: read every message, then return exactly one response.
|
|
77
|
+
def collect(reader, _context)
|
|
78
|
+
names = []
|
|
79
|
+
reader.each { |message| names << message.name }
|
|
80
|
+
Demo::V1::CollectResponse.new(summary: "Collected #{names.join(', ')}")
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
# Bidirectional streaming: receive and send on one duplex. The return value is ignored.
|
|
84
|
+
def chat(duplex, _context)
|
|
85
|
+
duplex.each { |message| duplex.send_message(Demo::V1::ChatResponse.new(text: "Hello, #{message.text}!")) }
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
server = ConnectRPC::Server.new(services: [Demo::V1::DemoService::SERVICE],
|
|
90
|
+
handlers: Demo::V1::DemoService.handlers_for(DemoStreams.new))
|
|
91
|
+
|
|
92
|
+
# The generated client calls, with `client` built as in the quick start:
|
|
93
|
+
client.countdown(Demo::V1::CountdownRequest.new(from: 2)) do |reader|
|
|
94
|
+
reader.each { |message| puts message.number } # Prints 2, 1.
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
response = client.collect do |writer|
|
|
98
|
+
%w[Ada Grace].each { |name| writer.send_message(Demo::V1::CollectRequest.new(name: name)) }
|
|
99
|
+
end
|
|
100
|
+
puts response.message.summary # Collected Ada, Grace
|
|
101
|
+
|
|
102
|
+
client.chat do |duplex|
|
|
103
|
+
duplex.send_message(Demo::V1::ChatRequest.new(text: "Ada"))
|
|
104
|
+
puts duplex.receive.text # Hello, Ada!
|
|
105
|
+
duplex.close_send
|
|
106
|
+
duplex.each { |message| puts message.text } # Reads any remaining replies until the stream ends.
|
|
107
|
+
end
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
[Clients and declarations](#clients-and-declarations) and
|
|
111
|
+
[Handlers and publication](#handlers-and-publication) give the full rules.
|
|
112
|
+
|
|
113
|
+
## Hosts and clients
|
|
114
|
+
|
|
115
|
+
Connect server streaming, client streaming and bidirectional (bidi) streaming
|
|
116
|
+
all use the same core engine, which has no dependencies. Which stream kinds you
|
|
117
|
+
can use depends on the host or client:
|
|
118
|
+
|
|
119
|
+
- Over HTTP/2, the optional `ConnectRPC::Async::Transport` client and the
|
|
120
|
+
native HTTP/2 hosts of Async and Falcon support all three kinds. They
|
|
121
|
+
support protobuf and ProtoJSON, identity and gzip encoding, h2c (HTTP/2
|
|
122
|
+
without TLS), verified TLS and mTLS.
|
|
123
|
+
- Over HTTP/1.1, Falcon also serves Connect server streaming and client
|
|
124
|
+
streaming, with both codecs and identity or gzip encoding, over TCP, TLS and
|
|
125
|
+
mTLS.
|
|
126
|
+
- The explicit `ConnectRPC::Async::HTTP1Transport` client provides unary
|
|
127
|
+
calls, server streaming and client streaming on the reactor that owns it.
|
|
128
|
+
- The standalone Async Host and the original Async Transport remain HTTP/2
|
|
129
|
+
only.
|
|
130
|
+
- NetHTTP, Rack, Rails and Testing remain unary only.
|
|
131
|
+
|
|
132
|
+
A client that does not support a streaming operation rejects it before any
|
|
133
|
+
encoding or I/O. Native listeners explicitly select the protocol capabilities
|
|
134
|
+
they actually support. Portable adapters reject requests with a streaming media
|
|
135
|
+
type before they read input or invoke handlers, including Rails callbacks.
|
|
136
|
+
|
|
137
|
+
Native gRPC reuses the declarations and session engine below, including unary
|
|
138
|
+
calls through the exchange SPI. Its protobuf-only negotiation, final HTTP/2
|
|
139
|
+
HEADERS, status codec and independent bounds are described in [gRPC](grpc.md).
|
|
140
|
+
The Connect terminal envelope and one-second tail policy below apply to Connect.
|
|
118
141
|
|
|
119
142
|
## Clients and declarations
|
|
120
143
|
|
|
@@ -197,12 +220,7 @@ There is no synthetic nil message for publishing headers. Core invokes the host
|
|
|
197
220
|
publisher at most once per call. If publication fails, the call raises and the
|
|
198
221
|
host aborts the response; core never finishes a stream with a terminal but no head.
|
|
199
222
|
|
|
200
|
-
|
|
201
|
-
instrumentation through handlers, codecs and cleanup. A separate publication
|
|
202
|
-
promise exposes response headers while processing continues. Body tasks consume
|
|
203
|
-
prepared bytes. Successful HTTP EOF waits for original processor completion;
|
|
204
|
-
late cleanup failure aborts/reset. Admission and graceful drain include processing,
|
|
205
|
-
wire tail and cleanup. Only actual peer RST_STREAM(CANCEL) signals explicit server
|
|
223
|
+
Only actual peer RST_STREAM(CANCEL) signals explicit server
|
|
206
224
|
Context cancellation. EOF, half-close, other reset codes and host shutdown do not.
|
|
207
225
|
A long-lived handler that blocks on application state can register
|
|
208
226
|
`context.on_cancel { ... }` to wake itself on that signal; the
|
|
@@ -366,6 +384,56 @@ including a failure after dispatch started but before the stream opened.
|
|
|
366
384
|
interceptor; one that blocks should observe cancellation itself, and its
|
|
367
385
|
frame lasts as long as a long-lived stream such as a health Watch.
|
|
368
386
|
|
|
387
|
+
## Completion policy
|
|
388
|
+
|
|
389
|
+
After a terminal envelope, the client requires HTTP EOF and transport completion
|
|
390
|
+
within one **absolute second**, with at most one extra byte read. Any extra byte
|
|
391
|
+
is a protocol error. A stalled tail is `unavailable`, including with `timeout: nil`.
|
|
392
|
+
A shorter real RPC deadline or explicit cancellation can win first. Otherwise
|
|
393
|
+
valid responses with late EOF or slow intermediaries can be rejected. This is
|
|
394
|
+
this library's interoperability policy, not a Connect requirement, RPC deadline,
|
|
395
|
+
wire timeout header or general stream watchdog. The
|
|
396
|
+
[support contract](support.md#native-client-completion) classifies it as
|
|
397
|
+
provisional, and [#102](https://github.com/jimeh/connectrpc-ruby/issues/102)
|
|
398
|
+
evaluates relaxing it.
|
|
399
|
+
|
|
400
|
+
An incidental send I/O failure permits terminal-only recovery of at most 262,144
|
|
401
|
+
additional wire body bytes in one absolute 100 ms, including response headers,
|
|
402
|
+
buffered remainders, prefixes, skipped data, terminal tail and transport finish.
|
|
403
|
+
Recovery skips data incrementally without decoding or inflating it. It cannot
|
|
404
|
+
steal a live reader or resume normal reading after discarding data. Only a valid
|
|
405
|
+
remote error with verified HTTP tail can replace the generic write failure.
|
|
406
|
+
Remote success cannot erase an unhandled send failure; an application may handle
|
|
407
|
+
a send failure and complete its normal response path. Recovery and the existing
|
|
408
|
+
1-second destructive cleanup allowance are separate allowances. Native or
|
|
409
|
+
application code that blocks the reactor remains outside hard timing guarantees.
|
|
410
|
+
|
|
411
|
+
That recovery applies to client-streaming and bidi calls, whose application
|
|
412
|
+
sends the requests. Core itself sends the one request of a server-streaming call
|
|
413
|
+
and of a gRPC unary call. Since 0.3.1 a send failure there does not end the
|
|
414
|
+
call: core closes its side and reads the response normally, under the normal
|
|
415
|
+
message limits, terminal and tail checks and the call deadline, so the response
|
|
416
|
+
decides. This is not the 100 ms recovery above. An OK response returns its
|
|
417
|
+
messages, a remote error raises, and a response that never completes raises the
|
|
418
|
+
read's own failure. A server that never answers therefore fails the call with
|
|
419
|
+
`deadline_exceeded` when its deadline expires, not with `unavailable` within
|
|
420
|
+
100 ms, and a call without a deadline waits as long as any response read does.
|
|
421
|
+
grpc-go 1.85.0 (`clientStreamWrapper.SendMsg` in `stream.go`) and connect-go
|
|
422
|
+
1.21.1 (`callUnary` and `CallServerStream` in `client.go`) also let the
|
|
423
|
+
response decide for these calls. Only a send failure is forgiven: an encoding
|
|
424
|
+
or message-size failure, a nil request, cancellation and the deadline still end
|
|
425
|
+
the call. If closing the send side then raises the write's failure again, or
|
|
426
|
+
an I/O error or `unavailable` caused by it, core forgives that too; any other
|
|
427
|
+
close failure ends the call, since the half-close may not have reached the
|
|
428
|
+
server. Instrumentation outcomes leave out the forgiven failures and their
|
|
429
|
+
causes, so when the response decides, observers classify the call by it; a
|
|
430
|
+
close failure that ends the call is reported as such. That includes the raw
|
|
431
|
+
transport failure behind a write error when the transport makes it the error's
|
|
432
|
+
cause, as connectrpc-hyper and connectrpc-async do, even if the transport
|
|
433
|
+
recorded it before core's write. A failure recorded independently, such as one
|
|
434
|
+
from another fiber during the send, still counts, unless the transport raised
|
|
435
|
+
the write error while handling it, which makes it the error's implicit cause.
|
|
436
|
+
|
|
369
437
|
## Bounds and protocol
|
|
370
438
|
|
|
371
439
|
Each direction retains at most one queued 16,384-byte output fragment and one
|
|
@@ -441,12 +509,14 @@ without a deadline can still block if a peer neither consumes nor closes.
|
|
|
441
509
|
|
|
442
510
|
Writer success, full native HTTP EOF and owned cleanup all precede successful
|
|
443
511
|
`finish`. `close_send` is idempotent and never reports writer failure. A writer
|
|
444
|
-
failure surfaced through `write`
|
|
445
|
-
|
|
512
|
+
failure surfaced through `write` always retires the connection. For a server
|
|
513
|
+
stream, core forgives it and the response decides, as for any request core
|
|
514
|
+
sends itself (see the [completion policy](#completion-policy)). For a client
|
|
515
|
+
stream, it permits core's bounded terminal-only remote error recovery, and an
|
|
516
|
+
unhandled send failure still wins over remote success. If failure first appears
|
|
446
517
|
after the last accepted write, `finish` returns unavailable even when the
|
|
447
518
|
terminal contains a remote error. This existing-SPI limit can mask that remote
|
|
448
519
|
error; the transport does not decode terminals or invent early success.
|
|
449
|
-
Unhandled send failures still win over remote success under core's policy.
|
|
450
520
|
|
|
451
521
|
The supplied completion timeout and original RPC deadline also cover cleanup;
|
|
452
522
|
cleanup has at most its existing 1-second allowance. Destructive retirement closes
|
|
@@ -457,3 +527,114 @@ hostname verification enabled. Unary close-delimited responses accept clean EOF;
|
|
|
457
527
|
without Content-Length, EOF cannot detect a semantically truncated payload that
|
|
458
528
|
is otherwise valid. Core still validates protobuf/JSON; unexpected TLS EOF
|
|
459
529
|
without close_notify remains a transport failure.
|
|
530
|
+
|
|
531
|
+
## Host behavior
|
|
532
|
+
|
|
533
|
+
This section describes how native hosts run streams. Most applications need
|
|
534
|
+
none of it.
|
|
535
|
+
|
|
536
|
+
### Native hosts
|
|
537
|
+
|
|
538
|
+
This applies to the native HTTP/2 hosts and to Falcon's HTTP/1.1 server; the
|
|
539
|
+
next section adds the HTTP/1.1 specifics. Each request has one original
|
|
540
|
+
processor task. It runs the handlers, codecs
|
|
541
|
+
and cleanup, and owns the authenticated peer identity, cancellation and
|
|
542
|
+
instrumentation for that whole time. A separate publication promise hands the
|
|
543
|
+
response headers to the host while processing continues. Separate body tasks
|
|
544
|
+
send the bytes that processing has already prepared.
|
|
545
|
+
|
|
546
|
+
A successful response reaches HTTP EOF, the end of its HTTP stream, only after
|
|
547
|
+
the original processor task has completed. If cleanup fails late, the host
|
|
548
|
+
aborts the response instead, which resets the stream on HTTP/2. Admission is the
|
|
549
|
+
slot the host reserves for each accepted request. A request holds its admission,
|
|
550
|
+
and a graceful drain waits for it, through processing, the wire tail (sending
|
|
551
|
+
the rest of the response on the wire) and cleanup.
|
|
552
|
+
|
|
553
|
+
### Falcon HTTP/1.1 server
|
|
554
|
+
|
|
555
|
+
A custom host opts in by calling `Server#call_stream(capabilities:
|
|
556
|
+
[:server_stream, :client_stream], ...)`, which lists the stream kinds (shapes)
|
|
557
|
+
it supports. With the default `capabilities: nil`, the server keeps the
|
|
558
|
+
portable behavior and rejects streaming requests. The legacy `http2: true`
|
|
559
|
+
option grants all three shapes. An explicit `capabilities:` value must be a
|
|
560
|
+
nonempty Array of supported shape symbols with no duplicates, and it cannot be
|
|
561
|
+
combined with `http2: true`.
|
|
562
|
+
|
|
563
|
+
If the list omits server or client streaming, a call of that kind returns a
|
|
564
|
+
bounded `unimplemented` error. If it omits bidi, a call to a known bidi method
|
|
565
|
+
returns a bare 505 response from the host-neutral core, before the server
|
|
566
|
+
reads input or selects a codec. Falcon turns every native HTTP/1.1 bidi 505
|
|
567
|
+
into a nonpersistent response, one that closes the connection, with exactly
|
|
568
|
+
one `Connection: close` header. gRPC-Web negotiation and CORS still take
|
|
569
|
+
precedence. Native gRPC remains HTTP/2 only, and Connect streaming over
|
|
570
|
+
HTTP/1.0 is rejected.
|
|
571
|
+
|
|
572
|
+
The original processor task keeps the handlers, codecs, authenticated peer
|
|
573
|
+
identity, trace activation and application cleanup. Separate response
|
|
574
|
+
consumers send the prepared bytes. The response headers can be published while
|
|
575
|
+
the handler is still reading input. A successful response's final HTTP chunk
|
|
576
|
+
(the terminal chunk), however, is delivered only after the original
|
|
577
|
+
application cleanup has finished. Leading metadata and propagation exclude
|
|
578
|
+
fields sent as actual chunked trailers, including `connect-timeout-ms`. When an
|
|
579
|
+
HTTP/1.1 peer closes its side of the connection (peer EOF), the server does not
|
|
580
|
+
turn that into Context cancellation.
|
|
581
|
+
|
|
582
|
+
When original framed input is incomplete at response-head resolution, Falcon
|
|
583
|
+
disables reuse and, since 0.3.0, reads the unread body before it writes the
|
|
584
|
+
response head, as Go's `net/http` server does (`maxPostHandlerReadBytes`). It
|
|
585
|
+
reads at most 256 KiB, though the last chunked read can pass that by less than
|
|
586
|
+
64 KiB, and leaves a declared remainder of 256 KiB or more unread.
|
|
587
|
+
`request_body_timeout` bounds each read wait and the Connect deadline bounds the
|
|
588
|
+
whole read; progress never extends the deadline, and `grpc-timeout` does not
|
|
589
|
+
apply. A stalled, expired or malformed remainder still receives the response.
|
|
590
|
+
Only the connection task reads, once the original processor has stopped reading
|
|
591
|
+
input: it has finished, or it has produced response output, which core does
|
|
592
|
+
only after a handler's last input read. During the read a separate task drains
|
|
593
|
+
that output into memory, so processing never blocks on it; the drain never
|
|
594
|
+
waits for processing completion or lifecycle observers. A head published before
|
|
595
|
+
any output, such as headers sent during CS input reads, is written at once, and
|
|
596
|
+
the remainder is read before the first output chunk. A bidi 505 and an
|
|
597
|
+
unanswered `Expect: 100-continue` request skip the read.
|
|
598
|
+
|
|
599
|
+
A successfully delivered response on a retiring connection uses one absolute
|
|
600
|
+
final-close expiry at the actual final HTTP flush plus 500 ms. On a successful
|
|
601
|
+
write, protocol-http1 closes the body only after its final flush (for HTTP/1.0
|
|
602
|
+
close-delimited bodies, also after the write half-close). A private body wrapper
|
|
603
|
+
therefore anchors the expiry when the writer closes the body without an error
|
|
604
|
+
after EOF or a HEAD response, before the body's close callbacks or lifecycle
|
|
605
|
+
observation. A response without a body anchors when the writer returns. Payload
|
|
606
|
+
bytes cannot trigger it. Cancellation can also close the body without an error, but
|
|
607
|
+
the response is then undelivered and ignores the expiry. Delayed callbacks
|
|
608
|
+
consume the same total budget. After completed delivery, Falcon half-closes raw
|
|
609
|
+
TCP writes and waits for the rest of that budget without reading, like
|
|
610
|
+
`net/http`'s `rstAvoidanceDelay`. Earlier owner abort/shutdown can shorten
|
|
611
|
+
either phase. Failed or incomplete delivery gets no success grace. Late
|
|
612
|
+
hygiene/grace failures preserve completed processing and delivery facts.
|
|
613
|
+
|
|
614
|
+
A retiring connection is one that Falcon will not reuse and closes after the
|
|
615
|
+
response. The request keeps its admission slot, and Falcon keeps ownership of
|
|
616
|
+
the socket, until retirement finishes and the original processing task has been
|
|
617
|
+
joined. A retiring connection never parses or dispatches a pipelined request (a
|
|
618
|
+
further request sent on the same connection), even if the original request
|
|
619
|
+
finishes. A connection that is not retiring and whose input was fully consumed
|
|
620
|
+
stays persistent, so it can serve another request. On forced teardown, Falcon
|
|
621
|
+
aborts the raw socket before it closes the framed request input and its
|
|
622
|
+
`Finishable` wrapper. Both timers are cooperative, so they can run past their
|
|
623
|
+
limit when the scheduler is delayed. The remaining grace period keeps the
|
|
624
|
+
connection's resources held. It is a best-effort way to avoid a connection
|
|
625
|
+
reset, not a guarantee of response delivery under arbitrary network or peer
|
|
626
|
+
failure. The [support contract](support.md#falcon-connect-h1-retirement)
|
|
627
|
+
promises this behavior and treats its budgets as provisional tuning values.
|
|
628
|
+
|
|
629
|
+
CI requires the production official H1 profiles to pass all 174 identity and 160
|
|
630
|
+
gzip cases on both pinned Rubies, including the original oversized CS cases over
|
|
631
|
+
TCP/TLS.
|
|
632
|
+
No official assertion or inventory changed. Unlike `net/http`, Falcon never
|
|
633
|
+
reuses a connection after incomplete streaming input, and it also reads when
|
|
634
|
+
the client sent `Connection: close`. In native H1 Web, original input cleanup
|
|
635
|
+
gates the staged Web terminal, and an incomplete upload also gates a rejection
|
|
636
|
+
head to avoid stopping the client's upload. Since 0.3.1 that cleanup, and an early
|
|
637
|
+
Connect unary response, read the remainder with the same limits and bounds.
|
|
638
|
+
The historical Web TCP/TLS failures, diagnosis and separate baseline repair are
|
|
639
|
+
recorded in the [conformance
|
|
640
|
+
status](../conformance/README.md#connect-http11-server-profiles).
|
|
@@ -113,6 +113,9 @@ module ConnectRPC
|
|
|
113
113
|
# thread or fiber at a time; moving a call to another thread needs an
|
|
114
114
|
# ordering hand-off such as a Queue or Mutex. The first finish wins.
|
|
115
115
|
class Handle # rubocop:disable Metrics/ClassLength
|
|
116
|
+
FAILURE_LIMIT = 8
|
|
117
|
+
private_constant :FAILURE_LIMIT
|
|
118
|
+
|
|
116
119
|
attr_reader :outcome
|
|
117
120
|
attr_accessor :request_bytes, :request_metadata, :code, :normalized_error
|
|
118
121
|
|
|
@@ -174,8 +177,23 @@ module ConnectRPC
|
|
|
174
177
|
|
|
175
178
|
def host_rejected? = !!@host_rejected
|
|
176
179
|
|
|
180
|
+
# The first recorded failure is the call's error.
|
|
177
181
|
def record_failure(error)
|
|
178
|
-
@
|
|
182
|
+
failures = @failures ||= [] #: Array[Exception]
|
|
183
|
+
return if failures.any? { |failure| failure.equal?(error) }
|
|
184
|
+
|
|
185
|
+
# Keep only the first failures, so a call that records failures
|
|
186
|
+
# repeatedly holds a bounded list and later ones displace none.
|
|
187
|
+
failures << error if failures.size < FAILURE_LIMIT
|
|
188
|
+
nil
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
# Internal. Drops the recorded failures a call forgave: the given errors
|
|
192
|
+
# and every exception in their cause chains. Other failures stay in
|
|
193
|
+
# order, and the first that remains is the call's error.
|
|
194
|
+
def forgive(*errors)
|
|
195
|
+
forgiven = errors.flat_map { |error| cause_chain(error) }
|
|
196
|
+
@failures&.reject! { |failure| forgiven.any? { |error| error.equal?(failure) } }
|
|
179
197
|
nil
|
|
180
198
|
end
|
|
181
199
|
|
|
@@ -194,7 +212,7 @@ module ConnectRPC
|
|
|
194
212
|
response_bytes: nil, response_metadata: {}, response_trailers: {})
|
|
195
213
|
record_failure(error) if error
|
|
196
214
|
processing_at = @processing_at #: Float
|
|
197
|
-
@outcome = Outcome.new(code: code, http_status: http_status, error: @
|
|
215
|
+
@outcome = Outcome.new(code: code, http_status: http_status, error: @failures&.first,
|
|
198
216
|
normalized_error: normalized_error, duration: now - processing_at,
|
|
199
217
|
request_bytes: @request_bytes, response_bytes: response_bytes,
|
|
200
218
|
request_metadata: Instrumentation.carrier(@request_metadata),
|
|
@@ -235,7 +253,7 @@ module ConnectRPC
|
|
|
235
253
|
|
|
236
254
|
prepared = @outcome #: Outcome
|
|
237
255
|
processing_at = @processing_at #: Float
|
|
238
|
-
outcome = @outcome = prepared.with(duration: now - processing_at, error: @
|
|
256
|
+
outcome = @outcome = prepared.with(duration: now - processing_at, error: @failures&.first)
|
|
239
257
|
@processing_state = :finished
|
|
240
258
|
notify_processing(outcome)
|
|
241
259
|
nil
|
|
@@ -243,6 +261,17 @@ module ConnectRPC
|
|
|
243
261
|
|
|
244
262
|
def now = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
245
263
|
|
|
264
|
+
def cause_chain(error)
|
|
265
|
+
chain = [] #: Array[Exception]
|
|
266
|
+
# @type var current: Exception?
|
|
267
|
+
current = error
|
|
268
|
+
while current && chain.none? { |seen| seen.equal?(current) }
|
|
269
|
+
chain << current
|
|
270
|
+
current = current.cause
|
|
271
|
+
end
|
|
272
|
+
chain
|
|
273
|
+
end
|
|
274
|
+
|
|
246
275
|
def notify_processing(outcome)
|
|
247
276
|
@notifying_processing = true
|
|
248
277
|
@observers.each { |callbacks| @bus.safely { callbacks.processing_finished&.call(outcome) } }
|
|
@@ -77,8 +77,7 @@ module ConnectRPC
|
|
|
77
77
|
def prepare_server_stream(method, request, session)
|
|
78
78
|
return unless method.is_a?(ServerStreamMethod) || method.is_a?(Method)
|
|
79
79
|
|
|
80
|
-
session.
|
|
81
|
-
session.close_send
|
|
80
|
+
session.send_request(request)
|
|
82
81
|
end
|
|
83
82
|
|
|
84
83
|
def yield_stream_endpoint(session, scope)
|
|
@@ -48,6 +48,9 @@ module ConnectRPC
|
|
|
48
48
|
@lifecycle&.record_failure(error)
|
|
49
49
|
@state.check!
|
|
50
50
|
if error.is_a?(IOError) || error.is_a?(SystemCallError)
|
|
51
|
+
# The raised failure has no cause; keep the raw error so a forgiven
|
|
52
|
+
# send can drop what the lifecycle recorded for it.
|
|
53
|
+
@raw_send_failure = error
|
|
51
54
|
failure = @send_failure = Error.new(:unavailable, "Streaming write failed")
|
|
52
55
|
raise failure, cause: nil
|
|
53
56
|
end
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
module ConnectRPC
|
|
4
4
|
module Streaming
|
|
5
|
-
class Session
|
|
5
|
+
class Session # rubocop:disable Metrics/ClassLength
|
|
6
6
|
def remote_completed?(error)
|
|
7
7
|
@strategy.grpc? && @eof && error.equal?(@remote_error)
|
|
8
8
|
end
|
|
@@ -48,6 +48,23 @@ module ConnectRPC
|
|
|
48
48
|
end
|
|
49
49
|
end
|
|
50
50
|
|
|
51
|
+
# Sends the one request of a unary or server-streaming call, which core
|
|
52
|
+
# writes itself. As in grpc-go and connect-go, a send failure leaves the
|
|
53
|
+
# outcome to the response; other failures still end the call.
|
|
54
|
+
def send_request(message)
|
|
55
|
+
forgiven = begin
|
|
56
|
+
send_message(message)
|
|
57
|
+
nil
|
|
58
|
+
rescue Error => e
|
|
59
|
+
raise unless send_failure?(e)
|
|
60
|
+
|
|
61
|
+
[e, @raw_send_failure].compact
|
|
62
|
+
end
|
|
63
|
+
# Closing outside the rescue keeps the forgiven failure from becoming
|
|
64
|
+
# the implicit cause of anything close_send raises.
|
|
65
|
+
forgiven ? close_forgiven_send(forgiven) : close_send
|
|
66
|
+
end
|
|
67
|
+
|
|
51
68
|
def abandon
|
|
52
69
|
check_open!
|
|
53
70
|
@abandoned = true
|
|
@@ -60,6 +77,40 @@ module ConnectRPC
|
|
|
60
77
|
|
|
61
78
|
private
|
|
62
79
|
|
|
80
|
+
# The lifecycle drops only the failures this send produced, so failures
|
|
81
|
+
# recorded independently, before or during it, still count.
|
|
82
|
+
def forgive_send(*errors)
|
|
83
|
+
@send_failure = @raw_send_failure = @writing_error = nil
|
|
84
|
+
@lifecycle&.forgive(*errors)
|
|
85
|
+
nil
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
# After a forgiven send, closing may fail again with the write's failure,
|
|
89
|
+
# or with a send failure caused by it, which is forgiven too. Any other
|
|
90
|
+
# failure ends the call: the half-close may not have reached the peer.
|
|
91
|
+
def close_forgiven_send(forgiven)
|
|
92
|
+
forgive_send(*forgiven)
|
|
93
|
+
close_send
|
|
94
|
+
rescue IOError, SystemCallError, Error => e
|
|
95
|
+
raise if e.is_a?(Error) && e.code != "unavailable"
|
|
96
|
+
raise unless caused_by?(e, forgiven)
|
|
97
|
+
|
|
98
|
+
forgive_send(e)
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
def caused_by?(error, causes)
|
|
102
|
+
seen = [] #: Array[Exception]
|
|
103
|
+
# @type var current: Exception?
|
|
104
|
+
current = error
|
|
105
|
+
while current && seen.none? { |failure| failure.equal?(current) }
|
|
106
|
+
return true if causes.any? { |cause| cause.equal?(current) }
|
|
107
|
+
|
|
108
|
+
seen << current
|
|
109
|
+
current = current.cause
|
|
110
|
+
end
|
|
111
|
+
false
|
|
112
|
+
end
|
|
113
|
+
|
|
63
114
|
def receive_message(skip_data)
|
|
64
115
|
raise StreamStateError, "Normal response consumption was relinquished" if @recovering
|
|
65
116
|
|
data/lib/connectrpc/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: connectrpc
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.3.
|
|
4
|
+
version: 0.3.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- jimeh
|
|
8
8
|
bindir: exe
|
|
9
9
|
cert_chain: []
|
|
10
|
-
date: 2026-11-
|
|
10
|
+
date: 2026-11-28 00:00:00.000000000 Z
|
|
11
11
|
dependencies: []
|
|
12
12
|
description: 'Ruby implementation of the Connect protocol: typed clients, a Net::HTTP
|
|
13
13
|
transport, host-neutral servers and a protoc plugin that generates service modules
|