The mariadb documentation says the default value for wait_timeout is 28800.
The container seems to have a value of 600 as default for the global variable.
Steps to reproduce
docker run -d --name mydb -it -e MYSQL_ROOT_PASSWORD=123456 mariadb
docker exec -it mydb bash
mysql -p123456
SHOW global VARIABLES LIKE "wait_timeout";
returns
| Variable_name | Value |
+---------------+-------+
| wait_timeout | 600 |
+---------------+-------+
expected
| Variable_name | Value |
+---------------+-------+
| wait_timeout | 28800 |
+---------------+-------+
This leads to problems with some other default configurations that assumes 8 hours timeout: In my case it was with flask-sqlalchemy that resets a timeout after 2 hours: https://github.com/mitsuhiko/flask-sqlalchemy/issues/91
I can confirm that it is happening, although I can't say why just yet:
$ docker pull mariadb:10
10: Pulling from library/mariadb
Digest: sha256:0b892e7e272381f95d74b1c01faf2ff57bdbb69489ff0dcf0f0e1f79006a916c
Status: Image is up to date for mariadb:10
$ docker run -dit --name mydb -e MYSQL_ROOT_PASSWORD=123456 mariadb:10
2081f0942aeb930ebed16bded4897b16956b7c5ce0e36234338cad35d036b553
$ docker exec -it mydb mysql -uroot -p123456
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 8
Server version: 10.2.6-MariaDB-10.2.6+maria~jessie mariadb.org binary distribution
Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> SHOW global VARIABLES LIKE 'wait_timeout';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| wait_timeout | 600 |
+---------------+-------+
1 row in set (0.00 sec)
MariaDB [(none)]>
Found it -- it's MariaDB's Debian package which sets this value: https://github.com/MariaDB/server/blob/5ff2db7f67401511b30dbd3fc69a1ea87d7e8cc4/debian/additions/my.cnf#L53
Closing since this is working-as-designed, but here's a simple workaround:
$ docker run -dit --name mydb -e MYSQL_ROOT_PASSWORD=123456 mariadb:10 --wait_timeout=28800
2e414afe04f4ed0bad8d13f41de2db77a0fe7abdc7570b714926354e95b64329
$ docker exec -it mydb mysql -uroot -p123456
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 8
Server version: 10.2.6-MariaDB-10.2.6+maria~jessie mariadb.org binary distribution
Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> SHOW global VARIABLES LIKE 'wait_timeout';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| wait_timeout | 28800 |
+---------------+-------+
1 row in set (0.00 sec)
MariaDB [(none)]>
How the above workaround should look in docker-compose? I tried:
command: mysqld --wait_timeout=28800
args:
- wait_timeout=28800
but w/o success.
I'd recommend something like the following:
```yaml
command: [
'--wait_timeout=28800',
]
Hey guys!
wait_timeout takes a different value depending if it's interactive or not.
If it's non-interactive, the value will be derived from the wait_timeout configuration parameter. Otherwise, it will be derived from the interactive_timeout configuration parameter, which is what you will see if you open a session with the mysql client.
Reference: https://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html#sysvar_wait_timeout
Hi all,
@tianon – many thanks, that helped!
@tanji – wait_timeout is what I really needed. The default value for the MariaDB container was 600 seconds, resulting in connection being closed every 10 minutes and sometimes a NodeJS worker not being restarted.
Seems like the workaround is not effective if MariaDB is deployed as Docker Swarm service.
More info
Closing since this is working-as-designed, but here's a simple workaround:
$ docker run -dit --name mydb -e MYSQL_ROOT_PASSWORD=123456 mariadb:10 --wait_timeout=28800 2e414afe04f4ed0bad8d13f41de2db77a0fe7abdc7570b714926354e95b64329 $ docker exec -it mydb mysql -uroot -p123456 Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 8 Server version: 10.2.6-MariaDB-10.2.6+maria~jessie mariadb.org binary distribution Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> SHOW global VARIABLES LIKE 'wait_timeout'; +---------------+-------+ | Variable_name | Value | +---------------+-------+ | wait_timeout | 28800 | +---------------+-------+ 1 row in set (0.00 sec) MariaDB [(none)]>
Thanks for the info that Docker overlay networks also be the cause of connection timeouts.
I'd strongly caution against using /sys/fs/cgroup/memory/memory.limit_in_bytes without first checking that it is a useful value. If the container doesn't have a limit set, it will probably be much larger than expected.
$ docker run --rm bash cat /sys/fs/cgroup/memory/memory.limit_in_bytes
9223372036854771712
$ docker run --rm bash cat /sys/fs/cgroup/memory/memory.limit_in_bytes | awk '{ print int($1/1024/1024/1024) }'
8589934591
$ # that's in GiB
$ docker run --rm bash cat /sys/fs/cgroup/memory/memory.limit_in_bytes | awk '{ print int($1/1024/1024/1024/1024/1024/1024) }'
7
$ # or ~7 Exabytes
Most helpful comment
I'd recommend something like the following:
```yaml
command: [
'--wait_timeout=28800',
]