[MXS-702] COMPRESS flag is not sent in the initial handshake Created: 2016-05-01  Updated: 2016-06-06  Resolved: 2016-06-06

Status: Closed
Project: MariaDB MaxScale
Component/s: mariadbclient
Affects Version/s: 1.4.1
Fix Version/s: N/A

Type: Task Priority: Minor
Reporter: Karl Assignee: Massimiliano Pinto (Inactive)
Resolution: Not a Bug Votes: 0
Labels: compression
Environment:

docker centos 7, containers: maxscale, 1 master, 2 slaves, nginx-php as web, some more for load balancing web


Sprint: 2016-11

 Description   

enter web container, create test file, switch $client_flags

<?php
 
$client_flags = 0; 
// works fine
 
// $client_flags = MYSQLI_CLIENT_COMPRESS;
// hangs
 
$mysqli = mysqli_init();
 
$mysqli->options(MYSQLI_OPT_CONNECT_TIMEOUT, 10);
 
$hostname = 'db';
$username = '***';
$password = '***';
$port = 3306;
$database = '***';
$socket = '';
 
$mysqli->real_connect($hostname, $username, $password, $database, $port, $socket, $client_flags);
 
if ($mysqli->connect_errno) {
    echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}
 
echo $mysqli->host_info . "\n";
 
$res = $mysqli->query("SELECT @@server_id id, @@hostname host");
 
 
while ($row = $res->fetch_assoc()) {
    echo " res = " . $row['id'] . ' : ' . $row['host'] . "\n";
}
 
?>



 Comments   
Comment by markus makela [ 2016-05-04 ]

The following test program seems to work as expected. Since MaxScale doesn't offer the COMPRESS flag in the handshake, the client doesn't use it.

#include <stdio.h>
#include <iostream>
#include <stdlib.h>
#include <mysql/mysql.h>
#include <string.h>
#include <unistd.h>
 
using namespace std;
#define CONNECTIONS 1
 
int main(int argc, char** argv)
{
    MYSQL *mysql;
    MYSQL_RES* result;
    MYSQL_ROW row;
    MYSQL_FIELD* fields;
 
    if ((mysql = mysql_init(NULL)) == NULL)
    {
        cout << "Failed initialize client library." << endl;
        return 1;
    }
 
    if (!mysql_real_connect(mysql, "127.0.0.1", "maxuser", "maxpwd", NULL, 4006, NULL, CLIENT_COMPRESS))
    {
        cout << "Failed to connect to database: " << mysql_error(mysql) << endl;
        mysql_close(mysql);
        return 1;
    }
 
    for (int i = 0; i < 1000; i++)
    {
        if(mysql_query(mysql, "SHOW DATABASES") == 0)
        {
            do
            {
                MYSQL_RES *res = mysql_store_result(mysql);
                mysql_free_result(res);
            }
            while (mysql_next_result(mysql) == 0);
        }
        else
        {
            cout << "Failed to execute query: " << mysql_error(mysql) << endl;
        }
    }
    mysql_close(mysql);
    return 0;
}

I'll investigate if PHP has different results.

Comment by markus makela [ 2016-05-06 ]

For some reason, mysqli doesn't honor the server capabilities and proceeds to send compressed data. This causes it to hang since MaxScale misinterprets the compression protocol packets.

Comment by Massimiliano Pinto (Inactive) [ 2016-06-06 ]

Adding:
print_r($mysqli);

after $mysqli->real_connect(...) gives on some systems:

[client_info] => 5.5.47-MariaDB

on others

[client_info] => mysqlnd 5.0.11-dev - 20120503 - $Id: 15d5c781cfcad91193dceae1d2cdd127674ddb3e $

The clients with "libmysqlnd" connect library are affected by this issue

Comment by Massimiliano Pinto (Inactive) [ 2016-06-06 ]

It's not a MaxScale bug, it's an issue with libmysqlnd libraries

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