Skip to content

feat: org connection limits and FIFO queue in cluster mode#570

Merged
EDsCODE merged 9 commits into
mainfrom
feature/org-connection-queuing
May 20, 2026
Merged

feat: org connection limits and FIFO queue in cluster mode#570
EDsCODE merged 9 commits into
mainfrom
feature/org-connection-queuing

Conversation

@EDsCODE
Copy link
Copy Markdown
Contributor

@EDsCODE EDsCODE commented May 19, 2026

Overview

This PR adds per-org connection limits for Duckgres cluster mode with FIFO queueing. When an org is at its configured max_connections, new session requests wait in that org's in-memory FIFO queue for up to worker_queue_timeout, which now defaults to 60s. If a request is still queued when the timeout expires, startup fails with SQLSTATE 53300 and message too many connections.

Proposed Changes

  • Config Store Schema: Adds max_connections to Org and carries it into OrgConfig snapshots.
  • Per-Org FIFO Admission Queue:
    • SessionManager tracks active slots and queued waiters per org.
    • Over-limit requests are admitted FIFO when sessions end, worker crash cleanup releases slots, failed session creation releases a reserved slot, or max_connections increases.
    • Queued client cancellations return cancellation, while queue deadline expiry returns ErrTooManyConnections.
  • Timeout Behavior:
    • Reuses existing worker_queue_timeout for worker acquisition and per-org connection-limit queue admission.
    • Changes the default from 5m to 60s and documents it in CLI help, README, and example config.
  • Database-Native Error Pattern:
    • Over-limit timeout maps to SQLSTATE 53300 with message too many connections.
  • Admin API:
    • Exposes max_connections in UpdateOrg.
    • Preserves existing org fields when updating only max_connections.
  • Worker Context Fix:
    • Ensures child worker connections have a connection context before sending initial parameters.

Verification

  • go test -count=1 ./controlplane -run 'TestSessionManager_ConnectionLimits'
  • go test -count=1 . -run TestResolveEffectiveConfigWorkerQueueTimeoutDefault
  • go test -count=1 .
  • just test-controlplane
  • just test-controlplane-k8s
  • git diff --check
  • just lint attempted; blocked locally because golangci-lint is not installed on PATH.

@EDsCODE EDsCODE force-pushed the feature/org-connection-queuing branch from d73a789 to cba9d4f Compare May 19, 2026 18:20
@EDsCODE EDsCODE changed the title feat: org connection limits and queuing in cluster mode feat: org connection limits in cluster mode May 19, 2026
EDsCODE added 2 commits May 20, 2026 13:18
…n-queuing

# Conflicts:
#	controlplane/control_cancel_test.go
#	controlplane/session_mgr.go
@EDsCODE EDsCODE changed the title feat: org connection limits in cluster mode feat: org connection limits and FIFO queue in cluster mode May 20, 2026
@EDsCODE EDsCODE merged commit dd0c7d0 into main May 20, 2026
22 checks passed
@EDsCODE EDsCODE deleted the feature/org-connection-queuing branch May 20, 2026 22:00
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.

1 participant