[MXS-3110] bad handshake error in maxscale 2.5.1 Created: 2020-08-13  Updated: 2020-09-22  Resolved: 2020-09-11

Status: Closed
Project: MariaDB MaxScale
Component/s: mariadbbackend, mariadbclient
Affects Version/s: 2.5.1
Fix Version/s: 2.5.4

Type: Bug Priority: Major
Reporter: Christopher E Bowen Assignee: Esa Korhonen
Resolution: Fixed Votes: 2
Labels: None
Environment:

Running rhel 7.8, php 7.1.30 from redhat software collections with mariadb 10.1 backends


Issue Links:
Duplicate
is duplicated by MXS-3171 PHP 7.2 + PDO - invalid HandShakeResp... Closed

 Description   

When attempting to connect to a db using php with either mysqli or PDO I get the errors

Fatal error: Uncaught PDOException: SQLSTATE[HY000] [1043] Bad handshake in /opt/app/etddev/releases/20200710192026/www/test1.php:4 Stack trace: #0 /opt/app/etddev/releases/20200710192026/www/test1.php(4): PDO->__construct('mysql:host=maxs...', '****', '*****') #1

{main}

thrown in /opt/app/etddev/releases/20200710192026/www/test1.php on line 4

And

Warning: mysqli::__construct(): (HY000/1043): Bad handshake in /opt/app/etddev/releases/20200710192026/www/test.php on line 11
Connection failed: Bad handshake

receptively

This is my config file

[maxscale]
threads=auto
admin_host=0.0.0.0
admin_secure_gui=false
log_debug=1

[mysqlcl-dev01]
type=server
address=10.76.10.171
port=3306
protocol=MariaDBBackend

[mysqlcl-dev02]
type=server
address=10.76.10.172
port=3306
protocol=MariaDBBackend

[mysqlcl-dev03]
type=server
address=10.76.10.173
port=3306
protocol=MariaDBBackend

[Galera-Monitor]
type=monitor
module=galeramon
servers=mysqlcl-dev01,mysqlcl-dev02,mysqlcl-dev03
user=monitor_user
password=************
monitor_interval=2000ms

[Splitter-Service]
type=service
router=readwritesplit
servers=mysqlcl-dev01,mysqlcl-dev02,mysqlcl-dev03
user=maxscale
password=***************
master_failure_mode=fail_on_write
master_reconnection=true

[Splitter-Listener]
type=listener
service=Splitter-Service
protocol=MariaDBClient
#protocol=MariaDBBackend
address=0.0.0.0
port=3306

We are attempting to switch from haproxy to maxscale after talk from your people



 Comments   
Comment by markus makela [ 2020-08-20 ]

Does this happen only with 2.5 or is 2.4 affected as well? If you haven't tried this with MaxScale 2.4, would it be possible for you to test it?

Comment by Christopher E Bowen [ 2020-08-20 ]

tested with the latest version of 2.4, maxscale-2.4.11-1.centos, and that works, went back to 2.5 and it failed still.

Comment by markus makela [ 2020-08-21 ]

OK, I think it's the improved protocol violation checks that are in MaxScale 2.5 that cause this problem. Some connectors (e.g. an old version of our JDBC connector) appear to send an extra byte that shouldn't be sent and MaxScale 2.5 refuses to accept this connection.

It might be that we'll have to accept this "broken" handshake that the client sends in order to be compatible with older connectors.

Comment by Alex [ 2020-08-23 ]

It works with PHP 5.6.40, but with PHP 7 does not.

Comment by markus makela [ 2020-08-24 ]

Woud you be able to provide a minimal example we could use to reproduce this?

Comment by Alex [ 2020-08-24 ]

<?
$db=mysqli_connect('10.0.0.1','mailsender','XXXXXX') or die ("Cannot connect to DB " . mysqli_connect_error() );
?>
PHP version 7.0.33

PHP Warning: mysqli_connect(): (HY000/1043): Bad handshake in /root/meshok/sendmail_now.php on line 24

Comment by markus makela [ 2020-08-24 ]

Perhaps this is a bug in the PHP implementation? I'm testing with PHP 7.4.9 (cli) (built: Aug 4 2020 08:28:13) ( NTS ) and I can't reproduce this with the latest 2.5 branch and MariaDB 10.4 backends.

alexcool what version of MariaDB are you using?

Comment by Alex [ 2020-08-24 ]

MariaDB 10.4.14
MaxScale 2.5.2

Debian

Same PHP connects to MariadDB directly just fine.

Comment by markus makela [ 2020-08-24 ]

Managed to reproduce this with PHP 7.0, newer versions don't seem to suffer from this problem. This seems to be a bug in the php-mysqlnd implementation of older versions of PHP 7. The client doesn't set the correct flags and proceeds to send a malformed handshake. This appears to be a problem in a few connectors so we might have to think about allowing this sort of behavior.

Comment by markus makela [ 2020-08-24 ]

This seems to have been fixed in PHP 7.2 and is only a problem with older versions. It looks like there's a relatively easy upgrade path that'll solve this problem which is why us solving this on the MaxScale end doesn't seem like a very good idea. I'll close this as Not a Bug since it's a problem with the connector and MaxScale is behaving correctly.

Comment by Esa Korhonen [ 2020-09-11 ]

Modified the protocol code to accept the buggy packets. Client attributes of such packets are not read as they are garbled.

Comment by Jan Kostroun [ 2020-09-22 ]

i have a same issue on:

MariDB 10.5.5 + Galera 4
MaxScale 2.5.3

Suse SLES 15 SP2
App: PHP 7.0.7

on MaxScale 2.4.11 works but after upgrade to 2.5.3 handshake error

Generated at Thu Feb 08 04:19:02 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.