-
-
Notifications
You must be signed in to change notification settings - Fork 927
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
allow getting recoverable_connection_errors without an active transport #1471
Conversation
This pull request fixes 1 alert when merging c217795 into b71b421 - view on LGTM.com fixed alerts:
|
super().__init__(*args, **kwargs) | ||
|
||
self.connection_errors = ( | ||
if consul: |
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.
only 3 transports are subject to this adjustments?
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.
Yeah, I did a search for self.connection_errors
and self.channel_errors
, and looked at each of the transports.
For some reason, the librabbitmq and mongodb backends don't have the try/except ImportError:
logic and they don't use __init__
to fill in connection_errors
and channel_errors
.
@@ -571,6 +573,16 @@ class MyTransport(Transport): | |||
conn = Connection(transport=MyTransport) | |||
assert conn.channel_errors == (KeyError, ValueError) | |||
|
|||
def test_channel_errors__exception_no_cache(self): |
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.
beside the unit tests I would love to see integration tests for this
This pull request fixes 1 alert when merging a08d2ad into c4a8c2a - view on LGTM.com fixed alerts:
|
This pull request fixes 1 alert when merging a8a9913 into 6ddf940 - view on LGTM.com fixed alerts:
|
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.
with pytest.raises(KeyError):
self.channel._receive_one(self.channel.subclient)
assert not self.channel._in_listen
E assert not True
E + where True = <t.unit.transport.test_redis.Channel object at 0x7f8bf8d594d0>._in_listen
E + where <t.unit.transport.test_redis.Channel object at 0x7f8bf8d594d0> = <t.unit.transport.test_redis.test_Channel object at 0x7f8bf8d591d0>.channel
t/unit/transport/test_redis.py:582: AssertionError
This pull request fixes 1 alert when merging c2c6b1b into 4a6e164 - view on LGTM.com fixed alerts:
|
This pull request fixes 1 alert when merging c6052ff into 4a6e164 - view on LGTM.com fixed alerts:
|
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.
I would like to take some time & more eyes and trials before merging this. in the mean the you can push any improvements in mind. and most possibly the more integration tests the better IMHO
besides, do we need any docs changes to mention the adjustments being made? |
@pawl did you try this in any project with celery? i want to have some integration test for this |
This pull request fixes 1 alert when merging 448cdb9 into 47781af - view on LGTM.com fixed alerts:
|
@auvipy I added an integration test here: 448cdb9
Oops, should I be updating the changelog? I'm not aware of any documentation changes since old code should continue to work the same way, because the errors are still a class attribute on the same class. I'm not sure we need to document the removal of |
I've tested the change with this branch of my celery memory leak example repo. It's still able to recover from connection errors successfully after I restart redis. Also, it connects successfully on start-up. |
ok we are good to go |
decided to land this change on 5.3 for now, as it changes some behaviours, but if other core team members agree will end landing in 5.2.x bug fix release |
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.
I am not 100% sure but if I read correctly the code get_transport_cls()
needs a transport as string or type. Default value is None
which I am not sure will work.
kombu/kombu/transport/__init__.py
Lines 47 to 86 in b6b4408
def resolve_transport(transport=None): | |
"""Get transport by name. | |
Arguments: | |
transport (Union[str, type]): This can be either | |
an actual transport class, or the fully qualified | |
path to a transport class, or the alias of a transport. | |
""" | |
if isinstance(transport, str): | |
try: | |
transport = TRANSPORT_ALIASES[transport] | |
except KeyError: | |
if '.' not in transport and ':' not in transport: | |
from kombu.utils.text import fmatch_best | |
alt = fmatch_best(transport, TRANSPORT_ALIASES) | |
if alt: | |
raise KeyError( | |
'No such transport: {}. Did you mean {}?'.format( | |
transport, alt)) | |
raise KeyError(f'No such transport: {transport}') | |
else: | |
if callable(transport): | |
transport = transport() | |
return symbol_by_name(transport) | |
return transport | |
def get_transport_cls(transport=None): | |
"""Get transport class by name. | |
The transport string is the full path to a transport class, e.g.:: | |
"kombu.transport.pyamqp:Transport" | |
If the name does not include `"."` (is not fully qualified), | |
the alias table will be consulted. | |
""" | |
if transport not in _transport_cache: | |
_transport_cache[transport] = resolve_transport(transport) | |
return _transport_cache[transport] |
@matusvalo Line 606 in a9c4f98
It looks like |
Yeah you are right :-/. I missed that it is wrapped in the same class. Please ignore my comment. |
…rt (celery#1471) * allow getting recoverable_connection_errors without an active transport * move redis transport errors to class * move consul transport errors to class * move etcd transport errors to class * remove redis.Transport._get_errors and references in tests * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix flake8 errors * add integration test for redis ConnectionError Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
I was looking into solutions for the celery + redis memory leak issue and I was attempting to reduce the references to initialized
Transport
s.One thing I noticed was that you currently need at least one initialized
Transport
with an active connection to allow filling the cache forrecoverable_connection_errors
/recoverable_channel_errors
/connection_errors
/channel_errors
. It seems like it makes more sense to get the errors from theTransport
class without needing to initialize it (in case there are connection errors on the firstTransport
initialization).This doesn't fix the memory leak issue, but maybe this change is still worth making?