Skip to content

♻️🚑️🤖 RabbitMQ: bound the logs queue to prevent unbounded broker memory growth - #9606

Open
sanderegg wants to merge 5 commits into
ITISFoundation:masterfrom
sanderegg:maintenance/bound-rabbitmq-logs-queue
Open

♻️🚑️🤖 RabbitMQ: bound the logs queue to prevent unbounded broker memory growth#9606
sanderegg wants to merge 5 commits into
ITISFoundation:masterfrom
sanderegg:maintenance/bound-rabbitmq-logs-queue

Conversation

@sanderegg

Copy link
Copy Markdown
Member

What do these changes do?

This PR adds three new opt-in parameters to RabbitMQClient.subscribe() (packages/service-library) — none change behavior for any existing exchange/service, since they all default to None/current behavior:

  • max_length — caps queue depth via x-max-length + x-overflow: drop-head, so a runaway queue drops its oldest messages instead of growing unbounded. Acts as a last-resort circuit breaker, not a routine control.
  • prefetch_count — lets a subscriber override the hardcoded default QoS (1 for shared queues / 10 for exclusive queues), which is otherwise a hard throughput ceiling regardless of how fast the handler runs.
  • enable_dead_letter_requeue — lets a subscriber disable the nack/TTL-expiry retry-via-requeue machinery, for best-effort/fire-and-forget exchanges where redelivering a stale message is actively harmful rather than useful.
  • A new periodic backlog monitor logs a WARNING when a bounded queue's depth grows for 3 consecutive checks — an early-warning signal that a consumer can't keep up, using its own dedicated channel to avoid interfering with active consumer traffic. This might need further tuning later on.

These are applied to the webserver's LoggerRabbitMessage (live log streaming) subscription specifically:

  • max_length=1_500_000 (headroom above the largest healthy historical burst observed, ~920K messages)
  • prefetch_count=100 (within RabbitMQ's own documented optimal range of 100–300)
  • enable_dead_letter_requeue=False

No other exchange or service is affected.

Related issue/s

How to test

Dev-ops

  • 🤖 Assisted-by: GitHub Copilot:Claude Sonnet 4.5

@sanderegg sanderegg self-assigned this Aug 27, 2026
@sanderegg sanderegg added the t:maintenance Maintenance work; used to filter tasks for end-of-sprint reporting in Review (Agreed July 3, Retro) label Aug 27, 2026
@sanderegg sanderegg added this to the War Pigs milestone Aug 27, 2026
@github-actions github-actions Bot added a:webserver webserver's codebase. Assigning the area is particularly useful for bugs a:services-library issues on packages/service-libs labels Aug 27, 2026
@sanderegg
sanderegg marked this pull request as ready for review August 27, 2026 16:28
@codecov

codecov Bot commented Aug 27, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 86.44068% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.11%. Comparing base (b722465) to head (934948c).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #9606      +/-   ##
==========================================
- Coverage   88.15%   86.11%   -2.05%     
==========================================
  Files        1559     1112     -447     
  Lines       60601    46362   -14239     
  Branches     1583      796     -787     
==========================================
- Hits        53421    39923   -13498     
+ Misses       6759     6182     -577     
+ Partials      421      257     -164     
Flag Coverage Δ
integrationtests 71.90% <ø> (-0.04%) ⬇️
unittests 86.00% <86.44%> (-0.99%) ⬇️
Components Coverage Δ
pkg_aws_library ∅ <ø> (∅)
pkg_celery_library ∅ <ø> (∅)
pkg_dask_task_models_library ∅ <ø> (∅)
pkg_models_library ∅ <ø> (∅)
pkg_notifications_library ∅ <ø> (∅)
pkg_postgres_database ∅ <ø> (∅)
pkg_service_integration ∅ <ø> (∅)
pkg_service_library 71.36% <86.44%> (+0.08%) ⬆️
pkg_settings_library ∅ <ø> (∅)
pkg_simcore_sdk 86.37% <ø> (-0.05%) ⬇️
agent 93.91% <ø> (ø)
api_server 92.97% <ø> (ø)
autoscaling 95.21% <ø> (ø)
catalog 91.90% <ø> (ø)
clusters_keeper 98.61% <ø> (ø)
dask_sidecar 93.22% <ø> (-0.16%) ⬇️
datcore_adapter 98.08% <ø> (ø)
director 79.17% <ø> (ø)
director_v2 91.97% <ø> (-0.07%) ⬇️
dynamic_scheduler 95.96% <ø> (+0.20%) ⬆️
dynamic_sidecar 72.51% <ø> (-16.15%) ⬇️
efs_guardian 89.40% <ø> (ø)
invitations 91.63% <ø> (ø)
payments 92.49% <ø> (ø)
resource_usage_tracker 91.63% <ø> (-0.06%) ⬇️
storage 87.99% <ø> (-0.04%) ⬇️
webclient ∅ <ø> (∅)
webserver ∅ <ø> (∅)

Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b722465...934948c. Read the comment docs.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@sanderegg sanderegg added the 🤖-automerge marks PR as ready to be merged for Mergify label Aug 27, 2026

@pcrespov pcrespov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

thx

Comment thread packages/service-library/src/servicelib/rabbitmq/_client.py

Copilot AI 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.

Pull request overview

This PR enhances the shared RabbitMQClient.subscribe() API (in packages/service-library) with opt-in controls to prevent runaway queue growth and improve high-volume consumer throughput, and then applies those controls specifically to the webserver live-log streaming consumer to protect the RabbitMQ broker from unbounded memory growth.

Changes:

  • Added optional max_length, prefetch_count, and enable_dead_letter_requeue parameters to RabbitMQClient.subscribe(), plus a periodic backlog monitor for bounded queues.
  • Updated the webserver logs subscription to cap queue depth, increase QoS prefetch, and disable dead-letter-based retries for best-effort log streaming.
  • Added service-library tests covering queue max-length behavior, QoS prefetch limiting, retry disabling, and backlog-monitor warning behavior.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
services/web/server/src/simcore_service_webserver/notifications/_rabbitmq_exclusive_queue_consumers.py Applies bounded-queue + higher prefetch + no-retry semantics to the live log streaming subscription to protect the broker.
packages/service-library/src/servicelib/rabbitmq/_client.py Extends RabbitMQClient.subscribe() with queue bounding, configurable QoS prefetch, optional retry-via-DLX, and a periodic backlog monitor.
packages/service-library/tests/rabbitmq/test_rabbitmq.py Adds tests validating the new subscription options and backlog monitor logging.
Suppressed comments (1)

packages/service-library/src/servicelib/rabbitmq/_client.py:333

  • Even though enable_dead_letter_requeue is documented correctly here, the earlier message_handler parameter docs still state that failures are always "redelivered". With this flag set to False, failures/expirations are dropped, so the message_handler docs should be updated to avoid misleading API consumers.
                "When True (default), messages that are nacked or that expire after sitting "
                "`message_ttl` in the queue are bounced through a delay queue and re-published into "
                "THIS SAME exchange for a retry, up to `unexpected_error_max_attempts` times. Set False "
                "for best-effort/fire-and-forget exchanges (e.g. live UI notifications) where a stale "
                "message has no value: expired/nacked messages are then simply dropped instead of "

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread packages/service-library/src/servicelib/rabbitmq/_client.py Outdated
Comment thread packages/service-library/src/servicelib/rabbitmq/_client.py Outdated
Comment thread packages/service-library/src/servicelib/rabbitmq/_client.py
Comment thread packages/service-library/src/servicelib/rabbitmq/_client.py
@sanderegg
sanderegg force-pushed the maintenance/bound-rabbitmq-logs-queue branch from a5ab55b to 2f7d094 Compare August 27, 2026 18:10

@GitHK GitHK 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.

👍

else 0
)
if consecutive_growth >= _BACKLOG_MONITOR_CONSECUTIVE_GROWTH_TO_WARN:
_logger.warning(

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 be nice to expose it as metrics and introduce alert based on it

@YuryHrytsuk YuryHrytsuk 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.

Brief and to the point.

Very nice!

@sanderegg
sanderegg force-pushed the maintenance/bound-rabbitmq-logs-queue branch from b84d4c9 to 934948c Compare August 28, 2026 17:34
@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🤖-automerge marks PR as ready to be merged for Mergify a:services-library issues on packages/service-libs a:webserver webserver's codebase. Assigning the area is particularly useful for bugs t:maintenance Maintenance work; used to filter tasks for end-of-sprint reporting in Review (Agreed July 3, Retro)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants