Repository navigation
gateway: end a stream whose open is not recorded, and wait for its writer - #275
Merged
Merged
Conversation
Tests ahead of the fixes for #264 and #260, so they fail first. A stream whose open record fails must end with Unavailable before its HelloAck, naming nothing of the store's error, leave the registry and the workload's hold, and leave the record truthful: the previous stream's offline mark stands, an open that landed though it reported failure is marked offline, and a stream another replica serves keeps its state. The next stream opens at once and its end is recorded offline. An open that finds the workload unknown or retired is answered as the Hello is. The handler must not return before its writer: a send in progress when the stream ends is waited for, a send that cannot return while the handler waits bounds the wait with a warning, and a snapshot stamp in flight lands before the offline mark and before the stream ends. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Claude <noreply@anthropic.com>
…iter A stream whose open record fails is no longer served (#264). Served, its acknowledgments and heartbeats landed while the record named an earlier stream, and its offline mark, written only while the record names the ending stream, was skipped: the workload read as connected with no stream. The session now leaves the registry while the workload is still held for the open, the same conditioned mark any ending stream writes records its end, the hold is released, and the stream ends before its HelloAck: Unavailable for a store failure, naming nothing of the error, so the agent redials with its backoff; PermissionDenied for an unknown workload and the opaque refusal for a retired one, as the Hello answers them. The handler now waits for its writer (#260). The writer touches no store: it reports each snapshot it sends and the handler stamps it, so every write a stream makes is the handler's, and shutdown's wait for handlers covers it. On its way out the handler waits at most five seconds for the writer, since a send without flow-control credit returns only once the stream is done, then stamps a snapshot sent before the end, then records the end. The stamp and the mark share the mark's five-second bound, so a stop still takes at most fifteen seconds. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Claude <noreply@anthropic.com>
|
No ADR contradictions found (diff-anchored review). ScopeThe diff touches FindingsNone of the two fixes contradicts an Accepted ADR's core decision, and none adds one that would need a superseding ADR.
Consistency / dangling references
No superseding ADR is present, and none is needed. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two defects in the sync handler (
internal/gateway/sync.go), both about a stream's writes not matching the stream's life.A stream whose open is not recorded is ended, not served (#264)
A replica records a stream's open, naming the stream on the workload's record, while it holds the workload; the offline mark is written only while the record names the ending stream (#109). When the open write failed, the handler logged it and served the stream: the stream's acknowledgments and heartbeats landed, but its offline mark found another stream's name, so the workload read as connected with no stream.
Now, when the open write fails, the handler:
sessions.withdraw) while the workload is still held for the open, so no other stream of it registers in between, and a retirement watching the workload sees a stream leave;HelloAck. The status is the Hello's for the same finding: the opaque refusal for a retired workload (ADR-0023),PermissionDeniedfor one the registry does not hold, and otherwiseUnavailablewithrecording stream open, naming nothing of the store's error. A stream ended meanwhile throughEndStreamreturns that status instead.The agent treats a stream that ends before
HelloAckas a failure: it redials with exponential backoff and full jitter, and since the stream was never established the attempt counter is not reset (internal/agent/sync/daemon.go,RunandrunSession). Nothing in the agent changes.The handler waits for its writer, and makes the snapshot stamp itself (#260)
The writer goroutine stamped
last_snapshot_sent_atafter each snapshot it sent, and the handler did not wait for it, while shutdown waits only for handlers before it closes the store.A send blocked on flow control returns only once the stream is done: grpc-go's server
SendMsgblocks in the stream's write quota until there is credit or the stream's context ends, and that context ends when the agent goes away, whenServer.Stopcloses the transports, or when the handler returns. An unbounded wait before return could therefore hang on a stream whose agent has stopped reading. So:writerExitTimeout), and logssync stream writer still in a send at the handler's exit; it ends with the streamat warning level if the bound is reached. That send then fails as the handler returns, and nothing it does touches the store;offlineWriteTimeout), the mark's bound before. AfterStopevery send returns at once, so a handler still returns within shutdown's five-second handler wait, and a stop still takes at most fifteen seconds; the composestop_grace_periodof twenty seconds is unchanged. Outside a stop, a handler whose writer is stuck in a send can take up to ten seconds to return.Tests
stream_open_integration_test.go(Postgres): the open write fails through a registry wrapper. The stream ends withUnavailableand the store's text is not in it; the replica no longer holds it; the record reads as the previous stream's end left it; an open that landed but reported failure reads offline; a stream served by another replica keeps its synced state; the unknown and retired findings answer as the Hello does; and in each case the next stream opens and its end is recorded offline. A held snapshot stamp delays the stream's end, and the stamp lands before the mark.writer_exit_test.go: over a stream whose sends block, the handler does not return while its writer is in a send and returns once the send does, and a send that never returns bounds the wait with the warning, after which the offline mark is written.Docs
ARCHITECTURE.md §4.2 says a stream whose open cannot be recorded is not served, and that the handler makes every write a stream causes.
docs/troubleshooting.mdgains an entry for an agent stream that ends withrecording stream open. CHANGELOG entries for both issues. ADR-0018 is unchanged: nothing in it says a stream is served whatever its open record, and its statement that the stored state describes the stream that registered last now holds when the open write fails.No schema, migration, proto, sqlc, agent, REST, or console change.
Fixes #264.
Fixes #260.
Generated by Claude Code