Repository navigation
Require grpc ~> 1.1 - #113
Conversation
|
Hey @Linuus if you have time and you can take a look, I would appreciate it. |
|
Will check tomorrow👍 |
| stream and the receiving side finishes on its own. Returns `:ok` if the | ||
| half-close was sent, or `{:error, reason}` if the stream could not be written. | ||
| """ | ||
| @callback close_send(stream(), config()) :: :ok | {:error, term()} |
There was a problem hiding this comment.
One quick feedback. This is a new, required callback so it could break old custom clients, right? Should we make it optional?
Something like
@optional_callbacks close_send: 2 + function_exported? fallback to old kill path
There was a problem hiding this comment.
I changed it to optional callback
Linuus
left a comment
There was a problem hiding this comment.
Does Pub/Sub actually end the stream on half-close, or does every close fall back to cancel after 3s? Have you seen close durations of less than 3s in your deploys?
|
|
||
| - Require `grpc ~> 1.1`. | ||
| - Fix the `:mint` adapter failing to connect: it rejects unknown adapter options as of `grpc` 1.1, so it now gets its native `:keepalive` option. `:keepalive_interval_ms` applies to `:mint` too, which also closes and replaces a connection after three unanswered pings. | ||
|
|
There was a problem hiding this comment.
Should we also mention the half-close on shutdown/drain?
|
|
||
| Returns `{:ok, nacked_count}` where `nacked_count` is the number of | ||
| buffered messages that were nacked and removed. | ||
| """ |
There was a problem hiding this comment.
I think this doc is outdated now and needs som tweaking.
| :ok -> %{state | send_closed: true} | ||
| _error -> state | ||
| end | ||
| end |
There was a problem hiding this comment.
After the half-close the keepalive timer keeps running. During a drain the stream stays open until the server ends it, so if that takes longer than keepalive_interval_ms, :send_keepalive writes to a half-closed stream. That write errors, and reset_connection closes the stream abruptly. Cancel the timer here, e.g. :ok -> %{cancel_keepalive_timer(state) | send_closed: true}.
| {:stream_closed} -> :ok | ||
| after | ||
| 0 -> :ok | ||
| end |
There was a problem hiding this comment.
The reader can also end with {:stream_error, error} (stream_reader.ex:66 and :106), for example if the server answers the half-close with a non-OK status. That message isn't discarded here, so on the close path without a drain it's still in the mailbox afterwards. handle_info({:stream_error, _}, ...) then handles it as a connection loss and schedules a reconnect.
Discard both messages, e.g. add a {:stream_error, _} -> :ok clause.
|
@Linuus thanks! I apply the comments. What I've made is do the half-close so we notify google pubsub that we don't want more, but do not wait. In normal work since we do the graceful shutdown the time is already be covered, and if not it's just a warning. |
|
Makes sense, thanks for measuring. Agree the wait isn't worth ~2s per producer, and the simpler version is nicer. Two things left:
|
Good catches as always! Both addressed already |
Linuus
left a comment
There was a problem hiding this comment.
Looks good, thanks! Approving. A few optional nits: the fallback in end_send_side could probably just call close_stream/1 (acks use the unary channel, so the stream's channel isn't needed during drain), and the graceful-shutdown wording in producer.ex (~178, ~520) still describes the old behaviour.
We now also emit the :disconnect telemetry for graceful disconnects. I don't think we did that before, but I also don't know if that matters or not though. 😅
| |> stop_reader() | ||
| |> cancel_keepalive_timer() | ||
| |> Map.merge(%{reader_pid: nil, grpc_stream: nil}) | ||
| end |
There was a problem hiding this comment.
Nit: This else can just be close_stream(state) I believe.
There was a problem hiding this comment.
Updated all the documentation to have both half-close and the fallback, changed to close_stream(state)
For the :disconnect telemetry, I think it makes sense to keep it, it is technically disconnecting the channel
Bumps the requirement to
grpc ~> 1.1.:http2_opts. It now gets:keepaliveand:keepalive_tolerance(3)::keepalive_interval_msapplies to:mint, and a connection that stops answering pings is closed and replaced.close_send/2callback toStreaming.Client(GRPC.Stub.end_stream/1). On graceful shutdown the stream manager half-closes the stream and waits up to 3s for the server to end it, falling back to cancel. This avoids killing a reader that still owns the stream.On grpc 1.0 the Mint adapter silently ignores the keepalive options, so Mint would run without keepalive.