Skip to content

api: enforce Connect stream lifecycle policies - #5508

Open
siavashs wants to merge 3 commits into
prometheus:mainfrom
siavashs:feat/connect-stream-lifecycle
Open

api: enforce Connect stream lifecycle policies#5508
siavashs wants to merge 3 commits into
prometheus:mainfrom
siavashs:feat/connect-stream-lifecycle

Conversation

@siavashs

@siavashs siavashs commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Bound stream idle time and lifetime, track active RPC cancellation, and cancel long-lived handlers during shutdown so every admission slot is eventually released.

Part of #5478

Keep handler registration, health and reflection names, and bounded procedure instrumentation derived from one catalog so new services cannot drift across separate allowlists.

Signed-off-by: Siavash Safi <siavash@cloudflare.com>
@siavashs
siavashs force-pushed the feat/connect-stream-lifecycle branch from a934601 to c38131d Compare September 1, 2026 12:15
Move RPC admission ahead of decoding, apply explicit unary read and protobuf size limits, and expose bounded lifecycle metrics so slow or oversized clients cannot consume unbounded resources.

Signed-off-by: Siavash Safi <siavash@cloudflare.com>
@siavashs
siavashs force-pushed the feat/connect-stream-lifecycle branch from c38131d to 066fff4 Compare September 1, 2026 12:34
Bound stream idle time and lifetime, track active RPC cancellation, and cancel long-lived handlers during shutdown so every admission slot is eventually released.

Signed-off-by: Siavash Safi <siavash@cloudflare.com>
@siavashs
siavashs force-pushed the feat/connect-stream-lifecycle branch from 066fff4 to 774f1a1 Compare September 1, 2026 12:45
@siavashs
siavashs marked this pull request as ready for review September 1, 2026 13:23
@siavashs
siavashs requested a review from a team as a code owner September 1, 2026 13:23
@coderabbitai

coderabbitai Bot commented Sep 1, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Team

Run ID: 2b859a5b-d8cc-457c-8e5e-a7d24c83373c

📥 Commits

Reviewing files that changed from the base of the PR and between 7935b44 and 774f1a1.

📒 Files selected for processing (12)
  • api/api.go
  • api/api_test.go
  • api/connect/connect.go
  • api/connect/connect_suite_test.go
  • api/connect/health_test.go
  • api/connect/status_test.go
  • app/app.go
  • app/lifecycle.go
  • app/options.go
  • app/options_test.go
  • cmd/alertmanager/main.go
  • test/e2e/status_test.go

Included review availability: Your plan provides up to 8 included reviews per hour; 5 remain after this review.


📝 Walkthrough

Walkthrough

The Connect API now supports configurable concurrency, timeouts, message-size limits, metrics, exact procedure matching, and shutdown cancellation. Application flags and options expose these settings, and tests cover unary, stream, metric, and shutdown behavior.

Changes

Connect RPC lifecycle

Layer / File(s) Summary
Configuration and API initialization
api/connect/connect.go, api/api.go, app/options.go, cmd/alertmanager/main.go, app/app.go
Connect settings flow from command-line flags and application options into API construction. NewAPI initializes descriptors and metrics and can return initialization errors.
Admission, registration, and shutdown
api/connect/connect.go, api/api.go, app/app.go, app/lifecycle.go
Handlers enforce concurrency, deadlines, request-size, and stream limits. Metrics record RPC outcomes. Instrumentation matches exact procedures. Shutdown rejects new RPCs and cancels active RPCs.
Lifecycle and limit validation
api/connect/*_test.go, api/api_test.go, app/options_test.go, test/e2e/status_test.go
Tests cover procedure labels, API initialization, request limits, unary and stream admission, metrics, defaults, and shutdown cancellation.

Estimated code review effort: 4 (Complex) | ~45 minutes

Merge Risk: 🟡 Moderate · up to 774f1

The PR adds shared stream admission limits and optional idle/lifetime expiration, but production defaults leave both expirations disabled. A reachable client can occupy all stream slots indefinitely, causing ResourceExhausted responses for other Connect users; merge should wait for finite defaults or explicit owner acceptance.

Sequence Diagram(s)

sequenceDiagram
  participant HTTPServer
  participant ConnectAPI
  participant ConnectControlHandler
  participant PrometheusMetrics
  HTTPServer->>ConnectAPI: invoke Shutdown()
  ConnectAPI->>ConnectControlHandler: reject new RPCs and cancel active RPCs
  ConnectControlHandler->>PrometheusMetrics: record terminal RPC outcomes
Loading
🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description accurately summarizes the primary change and references issue #5478, but it omits the required checklist, release-notes entry, applicable test and performance details, breaking-change … Complete the repository description template. Add the checklist responses, include the applicable unit/e2e test and performance information, state whether the change is breaking, confirm documentation and commit sign-off, and add a release-…
Docstring Coverage ⚠️ Warning Docstring coverage is 27.27% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 11 functions across 12 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise, follows the required area: short description format, and accurately describes the main Connect stream lifecycle changes.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description accurately summarizes the primary change and references issue #5478, but it omits the required checklist, release-notes entry, applicable test and performance details, breaking-change status, documentation status, and sign-off confirmation.

Resolution

Complete the repository description template. Add the checklist responses, include the applicable unit/e2e test and performance information, state whether the change is breaking, confirm documentation and commit sign-off, and add a release-notes entry or NONE.

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant