feat(gateway): add per-app connection rate limiting #482
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Add configurable maximum concurrent connections per app to prevent a single slow or overloaded app from exhausting system resources (especially upstream port pool) and affecting other apps.
max_connections_per_appconfig option in[core.proxy]sectionBackground
When an app becomes slow or overloaded, connections to it accumulate and don't release promptly. This can exhaust the upstream load balancer's port pool (since all connections come from the same source IP), causing connection failures for ALL apps - not just the problematic one.
This rate limiting ensures that a single misbehaving app cannot monopolize resources and impact the entire gateway.
Configuration
Test Results
Tested on TDX host with gateway CVM (
10.20.0.124:14100,max_connections_per_app = 50) and echo CVM (ports 5001-5005).Test 1: 30 connections (within limit)
Test 2: 100 connections (exceeding limit)
app connection limit exceeded app_id="..." total=50 max_connections=50Conclusion
Rate limiting works as expected, precisely capping concurrent backend connections per app. Excess connections are rejected after TLS handshake but before backend connection establishment.