-
-
Notifications
You must be signed in to change notification settings - Fork 933
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Close connections in case of an exception #2201
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add some tests to this please?
That confirms the bug fails without the fix on current main.
Thank you! 🙏
Sure, I'll also have a look at the tests that failed. |
You can run it locally with |
82e31c9
to
8869895
Compare
@Nusnus Thanks a lot for your tip with the tests! I added an integration test to the py_amqp tests that should fail without the change. |
f5f43c1
to
388b7c8
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2201 +/- ##
==========================================
+ Coverage 81.49% 81.50% +0.01%
==========================================
Files 77 77
Lines 9509 9522 +13
Branches 1148 1151 +3
==========================================
+ Hits 7749 7761 +12
Misses 1569 1569
- Partials 191 192 +1 ☔ View full report in Codecov by Sentry. |
d49e6f6
to
2c3bd2c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left some comments.
Good work 🔥
See also: |
d79f9dc
to
0839f26
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good
When an exception occurs while the connection is in use, the connection may become unsuable. Such connections need to be closed, such that the connection to the broker can be reestablished at a later point.
for more information, see https://pre-commit.ci
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved!
I also checked a patched Kombu vs all of Celery main
’s CI to make sure we won’t break anything there.
Everything passes.
Good work!
Merge once the CI here goes full green :)
* Close connections in case of an exception When an exception occurs while the connection is in use, the connection may become unsuable. Such connections need to be closed, such that the connection to the broker can be reestablished at a later point. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
* Close connections in case of an exception When an exception occurs while the connection is in use, the connection may become unsuable. Such connections need to be closed, such that the connection to the broker can be reestablished at a later point. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
* Close connections in case of an exception When an exception occurs while the connection is in use, the connection may become unsuable. Such connections need to be closed, such that the connection to the broker can be reestablished at a later point. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Fixes: celery/celery#9259
Issue
When an amqp exception occurs while a connection is in use, the connection becomes unusable. Any attempts to use the connection can potentially block indefinitely.
Currently, such broken connections are placed back into the connection pool, which causes a later
acquire
call on the pool to return a broken connection.Reproducer
See celery/celery#9259
When a celery app is created with the
confirm_publish=True
option, it is possible for a celery task's `apply_async' method to block indefinitely if a broken connection is retrieved from the connection pool.Fix
The
ProducerPool::acquire
andConnectionPool::acquire
method now return a wrappedConnection/Producer
, that ensures the connections are properly closed in case of an exception. A reproducer for the original bug was added as an integration test, to ensure that the fix worked.Additional comments
I believe there is a similar issue with the
ChannelPool
, but in this case I think it is not possible to simply close the connection, as other channels acquired from the pool may still be in use.