Skip to content

Add stomp.max_connections per-node connection limit#16368

Merged
michaelklishin merged 5 commits into
mainfrom
feature/gh-16347-stomp-connections-max
May 11, 2026
Merged

Add stomp.max_connections per-node connection limit#16368
michaelklishin merged 5 commits into
mainfrom
feature/gh-16347-stomp-connections-max

Conversation

@lukebakken

@lukebakken lukebakken commented May 10, 2026

Copy link
Copy Markdown
Collaborator

Closes #16347 (partial - adds stomp.max_connections).

What this PR does

Adds stomp.max_connections, a per-node connection limit for the plain STOMP plugin, matching the existing stream.max_connections and mqtt.max_connections settings. When the limit is reached, the broker sends a STOMP ERROR frame and closes the connection.

How it works

The enforcement follows the same application-level pattern used by stream.max_connections and rabbit.connection_max - it does not operate at the Ranch transport layer, so the TCP listen queue is unaffected and Ranch continues accepting connections normally.

rabbit_stomp_processor:initial_state/2 is kept as a one-line wrapper delegating to a new initial_state/3 that accepts the Ranch listener reference, so rabbit_web_stomp_handler (Web STOMP) requires no change and Web STOMP connections are never subject to the plain STOMP plugin limit.

Inside process_connect/3, check_node_connection_limit/1 is the first check in the maybe chain. It calls ranch:info(RanchRef) to get active_connections for the specific listener and compares it against application:get_env(rabbitmq_stomp, max_connections, infinity).

The limit is per-listener: TCP and TLS listeners are enforced independently.

Configuration

stomp.max_connections = 1000

The default is infinity (no limit). The setting accepts a non-negative integer or infinity.

Testing

Adds node_connection_limit to connections_SUITE. The test sets the limit to 0 via RPC, sends a CONNECT frame over a raw TCP socket, and asserts that an ERROR frame is received.

@lukebakken lukebakken changed the title Add stomp.max_connections setting Add stomp.max_connections per-node connection limit May 10, 2026
Introduces the stomp.max_connections setting to cap the number of STOMP
connections accepted per node, matching the pattern already established by
stream.max_connections. The cuttlefish translation uses cuttlefish:unset()
when the setting is absent so that application:get_env/3 returns the
infinity default without an explicit env entry.
Threads the Ranch listener reference through initial_state/3 (new; /2 is
kept as a wrapper passing undefined so rabbit_web_stomp_handler needs no
change) into #cfg{ranch_ref}. check_node_connection_limit/1 is called as
the first check in process_connect/3, using ranch:info/1 to compare active
connections against the configured limit and returning an ERROR frame when
the limit is exceeded.
Verifies that when stomp.max_connections is set to 0 a connecting client
receives a STOMP ERROR frame rather than a CONNECTED frame.
Without this, a failed assertion would leave max_connections set to 0,
causing all subsequent test cases that open a connection to fail.
@lukebakken lukebakken force-pushed the feature/gh-16347-stomp-connections-max branch from 2b3a41e to b310346 Compare May 11, 2026 15:18
@lukebakken lukebakken marked this pull request as draft May 11, 2026 15:25
@lukebakken lukebakken marked this pull request as ready for review May 11, 2026 16:05
@michaelklishin

Copy link
Copy Markdown
Collaborator

I am extending this to be very similar to the final design of #16367.

@michaelklishin michaelklishin added the do-not-backport Changes not meant to be backported to release branches label May 11, 2026
@michaelklishin michaelklishin added this to the 4.4.0 milestone May 11, 2026
@michaelklishin

michaelklishin commented May 11, 2026

Copy link
Copy Markdown
Collaborator

Give that the delta in main and v4.3.x for STOMP is substantial, this will have to be an alternative implementation for v4.3.x, v4.2.x rather than a backport or an adapted backport.

@michaelklishin michaelklishin merged commit 11f901d into main May 11, 2026
188 checks passed
@michaelklishin michaelklishin deleted the feature/gh-16347-stomp-connections-max branch May 11, 2026 23:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do-not-backport Changes not meant to be backported to release branches enhancement rabbitmq-stomp

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve connection limits, introduce per-protocol connection limits

2 participants