Skip to content
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

Moved self._lock initialisation to Pool constructor #3473

Merged
merged 4 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion redis/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -1378,6 +1378,7 @@ def __init__(
# will notice the first thread already did the work and simply
# release the lock.
self._fork_lock = threading.Lock()
self._lock = threading.Lock()
self.reset()

def __repr__(self) -> (str, str):
Expand All @@ -1395,7 +1396,6 @@ def get_protocol(self):
return self.connection_kwargs.get("protocol", None)

def reset(self) -> None:
self._lock = threading.Lock()
Copy link
Contributor

Choose a reason for hiding this comment

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

... So the lock is not re-initialized anymore when calling reset()? Is that intentional?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Any reasons why we do need to re-initialised lock variable?

Copy link
Contributor

Choose a reason for hiding this comment

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

There's probably a reason for it to have been in reset(). I'd look at the call sites for reset() and figure it out from there...

self._created_connections = 0
self._available_connections = []
self._in_use_connections = set()
Expand Down
28 changes: 24 additions & 4 deletions tests/test_connection_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@

import pytest
import redis
from redis.connection import to_bool
from redis.utils import SSL_AVAILABLE

from .conftest import _get_client, skip_if_redis_enterprise, skip_if_server_version_lt
from redis.cache import CacheConfig
from redis.connection import CacheProxyConnection, Connection, to_bool
from redis.utils import HIREDIS_AVAILABLE, SSL_AVAILABLE

from .conftest import (
_get_client,
skip_if_redis_enterprise,
skip_if_resp_version,
skip_if_server_version_lt,
)
from .test_pubsub import wait_for_message


Expand Down Expand Up @@ -196,6 +202,20 @@ def test_repr_contains_db_info_unix(self):
expected = "path=abc,db=0,client_name=test-client"
assert expected in repr(pool)

@pytest.mark.skipif(HIREDIS_AVAILABLE, reason="PythonParser only")
@pytest.mark.onlynoncluster
@skip_if_resp_version(2)
@skip_if_server_version_lt("7.4.0")
def test_initialise_pool_with_cache(self, master_host):
pool = redis.BlockingConnectionPool(
connection_class=Connection,
host=master_host[0],
port=master_host[1],
protocol=3,
cache_config=CacheConfig(),
)
assert isinstance(pool.get_connection("_"), CacheProxyConnection)


class TestConnectionPoolURLParsing:
def test_hostname(self):
Expand Down
Loading