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
Breaking changes with pcntl signals on channel->wait function
, when using non_blocking: false
#1135
Comments
I guess You can solve this by enabling async signals with |
channel->wait function
, when using non_blocking: true
channel->wait function
, when using non_blocking: true
channel->wait function
, when using non_blocking: false
Thank you for suggestion, it is already set to true. Sorry for not being able to provide steps to reproduce right now, i will provide them when the time allows me. Note: Updated the title, added clarifications that this happens only when the value of |
Can You clarify the problem, please? Signal handler is not invoked in time? Or You expect that |
BTW, if Your intention is to stop consuming as soon as possible, then probably it would be better to use method |
Script to reproduce: <?php
use PhpAmqpLib\Connection\AMQPStreamConnection;
use PhpAmqpLib\Message\AMQPMessage;
use PhpAmqpLib\Exception\AMQPTimeoutException;
require_once __DIR__ . '/vendor/autoload.php';
$connection = new AMQPStreamConnection(
'host',
5672,
'user',
'pass',
'/',
false,
'AMQPLAIN',
null,
'en_US',
3.0,
3.0,
null,
false,
0,
);
$channel = $connection->channel();
$channel->queue_declare('test');
$basicConsumer = $channel->basic_consume(
'test',
'test',
false,
false,
false,
false,
function (AMQPMessage $amqpMessage) {
// Process message
}
);
pcntl_signal(SIGALRM, static function ($signal) use ($channel, $basicConsumer) {
if (SIGALRM === $signal) {
var_dump('signal SIGALRM received');
$channel->basic_cancel($basicConsumer);
$channel->close();
}
});
pcntl_async_signals(true);
pcntl_alarm(2);
$idleTimeout = 5;
while ($channel->is_consuming()) {
var_dump('while is consuming...');
try {
var_dump('started waiting...');
$channel->wait(null, false, $idleTimeout);
var_dump('finished waiting...');
} catch (AMQPTimeoutException) {
break;
// Expected, this is idle timeout.
}
}
var_dump('finished consuming');
if ($channel->is_open()) {
$channel->basic_cancel($basicConsumer);
$channel->close();
}
var_dump('the end'); With 3.5.4 the output is:
With 3.6.0 the output is:
Bit of context:
|
Well, we had a bigger problem with previous versions, more context in #1094 and #1118 |
I don't have nearly as much experience with this as @ramunasd, but, based on the code provided by @cosminardeleanu, version 3.6.0 is behaving correctly. You specify a 5 second timeout, which is what you get with the new release. |
I feel that your approach is wrong. Consider some silly real life correlations: v.3.5.4
v.3.6.0
Is similar when you're working in kube / cloud:
As i said, this is not only related to signal alrm, but sigterm, sigint, etc, whatever signal you decide to handle. TLDR; Your reasoning/fixes does not change the fact these are breaking changes, in a minor version. |
You told A but skipped B. Consumer never knows what signal means. It might be termination signal, but also might be heartbeat sender or totally unrelated thing. In heartbeat case we must send special frame and continue read operation. So everything is not so simple as party/police example :) If You want have more responsive consumer, then use lower read timeout. It's simple like that:
Additional exception would be breaking change, that's for sure. Anyway, a term "breaking change" have many interpretations. I've seen many discussions regarding exact meaning of that term. I personally use idea that "breaking change" breaks compatibility and requires adoption. |
Version(s) affected: 3.6.0
Description
pcntl_alarm
no longer work as expected, compared with 3.5.4, it is no longer triggered immediately.Possible other signals may be affected.
How to reproduce
I don't have exact steps to reproduce right now, but i assume:
exit(0);
in the handler code.I would expect this to be a major version, because of these breaking changes.
The text was updated successfully, but these errors were encountered: