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

redis's connection pool makes me wonder #2832

Closed
forthcoming opened this issue Jul 5, 2023 · 2 comments
Closed

redis's connection pool makes me wonder #2832

forthcoming opened this issue Jul 5, 2023 · 2 comments
Assignees
Labels
bug Bug

Comments

@forthcoming
Copy link

https://github.com/redis/redis-py/blob/master/redis/connection.py#L1515

def release(self, connection):
    self._checkpid()
    with self._lock:
        try:
            self._in_use_connections.remove(connection)
        except KeyError:
            pass

        if self.owns_connection(connection):
            self._available_connections.append(connection)
        else:
            # pool doesn't own this connection. do not add it back
            # to the pool and decrement the count so that another
            # connection can take its place if needed
            self._created_connections -= 1
            connection.disconnect()
            return

Since you don't own this connection, it means that the program has been fork, and _created_connections has been initialized to 0, why subtract 1 again?Can someone explain it to me?,thanks

@petyaslavova
Copy link
Collaborator

PR is created with a fix: #3514

petyaslavova added a commit that referenced this issue Feb 24, 2025
petyaslavova added a commit that referenced this issue Feb 24, 2025
…ed by connection pool connection(fixes issue #2832). (#3514)

* Removing decreasing of created connections count when releasing not owned by connection pool connection(#2832).

* Fixed another issue that was allowing adding connections to a pool owned by other pools. Adding unit tests.

* Fixing a typo in a comment
@petyaslavova
Copy link
Collaborator

Fixed with PR#3514

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug
Projects
None yet
Development

No branches or pull requests

3 participants