Skip to content

🐛 Fix RabbitMQ probe cleanup on Python 3.14#7342

Merged
agoscinski merged 3 commits into
aiidateam:mainfrom
agoscinski:fix/rmq-autodetect-py314
Apr 30, 2026
Merged

🐛 Fix RabbitMQ probe cleanup on Python 3.14#7342
agoscinski merged 3 commits into
aiidateam:mainfrom
agoscinski:fix/rmq-autodetect-py314

Conversation

@agoscinski
Copy link
Copy Markdown
Collaborator

@agoscinski agoscinski commented Apr 28, 2026

Should fix issues when trying to connect to RMQ. This fix is not related to ZMQ but the problem became more pressing because in verdi presto we first try to connect to RMQ and if its not available

❮ verdi presto
Report: Option `--use-postgres` not enabled: configuring the profile to use SQLite.
error when creating transport: <AMQPConnectionError: (61, "Connect call failed ('127.0.0.1', 5672)")>
Report: RabbitMQ server not found: falling back to ZMQ broker.
Warning: The ZMQ broker is a new feature. If you experience issues, recreate the profile with `verdi presto --no-broker`.
Exception ignored while calling deallocator <function Connection.__del__ at 0x105a44ca0>:
Traceback (most recent call last):
  File "/Users/mbercx/.aiida_venvs/qe-test/lib/python3.14/site-packages/aio_pika/connection.py", line 215, in __del__
    asyncio.ensure_future(self.close())
  File "/Users/mbercx/.local/share/uv/python/cpython-3.14.4-macos-aarch64-none/lib/python3.14/asyncio/tasks.py", line 730, in ensure_future
    loop = events.get_event_loop()
  File "/Users/mbercx/.local/share/uv/python/cpython-3.14.4-macos-aarch64-none/lib/python3.14/asyncio/events.py", line 715, in get_event_loop
    raise RuntimeError('There is no current event loop in thread %r.'
RuntimeError: There is no current event loop in thread 'MainThread'.
/Users/mbercx/.aiida_venvs/qe-test/lib/python3.14/site-packages/alembic/operations/base.py:27: RuntimeWarning: coroutine 'RobustConnection.close' was never awaited
  from . import batch
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
Report: Initialising the storage backend.
Report: Migrating to the head of the main branch
Report: Storage initialisation completed.
Success: Created new profile `presto`.
Success: Configured the localhost as a computer.

First commit fixes the RobustConnection.close. Second commit surpresses the error when creating transport: <AMQPConnectionError: (61, "Connect call failed ('127.0.0.1', 5672)")>

This PR replaces probably PR #7328 but need to verify.


Probe RabbitMQ connection parameters in an isolated event loop and close the temporary aio-pika connection explicitly, even when the connection attempt fails.

This avoids the Python 3.14 cleanup warning emitted by aio-pika's Connection.del when verdi presto falls back from a failed RabbitMQ probe to the ZMQ broker.

Add regression coverage for the failed probe path and verify that it no longer emits the ignored deallocator exception or unawaited coroutine warning.

@agoscinski agoscinski changed the title 🐛 Fix RabbitMQ probe cleanup on Python 3.14 (#7342) 🐛 Fix RabbitMQ probe cleanup on Python 3.14 Apr 28, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 28, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.25%. Comparing base (282fd72) to head (0271f90).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7342      +/-   ##
==========================================
+ Coverage   80.23%   80.25%   +0.02%     
==========================================
  Files         577      577              
  Lines       45478    45502      +24     
==========================================
+ Hits        36487    36515      +28     
+ Misses       8991     8987       -4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

agoscinski added a commit to agoscinski/aiida-core that referenced this pull request Apr 29, 2026
Probe RabbitMQ connection parameters in an isolated event loop and
close the temporary aio-pika connection explicitly, even when the
connection attempt fails.

This avoids the Python 3.14 cleanup warning emitted by
aio-pika's Connection.__del__ when verdi presto falls back from a
failed RabbitMQ probe to the ZMQ broker.

Add regression coverage for the failed probe path and verify that it
no longer emits the ignored deallocator exception or unawaited
coroutine warning.
@agoscinski agoscinski force-pushed the fix/rmq-autodetect-py314 branch from 25fcc1e to 1039c2d Compare April 29, 2026 08:02
agoscinski added a commit to agoscinski/aiida-core that referenced this pull request Apr 29, 2026
Probe RabbitMQ connection parameters in an isolated event loop and
close the temporary aio-pika connection explicitly, even when the
connection attempt fails.

This avoids the Python 3.14 cleanup warning emitted by
aio-pika's Connection.__del__ when verdi presto falls back from a
failed RabbitMQ probe to the ZMQ broker.

Add regression coverage for the failed probe path and verify that it
no longer emits the ignored deallocator exception or unawaited
coroutine warning.
@agoscinski agoscinski force-pushed the fix/rmq-autodetect-py314 branch from 1039c2d to bd1390e Compare April 29, 2026 10:48
agoscinski added a commit to agoscinski/aiida-core that referenced this pull request Apr 29, 2026
Probe RabbitMQ connection parameters in an isolated event loop and
close the temporary aio-pika connection explicitly, even when the
connection attempt fails.

This avoids the Python 3.14 cleanup warning emitted by
aio-pika's Connection.__del__ when verdi presto falls back from a
failed RabbitMQ probe to the ZMQ broker.

Add regression coverage for the failed probe path and verify that it
no longer emits the ignored deallocator exception or unawaited
coroutine warning.
agoscinski added a commit to agoscinski/aiida-core that referenced this pull request Apr 29, 2026
Probe RabbitMQ connection parameters in an isolated event loop and
close the temporary aio-pika connection explicitly, even when the
connection attempt fails.

This avoids the Python 3.14 cleanup warning emitted by
aio-pika's Connection.__del__ when verdi presto falls back from a
failed RabbitMQ probe to the ZMQ broker.

Add regression coverage for the failed probe path and verify that it
no longer emits the ignored deallocator exception or unawaited
coroutine warning.
agoscinski added a commit to agoscinski/aiida-core that referenced this pull request Apr 30, 2026
Probe RabbitMQ connection parameters in an isolated event loop and
close the temporary aio-pika connection explicitly, even when the
connection attempt fails.

This avoids the Python 3.14 cleanup warning emitted by
aio-pika's Connection.__del__ when verdi presto falls back from a
failed RabbitMQ probe to the ZMQ broker.

Add regression coverage for the failed probe path and verify that it
no longer emits the ignored deallocator exception or unawaited
coroutine warning.
agoscinski added a commit to agoscinski/aiida-core that referenced this pull request Apr 30, 2026
Temporarily raise the aiormq and aio-pika logger levels
while probing RabbitMQ connection parameters.

The failed probe path is expected during verdi presto fallback,
so the transport creation error should not be shown before the CLI
reports that it is switching to the ZMQ broker.

Extend the subprocess regression test to verify that the noisy
transport log is no longer emitted alongside the Python 3.14 cleanup
warnings.
agoscinski added a commit to agoscinski/aiida-core that referenced this pull request Apr 30, 2026
Move aio_pika imports from module level into _probe_rabbitmq_connection()
to avoid loading aio_pika on every verdi invocation, since
BROKER_DEFAULTS is imported at module level by CLI options.
@agoscinski agoscinski force-pushed the fix/rmq-autodetect-py314 branch from bd1390e to 5229304 Compare April 30, 2026 05:35
Copy link
Copy Markdown
Collaborator

@GeigerJ2 GeigerJ2 left a comment

Choose a reason for hiding this comment

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

OK, only one very nitpicky comment. Apart from that, you have pleased the pedantic review agent. Good job!

Comment thread src/aiida/brokers/rabbitmq/defaults.py Outdated
@@ -40,8 +86,6 @@ def detect_rabbitmq_config(
:raises ConnectionError: If the connection failed with the provided connection parameters
:returns: The connection parameters if the RabbitMQ server was successfully connected to, or ``None`` otherwise.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Pre-existing, but since the PR modifies this function: the docstring says "or None otherwise" but the function never returns None. It raises ConnectionError on failure (which all three callers — cmd_presto.py:242, cmd_profile.py:85, cmd_profile.py:174 — explicitly catch). The return type annotation -> dict[str, t.Any] is correct. Suggested fix:

:returns: The connection parameters with keys prefixed with ``broker_``.

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.

done

agoscinski added a commit to agoscinski/aiida-core that referenced this pull request Apr 30, 2026
Probe RabbitMQ connection parameters in an isolated event loop and
close the temporary aio-pika connection explicitly, even when the
connection attempt fails.

This avoids the Python 3.14 cleanup warning emitted by
aio-pika's Connection.__del__ when verdi presto falls back from a
failed RabbitMQ probe to the ZMQ broker.

Add regression coverage for the failed probe path and verify that it
no longer emits the ignored deallocator exception or unawaited
coroutine warning.
agoscinski added a commit to agoscinski/aiida-core that referenced this pull request Apr 30, 2026
Temporarily raise the aiormq and aio-pika logger levels
while probing RabbitMQ connection parameters.

The failed probe path is expected during verdi presto fallback,
so the transport creation error should not be shown before the CLI
reports that it is switching to the ZMQ broker.

Extend the subprocess regression test to verify that the noisy
transport log is no longer emitted alongside the Python 3.14 cleanup
warnings.
agoscinski added a commit to agoscinski/aiida-core that referenced this pull request Apr 30, 2026
Move aio_pika imports from module level into _probe_rabbitmq_connection()
to avoid loading aio_pika on every verdi invocation, since
BROKER_DEFAULTS is imported at module level by CLI options.
@agoscinski agoscinski force-pushed the fix/rmq-autodetect-py314 branch from 5229304 to 1a409af Compare April 30, 2026 11:08
@agoscinski agoscinski marked this pull request as ready for review April 30, 2026 11:23
Comment thread src/aiida/brokers/rabbitmq/defaults.py Outdated
@@ -40,8 +86,6 @@ def detect_rabbitmq_config(
:raises ConnectionError: If the connection failed with the provided connection parameters
:returns: The connection parameters if the RabbitMQ server was successfully connected to, or ``None`` otherwise.
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.

Suggested change
:returns: The connection parameters if the RabbitMQ server was successfully connected to, or ``None`` otherwise.
:returns: The connection parameters with keys prefixed with ``broker_``.

agoscinski added a commit to agoscinski/aiida-core that referenced this pull request Apr 30, 2026
Probe RabbitMQ connection parameters in an isolated event loop and
close the temporary aio-pika connection explicitly, even when the
connection attempt fails.

This avoids the Python 3.14 cleanup warning emitted by
aio-pika's Connection.__del__ when verdi presto falls back from a
failed RabbitMQ probe to the ZMQ broker.

Add regression coverage for the failed probe path and verify that it
no longer emits the ignored deallocator exception or unawaited
coroutine warning.
agoscinski added a commit to agoscinski/aiida-core that referenced this pull request Apr 30, 2026
Temporarily raise the aiormq and aio-pika logger levels
while probing RabbitMQ connection parameters.

The failed probe path is expected during verdi presto fallback,
so the transport creation error should not be shown before the CLI
reports that it is switching to the ZMQ broker.

Extend the subprocess regression test to verify that the noisy
transport log is no longer emitted alongside the Python 3.14 cleanup
warnings.
agoscinski added a commit to agoscinski/aiida-core that referenced this pull request Apr 30, 2026
Move aio_pika imports from module level into _probe_rabbitmq_connection()
to avoid loading aio_pika on every verdi invocation, since
BROKER_DEFAULTS is imported at module level by CLI options.
@agoscinski agoscinski force-pushed the fix/rmq-autodetect-py314 branch from 1a409af to 5539fd5 Compare April 30, 2026 13:11
agoscinski added a commit to agoscinski/aiida-core that referenced this pull request Apr 30, 2026
Probe RabbitMQ connection parameters in an isolated event loop and
close the temporary aio-pika connection explicitly, even when the
connection attempt fails.

This avoids the Python 3.14 cleanup warning emitted by
aio-pika's Connection.__del__ when verdi presto falls back from a
failed RabbitMQ probe to the ZMQ broker.

Add regression coverage for the failed probe path and verify that it
no longer emits the ignored deallocator exception or unawaited
coroutine warning.
agoscinski added a commit to agoscinski/aiida-core that referenced this pull request Apr 30, 2026
Temporarily raise the aiormq and aio-pika logger levels
while probing RabbitMQ connection parameters.

The failed probe path is expected during verdi presto fallback,
so the transport creation error should not be shown before the CLI
reports that it is switching to the ZMQ broker.

Extend the subprocess regression test to verify that the noisy
transport log is no longer emitted alongside the Python 3.14 cleanup
warnings.
agoscinski added a commit to agoscinski/aiida-core that referenced this pull request Apr 30, 2026
Move aio_pika imports from module level into _probe_rabbitmq_connection()
to avoid loading aio_pika on every verdi invocation, since
BROKER_DEFAULTS is imported at module level by CLI options.
@agoscinski agoscinski force-pushed the fix/rmq-autodetect-py314 branch from 5539fd5 to c5f7af2 Compare April 30, 2026 13:12
Probe RabbitMQ connection parameters in an isolated event loop and
close the temporary aio-pika connection explicitly, even when the
connection attempt fails.

This avoids the Python 3.14 cleanup warning emitted by
aio-pika's Connection.__del__ when verdi presto falls back from a
failed RabbitMQ probe to the ZMQ broker.

Add regression coverage for the failed probe path and verify that it
no longer emits the ignored deallocator exception or unawaited
coroutine warning.

Reviewed-by: Julian Geiger <julian.geiger@psi.ch>
Temporarily raise the aiormq and aio-pika logger levels
while probing RabbitMQ connection parameters.

The failed probe path is expected during verdi presto fallback,
so the transport creation error should not be shown before the CLI
reports that it is switching to the ZMQ broker.

Extend the subprocess regression test to verify that the noisy
transport log is no longer emitted alongside the Python 3.14 cleanup
warnings.

Reviewed-by: Julian Geiger <julian.geiger@psi.ch>
Move aio_pika imports from module level into _probe_rabbitmq_connection()
to avoid loading aio_pika on every verdi invocation, since
BROKER_DEFAULTS is imported at module level by CLI options.

Reviewed-by: Julian Geiger <julian.geiger@psi.ch>
@agoscinski agoscinski force-pushed the fix/rmq-autodetect-py314 branch from c5f7af2 to 0271f90 Compare April 30, 2026 13:13
@agoscinski agoscinski merged commit 2491deb into aiidateam:main Apr 30, 2026
7 of 8 checks passed
agoscinski added a commit that referenced this pull request Apr 30, 2026
Probe RabbitMQ connection parameters in an isolated event loop and
close the temporary aio-pika connection explicitly, even when the
connection attempt fails.

This avoids the Python 3.14 cleanup warning emitted by
aio-pika's Connection.__del__ when verdi presto falls back from a
failed RabbitMQ probe to the ZMQ broker.

Add regression coverage for the failed probe path and verify that it
no longer emits the ignored deallocator exception or unawaited
coroutine warning.

Reviewed-by: Julian Geiger <julian.geiger@psi.ch>
agoscinski added a commit that referenced this pull request Apr 30, 2026
Temporarily raise the aiormq and aio-pika logger levels
while probing RabbitMQ connection parameters.

The failed probe path is expected during verdi presto fallback,
so the transport creation error should not be shown before the CLI
reports that it is switching to the ZMQ broker.

Extend the subprocess regression test to verify that the noisy
transport log is no longer emitted alongside the Python 3.14 cleanup
warnings.

Reviewed-by: Julian Geiger <julian.geiger@psi.ch>
@agoscinski agoscinski deleted the fix/rmq-autodetect-py314 branch April 30, 2026 13:15
agoscinski added a commit to agoscinski/aiida-core that referenced this pull request Apr 30, 2026
Probe RabbitMQ connection parameters in an isolated event loop and
close the temporary aio-pika connection explicitly, even when the
connection attempt fails.

This avoids the Python 3.14 cleanup warning emitted by
aio-pika's Connection.__del__ when verdi presto falls back from a
failed RabbitMQ probe to the ZMQ broker.

Add regression coverage for the failed probe path and verify that it
no longer emits the ignored deallocator exception or unawaited
coroutine warning.

Reviewed-by: Julian Geiger <julian.geiger@psi.ch>
agoscinski added a commit to agoscinski/aiida-core that referenced this pull request Apr 30, 2026
Temporarily raise the aiormq and aio-pika logger levels
while probing RabbitMQ connection parameters.

The failed probe path is expected during verdi presto fallback,
so the transport creation error should not be shown before the CLI
reports that it is switching to the ZMQ broker.

Extend the subprocess regression test to verify that the noisy
transport log is no longer emitted alongside the Python 3.14 cleanup
warnings.

Reviewed-by: Julian Geiger <julian.geiger@psi.ch>
agoscinski added a commit to agoscinski/aiida-core that referenced this pull request Apr 30, 2026
Move aio_pika imports from module level into _probe_rabbitmq_connection()
to avoid loading aio_pika on every verdi invocation, since
BROKER_DEFAULTS is imported at module level by CLI options.

Reviewed-by: Julian Geiger <julian.geiger@psi.ch>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants