24

I have a problem with connectivity in docker. I use an official mysql 5.7 image and Prisma server. When I start it via prisma cli, that uses docker compose underneath (described here) everything works.

But I need to start this containers programmatically via docker api and in this case connections from app are dropped with [Note] Aborted connection 8 to db: 'unconnected' user: 'root' host: '164.20.10.2' (Got an error reading communication packets).

So what I doo:

  1. Creating a bridge network:

    const network = await docker.network.create({
    Name: manifest.name + '_network',
    IPAM: {
      "Driver": "default",
      "Config": [
        {
          "Subnet": "164.20.0.0/16",
          "IPRange": "164.20.10.0/24"
        }
      ]
    }});
    
  2. Creating mysql container and attaching it to network

    const mysql = await docker.container.create({
    Image: 'mysql:5.7',
    Hostname: manifest.name + '-mysql',
    Names: ['/' + manifest.name + '-mysql'],
    NetworkingConfig: {
      EndpointsConfig: {
        [manifest.name + '_network']: {
          Aliases: [manifest.name + '-mysql']
        }
      }
    },
    Restart: 'always',
    Args: [
      "mysqld",
      "--max-connections=1000",
      "--sql-mode=ALLOW_INVALID_DATES,ANSI_QUOTES,ERROR_FOR_DIVISION_BY_ZERO,HIGH_NOT_PRECEDENCE,IGNORE_SPACE,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_BACKSLASH_ESCAPES,NO_DIR_IN_CREATE,NO_ENGINE_SUBSTITUTION,NO_FIELD_OPTIONS,NO_KEY_OPTIONS,NO_TABLE_OPTIONS,NO_UNSIGNED_SUBTRACTION,NO_ZERO_DATE,NO_ZERO_IN_DATE,ONLY_FULL_GROUP_BY,PIPES_AS_CONCAT,REAL_AS_FLOAT,STRICT_ALL_TABLES,STRICT_TRANS_TABLES,ANSI,DB2,MAXDB,MSSQL,MYSQL323,MYSQL40,ORACLE,POSTGRESQL,TRADITIONAL"
    ],
    Env: [
      'MYSQL_ROOT_PASSWORD=secret'
    ]
    });
    
    await network.connect({
       Container: mysql.id
    });
    await mysql.start();
    
  3. Then I wait Mysql to boot, create needed databases and needed Prisma containers from prismagraphql/prisma:1.1 and start them. App server resolves mysql host correctly, but connections are dropped by mysql.

Telnet from app container to mysql container in 3306 port responds correctly:

J
5.7.21U;uH  Kem']#45T]2mysql_native_password

What am I doing wrong?

Terion
  • 2,396
  • 3
  • 28
  • 42

3 Answers3

1

Check the below:

  • max_allowed_packets
  • wait_timeout
  • net_read_timeout

Also monitor MySQL process list during the issue to identify timeouts.

Matt Ke
  • 3,599
  • 12
  • 30
  • 49
Vaibhav
  • 41
  • 3
0

Can you try some wait, it could be possible that application try to connect to mysql server before its ready to accept connection. To test this, add some wait on startup or run mysql followed by application as different deployments.

Akash Sharma
  • 721
  • 3
  • 6
0

The fix is to add --wait-timeout=28800 (or higher number) into MySQL arguments:

Args: [
  "mysqld",
  "--max-connections=1000",
  "--sql-mode=ALLOW_INVALID_DATES,ANSI_QUOTES,ERROR_FOR_DIVISION_BY_ZERO,HIGH_NOT_PRECEDENCE,IGNORE_SPACE,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_BACKSLASH_ESCAPES,NO_DIR_IN_CREATE,NO_ENGINE_SUBSTITUTION,NO_FIELD_OPTIONS,NO_KEY_OPTIONS,NO_TABLE_OPTIONS,NO_UNSIGNED_SUBTRACTION,NO_ZERO_DATE,NO_ZERO_IN_DATE,ONLY_FULL_GROUP_BY,PIPES_AS_CONCAT,REAL_AS_FLOAT,STRICT_ALL_TABLES,STRICT_TRANS_TABLES,ANSI,DB2,MAXDB,MSSQL,MYSQL323,MYSQL40,ORACLE,POSTGRESQL,TRADITIONAL",
  "--wait-timeout=28800" // 28800 sec = 8 hours
],

Reference: https://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html#sysvar_wait_timeout

But maybe it's wiser to find out what is the root cause for idle connections.

iqqmuT
  • 653
  • 6
  • 8