[debian-mysql] Bug#1154898: libmariadb3: query fails with Lost connection when option file sets max_allowed_packet
Aaron Boeker
aaron at maplecube.net
Sun Nov 22 21:06:23 GMT 2026
Package: libmariadb3
Version: 1:11.8.9+ds-0+deb13u1
Severity: normal
Dear maintainer,
after libmariadb3 was upgraded from 1:11.8.6-0+deb13u1 to
1:11.8.9+ds-0+deb13u1 on trixie, applications that connect through the
C API with the default option group read enabled fail their first
query: mysql_store_result() returns NULL with errno 2013
(CR_SERVER_LOST, "Lost connection to server during query"), although
the MariaDB server executes the statement normally and logs it.
Downgrading to 1:11.8.6-0+deb13u1 restores normal behaviour with no
other change. Removing the trigger setting from the option file also
restores normal behaviour while staying on 11.8.9+ds.
Where this was observed
-----------------------
The upgrade broke IMAP authentication on a mail server: Dovecot 2.4.5
using its MySQL SQL passdb/userdb reported "sql: unknown user" for
valid accounts, with repeated
sqlpool(mysql): Query failed, retrying: Server has gone away
warnings. The MariaDB general query log showed the connection being
established and the passdb statement executed normally, yet the client
saw no rows. A second machine with the same package set kept working
only because its Dovecot process had not been restarted since before
the library upgrade, so it was still running the old library from
memory.
Trigger conditions (all three required)
---------------------------------------
1. libmariadb3 1:11.8.9+ds-0+deb13u1, whose client library reports
Connector/C 3.4.10. 1:11.8.6-0+deb13u1 does not have the problem.
2. An option file in the default chain setting max_allowed_packet for
the client, for example:
[client]
max_allowed_packet = 128M
Any explicit value triggers the failure, including the default
sized 16M. With no such setting in the option files the failure
does not occur.
3. The application calls mysql_options(..., MYSQL_READ_DEFAULT_GROUP,
"client") before mysql_real_connect(). Dovecot's MySQL driver does
this unconditionally. The CLIENT_MULTI_RESULTS flag and connection
timeouts are not needed to trigger the failure.
Reproduction (validated, self-contained)
----------------------------------------
1. Apply the following schema on the MariaDB server to test against:
----- begin setup.sql -----
CREATE DATABASE reprodb;
USE reprodb;
CREATE TABLE mail_user (
email VARCHAR(255) NOT NULL,
login VARCHAR(255),
password VARCHAR(255),
maildir VARCHAR(255),
maildir_format VARCHAR(20) DEFAULT 'maildir',
uid INT,
gid INT,
quota BIGINT,
imap_prefix VARCHAR(50) DEFAULT NULL,
disableimap CHAR(1) DEFAULT 'n',
disablepop3 CHAR(1) DEFAULT 'n',
server_id INT,
PRIMARY KEY (email)
);
CREATE TABLE mail_domain (
domain_id INT AUTO_INCREMENT PRIMARY KEY,
domain VARCHAR(255),
active CHAR(1),
server_id INT
);
INSERT INTO mail_user (email, login, password, maildir, uid, gid, quota,
server_id) VALUES
('user22 at example.org', 'user22 at example.org',
'$5$rounds=10000$saltvalue12345$0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJK',
'/var/vmail/example.org/user22/Maildir', 5000, 5000, 1073741824, 1),
('user2 at example.org', 'user2 at example.org',
'$5$rounds=10000$saltvalue67890$9876543210zyxwvutsrqponmlkjihgfedcbaZYXWVUTSRQPONMLK',
'/var/vmail/example.org/user2/Maildir', 5000, 5000, 2147483648, 1),
('user3 at example.org', 'user3 at example.org',
'$5$rounds=10000$saltvaluexxxxx$0123456789abcdefghij0123456789abcdefghij012345',
'/var/vmail/example.org/user3/Maildir', 5000, 5000, 5368709120, 1);
INSERT INTO mail_domain (domain, active, server_id) VALUES
('example.org', 'y', 1);
CREATE USER 'repro'@'localhost' IDENTIFIED BY 'repro-pass';
GRANT SELECT ON reprodb.* TO 'repro'@'localhost';
FLUSH PRIVILEGES;
----- end setup.sql -----
2. Build the reproducer:
apt-get install -y libmariadb-dev gcc
gcc -O0 -o repro repro.c $(mariadb_config --cflags --libs)
with the following source:
----- begin repro.c -----
/*
* repro.c - libmariadb3 11.8.9+ds (Connector/C 3.4.10) result read
regression.
*
* Symptom: with the default option group read enabled, the first query
on a
* fresh connection fails in mysql_store_result() with errno 2013
* (CR_SERVER_LOST, "Lost connection to server during query"), while the
* server executes the statement normally. Without the option group read,
* the same query on the same connection parameters works.
*
* Trigger condition: an option file in the default chain (for example
* ~/.my.cnf) containing a client side max_allowed_packet setting, e.g.:
*
* [client]
* max_allowed_packet = 128M
*
* Any explicit value triggers the failure (16M included); with no such
* setting in the option files the failure does not occur. The program
* runs the same statement twice on two fresh connections:
* once without the option group read, once with it, and prints the
outcome.
*
* Build: gcc -O0 -o repro repro.c $(mariadb_config --cflags --libs)
* Usage: HOME=<dir> ./repro <user> <password> <database> [socketpath]
* HOME selects which option files the library reads.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <mysql.h>
static void run(int opts, const char *user, const char *pass, const char
*dbn,
const char *login, const char *sockpath)
{
printf("== opts=%d (option group read: %s)\n", opts, opts ? "on" :
"off");
MYSQL *db = mysql_init(NULL);
if (db == NULL) { printf("mysql_init failed\n"); return; }
if (opts)
mysql_options(db, MYSQL_READ_DEFAULT_GROUP, "client");
if (!mysql_real_connect(db, "localhost", user, pass, dbn, 3306,
sockpath, 0)) {
printf(" connect failed: errno=%u %s\n", mysql_errno(db),
mysql_error(db));
mysql_close(db);
return;
}
char q[2048];
snprintf(q, sizeof q,
"SELECT email as user, password, maildir as userdb_home, "
"CONCAT( maildir_format, ':', maildir, '/', "
"IF(maildir_format='maildir','Maildir',maildir_format)) as
userdb_mail, "
"uid as userdb_uid, gid as userdb_gid, "
"CONCAT(quota, 'B') AS userdb_quota_storage_size, "
"CONCAT(maildir, '/.sieve') as userdb_sieve, "
"NULLIF(imap_prefix, '') as \"userdb_namespace/inbox/prefix\" "
"FROM mail_user "
"WHERE (login = '%s' OR email = '%s') "
"AND `disableimap` = 'n' AND server_id = '1' "
"AND NOT EXISTS (SELECT domain_id FROM mail_domain "
"WHERE domain = '%.*s' AND active = 'n' AND server_id = 1)",
login, login, (int)(strchr(login,'@') - login),
strchr(login,'@') + 1);
if (mysql_real_query(db, q, strlen(q)) != 0) {
printf(" query failed: errno=%u %s\n", mysql_errno(db),
mysql_error(db));
} else {
MYSQL_RES *res = mysql_store_result(db);
if (res == NULL) {
printf(" store_result FAILED: errno=%u %s\n",
mysql_errno(db), mysql_error(db));
} else {
printf(" ok: %llu row(s)\n", (unsigned long
long)mysql_num_rows(res));
mysql_free_result(res);
}
}
mysql_close(db);
}
int main(int argc, char **argv)
{
if (argc < 5) {
fprintf(stderr, "usage: repro <user> <password> <database>
<login> [socketpath]\n");
return 2;
}
mysql_library_init(0, NULL, NULL);
run(0, argv[1], argv[2], argv[3], argv[4], argc >= 6 ? argv[5] : NULL);
run(1, argv[1], argv[2], argv[3], argv[4], argc >= 6 ? argv[5] : NULL);
mysql_library_end();
return 0;
}
----- end repro.c -----
3. Make the client read an option file setting max_allowed_packet, for
example in ~/.my.cnf:
[client]
max_allowed_packet = 16M
4. Run it against the unix socket:
HOME=$HOME ./repro repro repro-pass reprodb user22 at example.org \
/run/mysqld/mysqld.sock
Observed output with 1:11.8.9+ds-0+deb13u1:
== opts=0 (option group read: off)
ok: 1 row(s)
== opts=1 (option group read: on)
query failed: errno=2013 Lost connection to server during query
The same run with 1:11.8.6-0+deb13u1 succeeds in both cases, and with
1:11.8.9+ds-0+deb13u1 both cases succeed when the max_allowed_packet
line is removed from the option file. The failure is deterministic,
not intermittent, and does not depend on whether the query matches any
rows: a zero row result fails as well. It reproduces against both an
11.8.9 and an 11.8.6 server, so the server version is not decisive.
Field confirmation
------------------
On the host where this was found, an administrator's
max_allowed_packet = 128M line had been appended to the tail of
/etc/mysql/mariadb.cnf, after the !includedir lines, which places it in
the [client-server] group that client libraries also read. Removing
that line fixed the Dovecot authentication failures immediately while
staying on 11.8.9+ds, confirming the trigger in the field. The setting
itself was redundant: the server side value was already configured
under [mysqld].
Relation to other reports
-------------------------
The Debian bug cluster around this connector generation (#1139473,
#1141671, #1144671; upstream MariaDB Jira CONC-821) concerns
mysql_stmt_bind_result zeroing *length for temporal result columns on
the prepared statement API path. That was backported in
1:11.8.9+ds-2, which is in unstable and testing as 1:11.8.9+ds-4.
The failure described here is different in three ways: it occurs on
the plain query path (mysql_real_query and mysql_store_result, no
prepared statements involved), it is triggered by a client side
max_allowed_packet loaded from an option file, and it manifests as a
lost connection rather than zeroed result lengths. The ds-2 backport
therefore likely does not cover this case, and both stable and the
revisions that fixed the other reports remain affected.
Expected behaviour
------------------
Reading client options from option files, including max_allowed_packet,
must not break result reading. A legally configured option file
turning into lost connections, with the consumer seeing "server has
gone away" symptoms that point everywhere except at the option file,
makes this extremely hard to diagnose from the application side.
System information
------------------
Debian 13.8 (trixie), Linux 6.12 amd64, libc6 2.41-12+deb13u5,
mariadb-server 1:11.8.9+ds-0+deb13u1, unix socket transport without
TLS. Failure reproduced with the 11.8.9+ds client library only; the
11.8.6 client library never failed in any configuration tested.
More information about the pkg-mysql-maint
mailing list