-
Notifications
You must be signed in to change notification settings - Fork 440
[amqp][lib] Improve heartbeat handling. Introduce heartbeat on tick. Fixes "Invalid frame type 65" and "Broken pipe or closed connection" #658
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
Conversation
This is a beautiful solution, Max. We didn't think of registering a tick function. |
@makasim elegant solution indeed! Could you please elaborate a bit on why it only "Fixes partly" both the |
@leonardogcsoares tick callback is not triggered if the script waits on an IO operation (for example it is mysql query that takes a long time to execute). So you could still miss a heartbeat and run into the issue. |
I see, so indeed for medium/quick consumers this is the perfect solution, but for longer-running processes you still run into the problem that PHP just doesn't allow truly asynchronous work (excluding the whole php-threads, or other work arounds). |
@leonardogcsoares The PR could fix IO issue too but would require a bit more work. Mainly by leveraging async sockets feature. |
/** | ||
* @group functional | ||
*/ | ||
class AmqpSubscriptionConsumerWithHeartbeatOnTickTest extends TestCase |
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 don't see where this test actually tests anything related to ticks. The test would also pass if no tick handler was registered. Or am I missing something?
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.
It contains decalre tricks
which triggers tick callback and therfor heartbeat logic.
Is there a better way to test it?
This is indeed a creative solution. We are using the amqp ext which suffers from the same heartbeat problem. Wouldn't it make sense to implement the same solution there? |
Unfortunately I don't see how to implement this for amqp ext as there does not seem to be any method to manually trigger a heartbeat. |
@Tobion there is an extension that fixes signal issues https://github.com/pdezwart/php-amqp#keeping-track-of-the-workers Have you seen\tried it? |
I don't see how this can solve the heartbeat problem. The problem is that the amqp ext connection does not allow to manually check heartbeats like done in this PR. |
php-amqplib comes with a heartbeat feature. It does not work at all, unreliable and broken. More in the post Keeping RabbitMQ connections alive in PHP.
This PR fixes it. You could wrap your long running code into
decalre(ticks=1) {}
. The number of ticks should be adjusted to your needs. Calling it at every tick is not good.Please note that it does not fix heartbeat issue if you spent most of the time on IO operation.
Fixes partly
Invalid frame type 65
issue.Fixes partly
Broken pipe or closed connection
issue.