Skip to content

fix: Hand MASQUE clients over promptly when a provider pod stops - #1573

Open
privateip wants to merge 1 commit into
mainfrom
fix/issue-1562
Open

privateip wants to merge 1 commit into
mainfrom
fix/issue-1562

Conversation

@privateip

Copy link
Copy Markdown
Contributor

Summary

When a MASQUE provider pod behind a public listener shut down, its clients lost about 48 seconds before a surviving pod took them over.

Shutdown closed the listener's socket before the server could send clients a close, never retired the grants it held, and the grant authority then refused the connector for 10 more seconds.

Now the server closes first, shutdown retires each open grant, and the authority holds a retired grant only while a retry of its issuing call could still arrive. The authority's delete of a released grant also now fails if core recorded an address after the authority read it, a race the old 10 second hold only narrowed.

Test plan

  • A client with an open request sees the connection close within 2 s of the listener stopping, not at its idle timeout
  • Shutdown retires the grant of every connector it served, and reports a retirement that fails
  • Another pod admits a connector right after its old grant is retired, and still waits while core holds an address of it
  • Lint, build and the race-enabled unit suite pass

Not covered: shutting down one of two listener backends in the lab.

Fixes #1562

When a provider pod behind a public listener shut down, its clients
lost about 48 seconds before another pod admitted them. Three things
added up:

- Shutdown closed the listener's UDP socket before the CONNECT-IP
  server, so the server had no socket to send CONNECTION_CLOSE on and
  clients learned of it only at their 30 second idle timeout.
  Listener.Stop now closes the server after the drain delay and only
  then the sockets.
- Shutdown never retired the grants it held, so the authority kept
  each authorization until its sweep found it unrenewed. The service
  now calls Adapter.BeginShutdown before stopping the transports, and
  from then on each request retires its grant as the server's close
  ends it. Requests have left the adapter by the time Shutdown runs,
  so retiring there would find nothing. A grant stays live while a
  newer request of the connector on the same pod may hold it, since
  the authority renews a pod's authorization in place.
- The authority then refused the connector for RetryWindow after the
  retirement. That hold exists so a retry of the issuing call finds
  the authorization, and such a retry is accepted only within
  RetryWindow of its issue. The authority now records the issue time
  and holds a retired authorization until the sooner of the two
  deadlines, so one retired long after issue is not held at all.

The 10 second hold had also narrowed a race in reap: core can record
an allocation after reap read the service with none, and the delete
carried only a UID precondition. The delete is now conditioned on the
resourceVersion read as well, so the service is kept for a later
pass.

Tests that used the time hold to stand in for core holding a pool now
set status.allocations, which is what reap checks.

Fixes: #1562
@privateip privateip self-assigned this Dec 2, 2026
@privateip
privateip marked this pull request as ready for review December 2, 2026 01:16
@privateip
privateip requested a review from a team as a code owner December 2, 2026 01:16
@privateip
privateip enabled auto-merge December 2, 2026 01:16
@privateip

Copy link
Copy Markdown
Contributor Author

Both reviewers returned a merge verdict on this head.

pr-conventions-reviewer: "VERDICT: merge. No reach or convention problems found. The diff is confined to internal/edge/masque, internal/edge/connectip and docs/edge, with nothing in a deploy path." It ran: gh pr view 1573; git diff base...head (full, plus -U0 comment scan); git log; git diff --stat; gh pr list --state open (no other open PR touches these files); go build ./internal/edge/... (passed); go vet ./internal/edge/masque/... ./internal/edge/connectip/... (passed). It did not run kustomize validation (no manifests), task ci or the unit suite.

pr-adversary: "VERDICT: merge. No defect in the changed paths; unit suite passes under -race; retryDeadline bound matches the Authorize acceptance check." It ran: gh pr view; gh api issues/1562; gh pr checks; git diff base...head; go build ./internal/edge/...; go vet ./internal/edge/masque/...; go test -race -count=1 ./internal/edge/masque/ ./internal/edge/connectip/ ./internal/edge/masque/service/ ./internal/edge/masque/authority/ (all passed).

No code changes were applied from review. Two decision items were resolved by the author. Acceptance criterion 3 of issue 1562 (a lab test that shuts down one of two listener backends) is an accepted gap, tracked in a follow-up issue. The envtests are confirmed to run in CI, which sets the envtest assets and fails rather than skips when they are missing; locally they failed against main and pass with the fix. One nit about timing in the listener Stop path needs no change.

CI: every check on 7b46f25 completed with success or skipped.

Auto-merge is enabled with the merge method, the only one the base branch ruleset allows. The ruleset requires one approving review including a code owner, dismisses stale reviews on push, and requires approval of the last push, so the PR waits for a human approval.

@privateip
privateip requested a review from scotwells December 2, 2026 01:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MASQUE clients lose about 48 seconds when a provider pod shuts down

1 participant