Skip to content

Conversation

pfreixes
Copy link
Contributor

This PR tries to solve the issues raised by #732 regarding
the danger of disconnect clients from the ConnectionPool.disconnect
method executed by a Thread different that those ones that are in charge
of the connections.

Instead of call the Connection.disconnect method it uses the syscall
shutdown to leave the socket unusable. Once the connection tries to use
the socket, even when it is already blocked such us the PubSub pattern, it
gets a socket.error exception that will be cactched by the
Connection class to then raise an ConnectionError and disconnect the
socket in a clean and safe way.

The Client.execute_command function catches the ConnectionError exception
and tries to connect again and run the command that raised the error.

Worth mentioning that in the case of the Sentinel environment, if the disconnect was because of a
change of the Redis pool servers - perhaps the master went
down and a slave was promoted, the next command will be executed using a new connection that will take into account these changes.

pfreixes added 4 commits June 19, 2016 20:40
This PR tries to solve the issues raised by redis#732 regarding
the danger of disconnect clients from the `ConnectionPool.disconnect`
method executed by a Thread different that those ones that are in charge
of the connections.

Instead of call the `Connection.disconnect` method it uses the syscall
`shutdown` to leave the socket unusable. Once the connection tries to use
the socket, even when it is already blocked such us the `PubSub` pattern, it
gets a `socket.error` exception that will be cactched by the
`Connection` class to then raise an `ConnectionError` and disconnect the
socket in a clean and safe way.

The `Client.execute_command` function catches the `ConnectionError` exception
and tries to connect again and run the command that raised the error.
Worth mentioning that in the case of the `Sentinel` environment, if some
changes regarding the Redis pool of servers - perhaps the mater went
down and a slave was promoted - the next command will be executed using
an other server.
@pfreixes pfreixes closed this Jun 21, 2016
@pfreixes pfreixes deleted the pool_disconnect_thread_safe branch June 21, 2016 18:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants