Frequent "Lost connection to MySQL server during query" (Got an error reading communication packets) errors


  • Used Zammad version: 5.0.3 on MySQL 5.7.37
  • Used Zammad installation type: Docker Swarm, image built from source
  • Operating system: Docker image built from ruby:2.7.4-slim
  • Browser + version: FF 96.0.2 (64-Bit)

Expected behavior:

Being able to leave app open in the browser in idle without getting errors when returning to it.

Actual behavior:

Getting Error 500 after 10-20 minutes in idle.

Steps to reproduce the behavior:

I finally upgraded from 3.3.0 to 5.0.3, but now I’m stuck with this problem:

  • Zammad works fine for about 10-20 minutes, then it seems to lose its connection to mysql, resulting in Error 500 in the GUI until doing a full refresh in the browser.

I’m running in a custom built docker image, which is very similar to zammad-docker-compose/containers/zammad, just using MySQL instead of Postgres. Instead of libpq-dev/libpq5 I install libmariadb-dev at build time and ruby-mysql2 at run time.

MySQL runs with these params:

    image: 'mysql:5.7.37'
    command: --character-set-client-handshake=FALSE --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci --max_allowed_packet=256M --innodb_fast_shutdown=0 --skip-character-set-client-handshake

I can log into Zammad, everything works fine. After a while, I get this in the mysql logs:

[Note] Aborted connection xxxx to db: 'zammad_prod' user: 'zammad' host: 'x.x.x.x' (Got an error reading communication packets)

Zammad still looking nice on the browser tab, but when I click something, like opening a ticket, I get

I, [2022-01-27T16:49:36.101374 #13-181240] INFO -- : Started POST "/api/v1/taskbar" for x.x.x.x at 2022-01-27 16:49:36 +0000
I, [2022-01-27T16:49:36.103534 #13-181340] INFO -- : Started GET "/api/v1/tickets/2642?all=true&_=1643297293802" for x.x.x.x at 2022-01-27 16:49:36 +0000
F, [2022-01-27T16:49:36.112024 #13-181340] FATAL -- :
[da32f6ef-4a58-4188-8766-14b6d4f06381] ActiveRecord::StatementInvalid (Mysql2::Error::ConnectionError: Lost connection to MySQL server during query):
[da32f6ef-4a58-4188-8766-14b6d4f06381] config/initializers/db_preferences.rb:14:in `block in <main>'
x.x.x.x - - [27/Jan/2022:16:49:36 +0000] "GET /api/v1/tickets/2642?all=true&_=1643297293802 HTTP/1.1" 500 46 "" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:96.0) Gecko/20100101 Firefox/96.0"

Zammad now displays various Error 500 messages. Once I fully refresh in the browser, all is fine again for 10-20 minutes, until the same as above happens again.

I worked through MySQL :: MySQL 5.7 Reference Manual :: B.3.2.7 MySQL server has gone away, tried increasing max_allowed_packet to 516M, which only leads to the same issue, just some minutes later.

I know there are not too many Zammad users on mysql, but has someone else possibly seen this behaviour? Anybody running Zammad 5.0.3 on MySQL 5.7.37 at all?

I found out that Zammad uses ruby gem mysql2 0.5.3 and I understand GitHub - brianmario/mysql2: A modern, simple and very fast Mysql library for Ruby - binding to libmysql in a way that mysql2 does not really support ruby 2.7 at this time. Could this be related?

Any help appreciated!


Sounds like a problem with your MySQL configuration for the connection pool. Have a look at the number of concurrent allowed connections and the number of persistent connections.

Depending on different options the MySQL service may consume a lot resources.
If you allow persistent connections the response will be faster as the connection is established, but when all connections are used, no new connections could be established. There a some settings which can help in this case.
Additional you might have a look at tuning primer which may help you to identify bottlenecks and the resources you may consume with the settings.

So I was able to isolate this issue, and suggest a possible fix here:

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.