-
Notifications
You must be signed in to change notification settings - Fork 105
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
Client::disconnect is asynchronous #93
Comments
Should be easily fixable with https://github.com/clue/reactphp-block |
The synchronous client uses its own event loop implementation. I am not sure that reactphp-block can help here.
So the basic code for client disconnection is:
There’s one thing to add: If the client has no open channels, the
As of now, this probably is the correct way to disconnect a synchronous Bunny client. This is also exactly what the destructor does. PS: A related tip: If, for whatever reason, you are trying to disconnect a client that has already been unknowingly disconnected (eg. by running into the heartbeat timeout), the client will throw a You can catch this exception in your disconnection code, but if the client thinks that it is still connected when it is garbage-collected (eg. at the end of script execution), it tries to disconnect again within the destructor. This will lead to the same So it is probably a good idea to override the client’s state to “disconnected” when your code notices that there is no longer a connection.
|
Hi. As the title says,
Client::disconnect
is asynchronous (i.e. it returns before the connection is closed). While I don't think it is a problem for most use-cases, it can lead to hard-to-debug scenarios.In our scenario, we opened a new connection for each published message (naive implementation). Which worked fine until we started publishing many messages in one process, where we occasionally ran out of sockets (default limit on Linux is 1024). Figuring this out took me several hours and I fixed it by improving our implementation by using a single connection for all the published messages.
Originally, I though that this was a bug, but after looking into it more I discovered, that it's not so much a bug, but rather a misleading semantic of the
disconnect
method. To achieve synchronous disconnect, one has to make sure the client's destructor is called. Unfortunately, because there is a circular reference between the client and the channel, it does not happen by itself consistently.Here is an example which reproduces the issue:
As it is, it ends with:
The text was updated successfully, but these errors were encountered: