-
Notifications
You must be signed in to change notification settings - Fork 68
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
Nullify connecting after canceling the timer #107
Conversation
@choval Thanks for spotting and your updated report! (original #106) Unfortunately, the PR still does not contain any tests, so it's a bit unclear what issue is being resolved here. Also, a test would help us to ensure we do not introduce any regressions in the future. The way I understand this piece of logic, your change should not change anything about the async behavior. The |
Ping @choval, can you update the status here, does the problem persist or did you mange to resolve this in the meantime? |
sorry, the problem persists, got stuck with work, give me this week i'll see if i can code this scenario, if not i'll ping back~ |
@clue I've managed to reproduce this, it takes a few hits.
The handler runs in two ticks, once for null assign, and then the if in a separate one, I believe due to the |
Please note that my PR doesn't fix it. |
@choval Thank you very much for the update, I can now reproduce this locally and I'm working on a fix for this 👍 Here's the updated gist to reproduce this 100%: <?php
require('vendor/autoload.php');
$user = 'test';
$pass = 'test';
$host = 'localhost';
$schema = 'test';
$idle = 0.05;
$uri = "{$user}:{$pass}@{$host}/{$schema}?idle={$idle}";
$loop = React\EventLoop\Factory::create();
$factory = new React\MySQL\Factory($loop);
$con = $factory->createLazyConnection($uri);
$conk = $factory->createLazyConnection($uri); // Separate connection to kill the first connection
// Chase the query to kill it, simulates a server side connection close
$kill_timer = $loop->addPeriodicTimer($idle/2, function() use ($conk) {
$conk->query('SHOW PROCESSLIST')
->then(function($cmd) use ($conk) {
foreach($cmd->resultRows as $row) {
if($row['Info'] == 'SELECT SLEEP(1)') {
$pid = $row['Id'];
$conk->query('KILL CONNECTION '.$pid);
}
}
});
});
$stream = $con->queryStream('SELECT SLEEP(1)');
$stream->on('data', 'var_dump');
$stream->on('error', function (Exception $e) {
echo 'stream error: ' . $e->getMessage() . PHP_EOL;
});
$stream->on('close', function () use ($loop, $kill_timer) {
echo 'closed stream' . PHP_EOL;
$loop->cancelTimer($kill_timer);
});
$loop->run(); |
@choval Again thanks for reporting! I was able to reproduce this and have just filed a fix in #110 It also looks like there might be a similar race condition in clue/reactphp-redis#87 and clue/reactphp-sqlite#23, so I'll look into this in follow-up PRs as well 👍 |
Thanks for all the awesome libraries! Im closing this PR as it doesn't fix anything :-) |
#106 (comment)
My previous pr would actually trigger a new connection when trying to idle it... This just moves nullifying
connecting
AFTER canceling theidleTimer
.I can't seem to reproduce this, it was a one time fluke, which resulted in a fatal error and killed the script.