Commit Graph

259 Commits

Author SHA1 Message Date
awmackowiak dcb43be891
Fix Redis connections after reconnect - consumer starts consuming the tasks after crash. (#2007)
* Add more logs

* Launch _on_connection_disconnect in Conection only if channel was added properly to the poller

* Prepare test which check the flow of the channel removal from poller

* Change the comment
2024-06-12 22:00:22 +06:00
FrankK-1234 1217865d40
ConnectionPool can't be used after .resize(..., reset=True) (resolves #2018) (#2024)
* ConnectionPool can't be used after .resize(..., reset=True) (resolves #2018)

* Update kombu/resource.py

---------

Co-authored-by: Asif Saif Uddin <auvipy@gmail.com>
2024-06-11 22:43:13 +03:00
FrankK-1234 30db054e57 fix flake-err: allow uses to disable broker heartbeats by not providing a timeout 2024-06-01 10:21:46 +06:00
FrankK-1234 83ad62072d enhance: allow uses to disable broker heartbeats by not providing a timeout (#1997,#1998) 2024-06-01 10:21:46 +06:00
FrankK-1234 aec8faf034 enable/fix test_etcd.py 2024-05-18 13:28:50 +06:00
huyenvu2101 4d281948f2 Fix: Fanout exchange messages mixed across virtual databases in Redis sentinel 2024-05-04 12:28:13 +06:00
Ville Lindholm 25d02e6e1d
add escape hatch for custom JSON serialization (#1955)
* add escape hatch for custom JSON serialization

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* fix lint

* fix pydocstyle

* fix whitespace

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Tomer Nosrati <tomer.nosrati@gmail.com>
Co-authored-by: Ville Lindholm <ville@lindholm.dev>
2024-03-13 13:52:42 +02:00
Julien Cosmao bda9a2f18e
Expose cancel callback from py-amqp channel.basic_consume (#1953)
When broker send Basic.cancel notification, py-amqp default behavior is
to raise a ConsumerCancelled exception. It is then treated as an error
even if connection and channel are still operationnal and connection
is closed.

Basic.cancel may be sent by broker when a queue is deleted or when
replicated queue leader change. py-amqp channel.basic_consume allow to
define a callback function on this event. It may be useful to register
this callback from kombu when consuming from a queue.

(cherry picked from commit e1fa168ace)
Signed-off-by: julien.cosmao <julien.cosmao@ovhcloud.com>

Co-authored-by: julien.cosmao <julien.cosmao@ovhcloud.com>
2024-03-09 10:23:22 +02:00
Christian Clauss 10f5c3fdd6
Upgrade to pytest v8 that remove nose compatibility (#1914) 2024-02-05 16:56:13 +02:00
ainscore 48f38779da
Always convert azureservicebus namespace to fully qualified (#1892)
* Always convert azureservicebus namespace to fully qualified

* Fix tests

* Format exception
2024-01-25 15:06:49 +01:00
Adam Sussman 159e9df430
Fix crash when using global_keyprefix with a sentinel connection (#1838)
* Fix partial closure error when instantiating redis pool for a global_keyprefix sentinel connection

* add tests for redis sentinel connection with global_keyprefix setting

* StrictRedis is deprecated, use Redis class

* add some resource cleanup

* add some resource cleanup
2024-01-09 09:28:22 +01:00
marnikow 0dec03da18
azure service bus: fix TypeError when using Managed Identities (#1825)
* azure servicebus: fix TypeError: argument of type 'DefaultAzureCredential' is not iterable

* Update t/unit/transport/test_azureservicebus.py

* Update t/unit/transport/test_azureservicebus.py

* Update t/unit/transport/test_azureservicebus.py

---------

Co-authored-by: Asif Saif Uddin <auvipy@gmail.com>
2023-12-29 10:15:35 +01:00
Alisson Claudino 8aff4e73cd
fix: freeze set during ticks iter in async hub (#1830)
* test: ticks set size changed during iteration in async hub

* fix: freeze set during ticks iter in async hub
2023-12-19 13:07:56 +02:00
Rafid K 6121539379
Use the correct protocol for SQS requests (#1807)
* Use the correct protocol for SQS requests

TL;DR - The use of boto3 in #1759 resulted in relying on blocking
(synchronous) HTTP requests, which caused the performance issue reported
in #1783.

`kombu` previously used to craft AWS requests manually as explained in
detail in #1726, which resulted in an outage when botocore temporarily
changed the default protocol to JSON (before rolling back due to the
impact on celery and airflow.) To fix the issue, I submitted #1759,
which changes `kombu` to use `boto3` instead of manually crafting AWS
requests. This way when boto3 changes the default protocol, kombu won't
be impacted.

While working on #1759, I did extensive debugging to understand the
multi-threading nature of kombu. What I discovered is that there isn't
an actual multi-threading in the true sense of the word, but an event
loop that runs on the same thread and process and orchestrate the
communication with SQS. As such, it didn't appear to me that there is
anything to worry about my change, and the testing I did didn't discover
any issue. However, it turns out that while kombu's event loop doesn't
have actual multi-threading, its [reliance on
pycurl](https://github.com/celery/kombu/blob/main/kombu/asynchronous/http/curl.py#L48)
(and thus libcurl) meant that the requests to AWS were being done
asynchronously. On the other hand, boto3 requests are always done
synchronously, i.e. they are blocking requests.

The above meant that my change introduced blocking on the event loop of
kombu. This is fine in most of the cases, since the requests to SQS are
pretty fast. However, in the case of using long-polling, a call to SQS's
ReceiveMessage can last up to 20 seconds (depending on the user
configuration).

To solve this problem, I rolled back my earlier changes and, instead, to
address the issue reported in #1726, I now changed the
`AsyncSQSConnection` class such that it crafts either a `query` or a
`json` request depending on the protocol used by the SQS client. Thus,
when botocore changes the default protocol of SQS to JSON, kombu won't
be impacted, since it crafts its own request and, after my change, it
uses a hard-coded protocol based on the crafted requests.

This solution shouldn't be the final solution, and it is more of a
workaround that does the job for now. The final solution should be to
completely rely on boto3 for any communication with AWS, and ensuring
that all requests are async in nature (non-blocking.) This, however, is
a fundamental change that requires a lot of testing, in particular
performance testing.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update kombu/asynchronous/aws/sqs/connection.py

* [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>
Co-authored-by: Asif Saif Uddin <auvipy@gmail.com>
2023-11-16 14:19:49 +06:00
jiangxianfu 3884eb9dd6
fix: redis requeue concurrency bug #1800 (#1805)
* fix: redis requeue concurrency bug  #1800

* fix: add unit test

* fix: update
2023-10-30 19:34:31 +06:00
Asif Saif Uddin 7187021ecc
using assert_called_once() in est__pop_ready_uses_lock (#1813) 2023-10-18 16:14:16 +06:00
Asif Saif Uddin 6c8e7e6b28
added Python 3.12 in the CI (#1812)
* added Python 3.12 in the CI

* try to make kafka work on py3.12

* skip kafka for the time being as it seems not woring with py3.12 yet

* using assert_called_once()
2023-10-18 15:50:39 +06:00
Peter Marheine 3ad075a536
Create a lock on cached_property if not present (#1811)
* Create a lock on cached_property if not present

This fixes #1804 (fixing breakage caused by use of undocumented
implementation details of functools.cached_property) by ensuring a lock
is always present on cached_property attributes, which is required to
safely support setting and deleting cached values in addition to
computing them on demand.

* Add a unit test for cached_property locking
2023-10-18 15:45:10 +06:00
Asif Saif Uddin 1dfe4f3c86
Revert "[fix #1726] Use boto3 for SQS async requests (#1759)" (#1799)
This reverts commit 862d0bc728.
2023-10-10 11:55:38 +06:00
Sergey Romanyuk 2454aa7a4d
Added as_uri method to MongoDB transport - Fixes #1795 (#1796)
* Added as_uri method to MongoDB transport, Added tests

* Make flake8 happy

* Removed unnecessary test
2023-10-04 23:00:35 +06:00
marnikow 0e445d108e
fix azure servicebus using managed identity support (#1801)
* azure servicebus: use DefaultAzureCredential in documentation

* azure servicebus: only use connection string when using sas key

* azure servicebus: add two small tests for paring of connection string

* azure servicebus: fix lint issues
2023-10-04 16:47:36 +06:00
flolas c18e9626e1 raise access denied error when ack 2023-09-04 02:16:00 +06:00
mbierma 492776eb7f
fix: Prevent redis task loss when closing connection while in poll (#1733)
* Catch brpop before closing connection

* Update unit test

---------

Co-authored-by: mbierma <3448579-mbierma@users.noreply.gitlab.com>
2023-08-15 10:16:49 +06:00
Rafid K 862d0bc728
[fix #1726] Use boto3 for SQS async requests (#1759)
* [fix #1726] Use boto3 for SQS async requests

* [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>
2023-06-27 10:06:41 +06:00
Tomer Nosrati 18edd4c848 Reverted unwanted constraint introduced in #1629 with max_retries not being able to be None (when it should) 2023-06-19 09:54:28 +06:00
Sebastian Kreft dd341709bf fix: allow deserializing any version of UUID
In PR #1575 a new serializer for UUIDs was introduced, however it fails when deserializing UUIDs which version is not within 1 and 5. Given that there's a new standard (https://datatracker.ietf.org/doc/html/draft-peabody-dispatch-new-uuid-format-04) ganining traction that introduces UUIDs v6, v7 and v8, we change the code to allow such versions.

In the test, we generate one UUID for each version using the package `uuid6` (https://github.com/oittaa/uuid6-python)
2023-06-15 18:57:24 +06:00
Tom Sparrow 5062d53f94
SQS: avoid excessive GetQueueURL calls by using cached queue url (#1621)
* Fix #1618: avoid re-fetching queue URL when we already have it

`_get_from_sqs` was unnecessarily calling `get_queue_url` every
time even though the only place which calls `_get_from_sqs`
(that is `_get_async`) actually already knows the queue URL.

This change avoids hundreds of `GetQueueUrl` AWS API calls per hour
when using this SQS backend with celery.

Also `connection` is set by the one-and-only caller (and `queue` is
actually the queue name string now anyway so couldn't ever have
`.connection`) so remove the None default and unused fallback code.

* Clarify that `_new_queue` returns the queue URL

It seems that prior to 129a9e4ed0 it returned a queue
object but this is no longer the case so update comments
variable names accordingly to make it clearer.

Also remove the incorrect fallback which cannot
be correct any more given the return value has to
be the queue URL which must be a string.

* Unit test coverage for SQS async codepath

This key code path (which as far as I can see is
the main route when using celery with SQS) was
missing test coverage.

This test adds coverage for:
`_get_bulk_async` -> `_get_async` -> `_get_from_sqs`
2023-04-19 10:01:07 +06:00
Francis Charette-Migneault f86f1fc6e1
fix mongodb transport obsolete calls (#1694)
* fix mongodb transport obsolete calls + add test mock specs to check valid methods

* fix linting
2023-04-18 10:54:17 +06:00
Ismael Jiménez Sánchez ff031f73f2
fix: handle keyerror in azureservicebus transport when message is not found in qos and perform basic_ack (#1691)
* fix: handle keyerror when message is not found in qos and perform basic_ack

* fix: added tests for basic_ack

* fix: limit line length
2023-04-11 22:33:26 +06:00
Maxwell Muoto 9659f11ae1
Deprecate pytz and use zoneinfo (#1680)
* Main

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Fix

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Fix

* Trigger Build

* Fix

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Fix

* Fix

* noqas

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Fix

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* remove unused noqa

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* re-add import

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Fix

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Fixes

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* use pytest-freezer (#1683)

* Main

* Trigger Build

* Fixes

* remove

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* lint

* Lint

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Asif Saif Uddin <auvipy@gmail.com>
2023-04-09 14:08:23 +06:00
Jason R. Coombs c310364cc0 Adapt the mock to correctly mock the behaviors as implemented on Python 3.10. Ref #1663. 2023-03-12 22:33:37 +06:00
Serhii Tereshchenko 6fe50f5985
refactor: Refactor utils/json (#1659)
* refactor: Refactor utils/json

* Update kombu/utils/json.py

* Update kombu/utils/json.py

* chore: Use older syntax (no walrus)

* chore: Update doscstrings

* chore: Fix pydocstyle complaints

* chore: Restore previous docstring
2023-03-02 16:18:21 +06:00
Jason Barnett d3ca0d562e azure service bus: add type annotations and use cached property 2023-01-05 00:34:46 +06:00
Jason Barnett 4fac6bc84c
add managed identity support to azure storage queue (#1631)
* add managed identity support to azure storage queue

* flake8 fixes
2022-12-27 00:51:47 +06:00
Tomer Nosrati 44025bfa52
Allowing `Connection.ensure()` to retry on specific exceptions given by policy (#1629)
* Added unit test: test_ensure_retry_errors_is_not_looping_infinitely()

* Added unit test: test_ensure_retry_errors_is_limited_by_max_retries()

* Added retry_errors arg to Connection.ensure() to allow applying retry policy for specific errors additionally
2022-12-18 12:34:57 +02:00
David Bossanyi 22b559684f
Allow azurestoragequeues transport to be used with Azurite emulator in docker-compose (#1611)
* Parse credential as a dict when using Azurite emulator

This more flexible credential allows the use of Azurite for integration testing in local docker-compose configurations.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Fix some lint errors

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2022-10-16 20:43:15 +06:00
Marti Raudsepp bfec7faf8d Fix errors from flake8 lint
Python's `del` is a statement, not a function, and doesn't need
parenthesis.
2022-10-12 20:47:19 +06:00
Marti Raudsepp 3a49533bc2
Add separate transport option for retry loop timeout (#1599)
* Add separate transport option for retry loop timeout

This only applies when using `Connect.default_channel`.

Before this change, the retry loop timeout was set equal to TCP connect timeout (`connect_timeout`), meaning when first connection attempt timeouted, no retry would be attempted.

Now if a new transport option `connect_total_timeout` is provided, this overrides `connect_timeout` for the retry loop (but not for TCP connect).

* Add tests

* Fix isort

* Rename to connect_retry_timeout

* Reformat

* connect_retry_timeout -> connect_retries_timeout

* Fix flake8
2022-10-12 19:41:04 +06:00
karajan1001 6ae9fac150 Solve Kombu filesystem transport not thread safe
partly fix: #398
1. add exclusive lock during the whole exchange file update.
2. add some unit test for file lock
2022-09-23 17:29:34 +06:00
Manuel Vázquez Acosta 2d88c43fef Make JSONEncoder keep the same type for date/datetime.
Otherwise Celery jobs start to get `datetime` in place of `date` and that
could lead to errors.

See https://github.com/celery/celery/issues/7754, related PR #1515.
2022-09-21 12:24:08 +06:00
Gao afcde0a0bd
Revert "Solve Kombu filesystem transport not thread safe (#1593)" (#1595)
This reverts commit 8699920e05.
2022-09-09 22:52:53 +06:00
Gao 8699920e05
Solve Kombu filesystem transport not thread safe (#1593)
* Solve Kombu filesystem transport not thread safe

fix: #398
Currently only write lock used in msg/exchange file written. Cause
reading in other thread got some incomplete result.

1. Add timeout for the lock acquire.
2. Add Share locks when reading message from filesystem.
3. Add a unit test for the `lock` and `unlock`
4. Add a unit test to test the lock during message processing.

* Replace deprecated function.
2022-09-07 21:54:28 +06:00
Shahar Lev 717ad3ddc9
hub: tick delay fix (#1587)
* hub: tick delay fix

todo and timer callbacks can perform actions that
require a tick callback to be executed right away
without polling.

the current order can cause issues
when using single worker with no prefetch (acks late).

related issue in celery:
https://github.com/celery/celery/issues/7718

* add unit test for hub delay fix

* [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>
2022-08-24 14:32:35 +06:00
Carlos Gottberg 10a673b17c
Avoid losing type of UUID when serializing/deserializing (#1575)
* Avoid losing type of UUID when serializing/deserializing

Serializing UUIDs as strs and deserializing them as strs can lead to
somewhat obscure bugs such as the one that led to the creation of this
PR in django-cacheback
https://github.com/codeinthehole/django-cacheback/pull/100 which some
would call unexpected behaviour.

After all, an UUID is altogether a different type from strs and if
bytes got their own serializer/deserializer for UUID the same logic
should apply.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update documentation for JSON serialization

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2022-07-17 23:09:40 +06:00
Dan Cecile 4440c649e0 Add WATCH to prefixed complex commands 2022-07-14 22:56:41 +06:00
eloranger 674a645356
Add support to SQS DelaySeconds (#1567)
* Add DelaySeconds to kwargs

* Add test

* add default value for DelaySeconds

* Fix tests and add check for properties

* Fix flake8 style issue

Co-authored-by: Edmund Lam <2623895+edmundlam@users.noreply.github.com>
2022-07-12 22:31:21 +06:00
dobosevych c4829754db
Datetime serialization and deserialization fixed (#1515)
* Datetime serialization and deserialization fixed

* Unit test fixed

* Unit test fixed

* Fixed pylint

* Added Undocumented Autodoc Modules

* Update kombu/utils/json.py

Co-authored-by: Omer Katz <omer.katz@omerkatz.com>

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Clean and freeze now

* Clean and freeze now

* Clean and freeze now

* Clean and freeze now

Co-authored-by: Asif Saif Uddin <auvipy@gmail.com>
Co-authored-by: Omer Katz <omer.katz@omerkatz.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2022-05-31 11:21:04 +06:00
Marcelo Trylesinski 0a2f54eac2
Annotate `abstract.py` (#1522)
* Annotate `abstract.py`

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* apply pre-commit

* Use quotes

* Add typing_extensions as requirement

* Add quotes

* Add quotes

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2022-05-15 13:17:49 +06:00
Jonas Miederer b3e89101dc
Upgrade Azure Storage Queues transport to version 12 (#1539)
* updated azurestoragequeues transport for azure-storage-queues v12 + added basic tests

* fixed flake8 issues

* pinned azure-storage-queue lib to >= v12.0.0

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* azure-storage-queue>=12.2.0

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Asif Saif Uddin <auvipy@gmail.com>
2022-04-23 14:15:49 +06:00
Marcelo Trylesinski 14d395aa85
Annotate `exceptions.py` and `clocks.py` (#1526)
* Annotate `exceptions.py`

* Annotate `clocks.py`
2022-04-18 18:52:26 +06:00