Skip to content

[graphql-stream] Cap concurrent subscriptions with a configurable max_subscribers limit [23/n] - #27787

Merged
tpham-mysten merged 1 commit into
tpham-mysten/subscription-lifecycle-metricsfrom
tpham-mysten/subscription-max-subscribers-v2
Aug 26, 2026
Merged

tpham-mysten merged 1 commit into
tpham-mysten/subscription-lifecycle-metricsfrom
tpham-mysten/subscription-max-subscribers-v2

Conversation

@tpham-mysten

@tpham-mysten tpham-mysten commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

Description

Subscriptions currently open without any aggregate limit, so a burst of subscribers can drive server CPU and memory unbounded. This adds a configurable max_subscribers (default 1024): each subscription claims a slot from a shared semaphore held for its lifetime by the lifecycle guard, and a subscription opened while all slots are taken is refused with a resource_exhausted error so the client can retry later. Refusals are counted by graphql_subscription_rejected{type, reason}.

Guard creation moves out of the driver stream! bodies up to the resolver, so admission happens once at connect time before any work begins.

Test plan

New rejects_at_capacity unit test covers admission, the at-capacity refusal and its metric, and slot release on drop. Existing subscription lib tests cover the guard threaded through the drivers.

Stack

Release notes

Check each box that your change affects. If none of the boxes relate to your changes, release notes aren't required.

For each box you select, include information after the relevant heading that describes the impact of your changes that a user might notice and any actions they must take to implement updates.

  • Protocol:
  • Nodes (Validators and Full nodes):
  • gRPC:
  • JSON-RPC:
  • GraphQL:
  • CLI:
  • Rust SDK:
  • REST API:

@tpham-mysten
tpham-mysten temporarily deployed to sui-typescript-aws-kms-test-env August 21, 2026 04:39 — with GitHub Actions Inactive
@vercel

vercel Bot commented Aug 21, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
sui-docs Ready Ready Preview Aug 26, 2026 7:41pm
2 Skipped Deployments
Project Deployment Actions Updated (UTC)
multisig-toolkit Ignored Ignored Preview Aug 26, 2026 7:41pm
sui-kiosk Ignored Ignored Preview Aug 26, 2026 7:41pm

Request Review

@tpham-mysten
tpham-mysten force-pushed the tpham-mysten/subscription-max-subscribers-v2 branch from 519e4f5 to d3a5e41 Compare August 21, 2026 04:42
@tpham-mysten
tpham-mysten temporarily deployed to sui-typescript-aws-kms-test-env August 21, 2026 04:42 — with GitHub Actions Inactive
@tpham-mysten tpham-mysten changed the title Cap concurrent subscriptions with a configurable max_subscribers limit [graphql-stream] Cap concurrent subscriptions with a configurable max_subscribers limit [23/n] Aug 21, 2026
@tpham-mysten
tpham-mysten marked this pull request as ready for review August 21, 2026 04:43
@tpham-mysten
tpham-mysten requested a review from a team as a code owner August 21, 2026 04:43
@tpham-mysten
tpham-mysten temporarily deployed to sui-typescript-aws-kms-test-env August 21, 2026 04:43 — with GitHub Actions Inactive
@tpham-mysten
tpham-mysten force-pushed the tpham-mysten/subscription-max-subscribers-v2 branch from d3a5e41 to ebcb2a5 Compare August 24, 2026 20:32
@tpham-mysten
tpham-mysten temporarily deployed to sui-typescript-aws-kms-test-env August 24, 2026 20:32 — with GitHub Actions Inactive
@datadog-mystenlabs

datadog-mystenlabs Bot commented Aug 24, 2026 •

Copy link
Copy Markdown

Pipelines

⚠️ Warnings

🚦 5 Pipeline jobs failed

Native Bridge | test (ubuntu-ghcloud)

View in Datadog · View in GitHub Actions

Unbound variable: FOUNDRY_BIN_DIR during script execution.

Release Notes | Validate Release Notes in 27787

View in Datadog · View in GitHub Actions

Found issues with release notes in PR 27787: unfamiliar impact area 'REST API'.

Rust | simtest

View in Datadog · View in GitHub Actions

4 tests failed due to panic: 'there is no reactor running, must be called from the context of a Madsim runtime' at /home/runner/.cargo/git/checkouts/mysten-sim-84667d6d927bc7b7/6b8e1e8/msim/src/sim/runtime/context.rs:15:55.

View all 5 failed jobs.

Useful? React with 👍 / 👎

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: ebcb2a5 | Docs | View more details | Give us feedback!

@amnn amnn left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would consider allowing requests to wait a little bit for a semaphore token, but broadly looks good, thanks @tpham-mysten

Comment thread crates/sui-indexer-alt-graphql/src/task/streaming/lifecycle.rs
@tpham-mysten
tpham-mysten force-pushed the tpham-mysten/subscription-max-subscribers-v2 branch from ebcb2a5 to 9e11fc9 Compare August 26, 2026 19:38
@tpham-mysten
tpham-mysten temporarily deployed to sui-typescript-aws-kms-test-env August 26, 2026 19:38 — with GitHub Actions Inactive
@tpham-mysten

Copy link
Copy Markdown
Contributor Author

Thanks @amnn!

Doing this on the GraphQL server side is probably not the right place, mainly because it's tricky to decide which request we should hold. From the infra side, I think the per-IP rate limit should be partially sufficient to prevent it.

@tpham-mysten
tpham-mysten merged commit 8b91635 into main Aug 26, 2026
62 of 63 checks passed
@tpham-mysten
tpham-mysten deleted the tpham-mysten/subscription-max-subscribers-v2 branch August 26, 2026 20:13
@amnn

amnn commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

I think if we take the view that we should not be hitting this limit under normal operation, and we can rely on health checks and auto-scaling, then I can get behind this (but then we should probably set a more generous upper limit at this layer and leave the more conservative limit for the gateway to enforce).

This branch was successfully deployed

1 active and 1 inactive deployments
Preview – sui-docs — 9e11fc96 Deployed Aug 26, 2026 by vercel[bot]
sui-typescript-aws-kms-test-env — 9e11fc96 Deployed Aug 26, 2026 by tpham-mysten via Lint, Build, and Test #90473
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.

2 participants