Laravel: General error: 1835 Malformed communication packet after MariaDB update

MariaDB update to 10.2.35 is causing the following MySQL error on Laravel with PHP <= 7.2. cPanel servers on automatic updates have all been updated to this MariaDB version last night.

Laravel error

SQLSTATE[HY000]: General error: 1835 Malformed communication packet {"exception":"[object] (PDOException(code: HY000): SQLSTATE[HY000]: General error: 1835 Malformed communication packet at /laravel/vendor/laravel/framework/src/Illuminate/Database/Connectors/MySqlConnector.php:57 

cPanel MariaDB auto-update

root@sh1 [~]# tail -n 6 /var/log/yum.log
Nov 04 03:04:49 Updated: MariaDB-common-10.2.35-1.el6.x86_64
Nov 04 03:04:51 Updated: MariaDB-compat-10.2.35-1.el6.x86_64
Nov 04 03:05:03 Updated: MariaDB-client-10.2.35-1.el6.x86_64
Nov 04 03:05:59 Updated: MariaDB-server-10.2.35-1.el6.x86_64
Nov 04 03:06:00 Updated: MariaDB-shared-10.2.35-1.el6.x86_64
Nov 04 03:06:02 Updated: MariaDB-devel-10.2.35-1.el6.x86_64 

Workaround with PHP version

Upgrade your PHP to 7.3 or 7.4. This should fix the issue.

Workaround with Laravel

# git diff
diff --git a/config/database.php b/config/database.php
index 18aaef6..ba01c92 100644
--- a/config/database.php
+++ b/config/database.php
@@ -52,6 +52,7 @@ return [
             'prefix' => '',
             'strict' => false,
             'engine' => null,
+            'options' => [PDO::ATTR_EMULATE_PREPARES => true],
         ],
     ], 

Error should go away with this workaround. Note that there may be security concerns with this option and it could also cause issues, test it carefully. Upgrading PHP version is a better path.

Issue updates

This bug as been fixed by MariaDB with the following releases: 10.2.36, 10.3.27, 10.4.17, 10.5.8