Skip to content

Suppress spurious warnings from port scanner connections#15713

Merged
michaelklishin merged 2 commits intorabbitmq:mainfrom
amazon-mq:fix/fewer-stream-warnings
Mar 12, 2026
Merged

Suppress spurious warnings from port scanner connections#15713
michaelklishin merged 2 commits intorabbitmq:mainfrom
amazon-mq:fix/fewer-stream-warnings

Conversation

@lukebakken
Copy link
Copy Markdown
Collaborator

Follow-up to #15703, which fixed a crash when port scanners connect to the stream port. That fix revealed two remaining sources of log noise:

1. Unrecognised pre-auth data logged at warning level

handle_frame_pre_auth/4 had a catch-all that logged {unknown, Data} at warning level. Since this is expected from port scanners and other non-RabbitMQ clients, a specific {unknown, _} clause is added that logs at debug level instead. The existing warning-level catch-all remains for any other unexpected pre-auth commands.

A specific {unknown, _} clause is also added to handle_frame_post_auth/4 with a clearer log message (post-auth unrecognised data is more noteworthy and stays at warning). send_close_and_increment/2 is extracted to eliminate the resulting duplication.

2. Spurious "invalid transition" warnings from partial frames

When incoming data does not contain a complete frame (e.g. a port scanner sends fewer bytes than a full frame header), no commands are parsed and connection_step remains unchanged. The five pre-open state handlers (tcp_connected, peer_properties_exchanged, authenticating, tuning, tuned) treated this as an invalid transition and logged a warning.

A guard is added to each handler that returns keep_state when NextConnectionStep equals the current state name, correctly waiting for more data. The existing negotiation timeout will still close connections that make no progress.

Port scanners and other non-RabbitMQ clients connecting to the stream
port send arbitrary data before any authentication takes place. The
resulting `{unknown, Data}` commands are expected and not actionable,
so logging them at warning level is unnecessarily noisy.

Add a specific clause for `{unknown, _}` in `handle_frame_pre_auth/4`
that logs at debug level. The existing warning-level catch-all remains
for any other genuinely unexpected pre-auth commands.

Also add a specific clause for `{unknown, _}` in
`handle_frame_post_auth/4` with a clearer log message, and extract
`send_close_and_increment/2` to eliminate the resulting duplication.
Two sources of noise in the logs when port scanners connect to the
stream port:

1. Unrecognised pre-auth data was logged at warning level. Since this
   is expected from port scanners and other non-RabbitMQ clients, add a
   specific `{unknown, _}` clause in `handle_frame_pre_auth/4` that
   logs at debug level instead. The existing warning-level catch-all
   remains for any other unexpected pre-auth commands.

   Also add a specific `{unknown, _}` clause in
   `handle_frame_post_auth/4` with a clearer log message, and extract
   `send_close_and_increment/2` to eliminate the resulting duplication.

2. When incoming data does not contain a complete frame (e.g. a port
   scanner sends fewer bytes than a full frame header), no commands are
   parsed and `connection_step` remains unchanged. The pre-`open`
   state handlers treated this as an invalid transition and logged a
   warning. Add a guard in each of the five pre-`open` state handlers
   (`tcp_connected`, `peer_properties_exchanged`, `authenticating`,
   `tuning`, `tuned`) that returns `keep_state` when
   `NextConnectionStep` equals the current state, waiting for more
   data. The existing negotiation timeout will still close connections
   that make no progress.
fun(NextConnectionStep,
#statem_data{transport = Transport,
connection = #stream_connection{socket = S}} =
StatemData,
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

FYI I re-formatted these functions using = in neovim.

michaelklishin added a commit that referenced this pull request Mar 12, 2026
@michaelklishin michaelklishin merged commit 0fa1e99 into rabbitmq:main Mar 12, 2026
182 checks passed
mergify bot pushed a commit that referenced this pull request Mar 12, 2026
(cherry picked from commit b69c014)
@the-mikedavis the-mikedavis deleted the fix/fewer-stream-warnings branch March 12, 2026 14:06
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