php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #81335 PHP Warning, Packets out of order after connection timeout
Submitted: 2021-08-06 10:37 UTC Modified: 2021-09-14 12:27 UTC
Votes:65
Avg. Score:4.4 ± 0.8
Reproduced:64 of 64 (100.0%)
Same Version:28 (43.8%)
Same OS:25 (39.1%)
From: bohuslav at simek dot si Assigned:
Status: Verified Package: PDO MySQL
PHP Version: 7.4.22 OS: Alpine Linux 3.14
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: bohuslav at simek dot si
New email:
PHP Version: OS:

 

 [2021-08-06 10:37 UTC] bohuslav at simek dot si
Description:
------------
After migration from MySQL 8.0.23 to 8.0.25 a warning "Packets out of order. Expected 1 received 0. Packet size=145" will be shown after MySQL connection timeout. mysqlnd is used a as connection library.

pdo_mysql

PDO Driver for MySQL => enabled
Client API version => mysqlnd 8.0.8

I don't want to speculate, but this can be caused by changes introduce in Connection Management by MySQL 8.0.24 (https://dev.mysql.com/doc/relnotes/mysql/8.0/en/news-8-0-24.html header Connection Management Notes) as MySQL now provides reason why client has been disconnected.



Test script:
---------------
<?php declare(strict_types=1);

$options = [
    PDO::ATTR_ERRMODE            => PDO::ERRMODE_EXCEPTION,
    PDO::ATTR_PERSISTENT         => false,
    PDO::MYSQL_ATTR_INIT_COMMAND => 'SET time_zone = "UTC"',
    PDO::ATTR_EMULATE_PREPARES   => true,
];

$pdo = new PDO(
    'mysql:dbname=unit_tests;host=mysql-test;port=3306;charset=utf8mb4',
    'root',
    '',
    $options
);

$pdo->exec('SET SESSION wait_timeout=1');
sleep(3);
$pdo->exec('SELECT 123'); // PHP Warning:  Packets out of order. Expected 1 received 0. Packet size=145


Expected result:
----------------
warning "Packets out of order. Expected 1 received 0. Packet size=145" should not happen.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-08-06 12:43 UTC] dharman@php.net
-Status: Open +Status: Verified
 [2021-08-06 12:43 UTC] dharman@php.net
Thanks for reporting. This indeed should be fixed in mysqlnd. Tested on git.master and the mysqlnd client doesn't notice the connection has dropped when sending a query.
 [2021-08-06 18:16 UTC] cmb@php.net
With MySQL 5.6.44 and 8.0.19 I get:
SQLSTATE[HY000]: General error: 2006 MySQL server has gone away

I'm waiting for the update to 8.0.26 to finish for about eight
hours now.  I'll test with that version when it's finished (if it
ever finishes).
 [2021-09-14 12:27 UTC] cmb@php.net
Oops, forgot about this.  Anyway, result with git-master and MySQL
8.0.26:

SQLSTATE[HY000]: General error: 2006 MySQL server has gone away

Is this Linux specific?
 [2021-09-30 20:23 UTC] vovikems at gmail dot com
Having same error using official docker images: php:8.0.9-cli and mysql:8.0.26. Typically this error seen on first DB query since long time (about 10h-15h) keeping DB connection without any query sent. Next query is always ok.
FYI i'm using long-running php application (RoadRunner, Spiral Framework, CycleORM).
 [2022-03-07 16:20 UTC] maurice dot volaski at einsteinmed dot edu
I am seeing this on my Mac with PHP 8.1.2 (Apache module) and MySQL 8.0.28 Homebrew.
 [2022-09-06 14:06 UTC] peter dot maatman at rentman dot nl
We are seeing this issue appear in production after we started migrating our production database servers from mysql 8.0.19 to 8.0.28.

Our php version currently is 7.4.16 with pdo_mysql enabled, we run our php in a docker container based on the official php:7.4-fpm image.

I can confirm that the test script reproduces the bug.
 [2022-11-03 15:22 UTC] addi dot hurz at gmail dot com
macOS 12.5.1 with arm CPU _ PHP 8.1.12 _ MySQL 8.0.31 all installed and freshly updated with homebrew

script still produces:

Warning: Packets out of order. Expected 1 received 0. Packet size=145

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 2006 MySQL server has gone away
 [2022-11-08 22:42 UTC] johnnywalker at gmail dot com
I can confirm script failing in 2 different setups with Php 7.4.3

## Setup 1 ##
Mysql Server version: 8.0.31
Distribution:         Ubuntu 20.04.5
Linux Kernel:         5.15.0
Php Version:          7.4.3

PHP Warning:  Packets out of order. Expected 1 received 0. Packet size=145 in...


## Setup 2 ##
Mysql Server version: 8.0.30
Distribution:         Ubuntu 20.04.5 LTS
Linux Kernel:         5.4.0
Php Version:          7.4.3

PHP Warning:  Packets out of order. Expected 1 received 0. Packet size=145 in...
 [2023-02-08 12:01 UTC] jeka dot corvus at gmail dot com
I have the same error 

docker image: php:8.2-fpm-alpine - php 8.2.2
docker image: percona-server:8.0 - mysql:8.0.30
Linux Kernel: 5.15.49

PHP Warning:  Packets out of order. Expected 1 received 0. Packet size=145
 [2023-04-06 20:32 UTC] adrien at poupa dot net
We are seeing the same problem after migrating to MySQL 8.0.28. However in our case it makes sense: we are using persistent connections, and this is happening after the server closed the connection.

My fix would have been to retry to connect when this happens; however even with mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT); I am not able to catch this as the warning is always reported and the exception is 2006 - MySQL has gone away. It should trigger a catchable exception in my opinion.
 [2023-05-26 14:48 UTC] pgolovin at gmail dot com
Have the same problem:
- PHP 8.1.15
- MySQL 8.0.32
- CentOS Linux release 7.7.1908
 
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Mon Jun 05 05:03:39 2023 UTC