Skip to content

fix(agent): treat a registrar drain GOAWAY as a handoff, not a watch failure (#718) - #720

Merged
bpalermo merged 2 commits into
mainfrom
fix/718-registrar-goaway-drain
Sep 5, 2026
Merged

bpalermo merged 2 commits into
mainfrom
fix/718-registrar-goaway-drain

Conversation

@bpalermo

@bpalermo bpalermo commented Sep 5, 2026

Copy link
Copy Markdown
Owner

Fixes #718.

The line that had to be explained away

On every registrar Deployment roll (helm rev199/200/201 on 2026-09-05) one or two agents logged, at ERROR:

registrar/registrar.go:588 watch stream disconnected
  rpc error: code = Unavailable desc = closing transport due to: connection error: desc = "error reading from server: EOF", received prior goaway: code: NO_ERROR ...

The draining registrar sent a graceful GOAWAY, the agent reconnected to the surviving replica immediately, nothing was lost. But after #712 quieted the startup case this was the only ERROR an agent emits in a healthy deploy, so it tripped every "zero ERROR lines" gate (deploy validation, the pressure harness's informational list, soak grading).

Classification rule

isServerDrainGoaway(err) is true when both:

  1. status.Code(err) == codes.Unavailable, and
  2. the status message contains received prior goaway: code: NO_ERROR.

grpc-go exposes the GOAWAY code nowhere structurally — the status carries no Details, and google.golang.org/grpc/internal/transport is not importable — so the substring match on the rendered message is the discriminator. It comes from internal/transport/http2_client.go:

st = status.Newf(codes.Unavailable, "closing transport due to: %v, received prior goaway: %v", err, goAwayDebugMessage)
goAwayDebugMessage = fmt.Sprintf("code: %s", f.ErrCode)               // no debug data
goAwayDebugMessage = fmt.Sprintf("code: %s, debug data: %q", …)       // with debug data

grpc-go's own test/goaway_test.go asserts against the same literal, and the unit test here pins it against real grpc-go output rather than a hand-written string. The exact status the test observed from a real GracefulStop() on grpc-go v1.83.0:

rpc error: code = Unavailable desc = closing transport due to: connection error: desc = "error reading from server: EOF", received prior goaway: code: NO_ERROR, debug data: "graceful_stop"

What changes

For a server drain the agent now logs, at INFO:

{"level":"INFO","logger":"registrar-registry","msg":"watch stream closed by server drain; reconnecting","server_drain":true,"error":"rpc error: code = Unavailable desc = closing transport due to: connection error: desc = \"error reading from server: EOF\", received prior goaway: code: NO_ERROR, debug data: \"graceful_stop\""}

— no watch_errors, no backoff; it re-dials the survivor straight away.

What still logs ERROR

Everything that is a real failure. handleStreamError now returns the error to fail on (nil for every expected end), and the loop runs the failure path on it:

Still quiet, as before: io.EOF, the parent-context-cancelled shutdown, a local filter re-assert (Canceled), and a DataLoss forced resync.

Two behaviour notes:

  • The established-stream loss path previously had no metric and no backoff — it re-dialled instantly and only the stream-open path backed off. It now shares failStream with the open path, so a genuinely failing established stream is counted and paced (~1s + jitter) instead of spinning.
  • The ERROR message gained , retrying (watch stream disconnected → watch stream disconnected, retrying), matching the open-path wording. Nothing in the repo, charts or dashboards greps the old string.

Validation

  • New registry/internal/registrar/watch_drain_test.go, reusing fix(agent): stop logging the startup watch-stream handoff as an ERROR (#700) #712's bufconn + locked-JSON-slog harness. Two in-process registrars behind a swappable dial target (the Service VIP): the client streams from replica 1, replica 2 comes up, then replica 1 is drained (GracefulStop() in a goroutine writes the GOAWAY; Stop() then tears the transport down with the stream open — that is what turns the GOAWAY into the client-side Unavailable status). Asserts zero "level":"ERROR" records, one INFO carrying server_drain=true and the real grpc-go error string, aether.agent.registry.watch_errors never recorded, and that the client reconnects and applies the survivor's snapshot.
  • TestWatchLoop_NonGoawayDisconnectStillErrors is the negative half: Stop() with no GOAWAY still yields the ERROR line (with a backoff attr, and no GOAWAY detail in the error) and increments watch_errors.
  • The drain test fails without the production change: neutering isServerDrainGoaway to return false reproduces Should not be: "ERROR" … a registrar drain must not log at ERROR.
  • bazel test --test_arg=-test.short //registry/... //agent/... — 39/39 pass; make gazelle, make format-check, and the gocognit lint aspect with --@aspect_rules_lint//lint:fail_on_violation clean.

No chart change.

🤖 Generated with Claude Code

https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr

bpalermo and others added 2 commits September 5, 2026 19:16
…failure (#718)

On every registrar Deployment roll the draining replica sends a graceful
HTTP/2 GOAWAY (NO_ERROR) and the agent's watch stream dies with

  rpc error: code = Unavailable desc = closing transport due to: connection
  error: desc = "error reading from server: EOF", received prior goaway:
  code: NO_ERROR, debug data: "graceful_stop"

The agent reconnects to the surviving replica immediately, so this is a
handoff, not a failure — but it was the only ERROR an agent emitted in a
healthy deploy (after #712 quieted the startup case), tripping every
"zero ERROR lines" gate.

Classify it: status code Unavailable plus the `received prior goaway:
code: NO_ERROR` detail grpc-go renders into the status message (the code
is exposed nowhere structurally; internal/transport is not importable).
That case now logs INFO "watch stream closed by server drain;
reconnecting" with server_drain=true and the same error attr, counts no
watch_errors, and reconnects with no backoff.

Every other established-stream loss keeps the failure path, which the
established path never had: ERROR, watch_errors, and the jittered
backoff, now shared with the stream-open path via failStream.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
@bpalermo
bpalermo merged commit bc601f4 into main Sep 5, 2026
16 checks passed
@bpalermo
bpalermo deleted the fix/718-registrar-goaway-drain branch September 5, 2026 22:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant