Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash when entrypoint inits database and passing init-connect argument with whitespace #574

Open
Alex1s opened this issue May 5, 2024 · 2 comments

Comments

@Alex1s
Copy link
Contributor

Alex1s commented May 5, 2024

Use this docker-compose.yaml

services:
  sql:
    image: docker.io/mariadb:10.11.7
    ports:
    - "3306:3306"
    environment:
      - MYSQL_USER=${MYSQL_USER:?}
      - MYSQL_DATABASE=${MYSQL_DATABASE:?}
      - MYSQL_PASSWORD=${MYSQL_PASSWORD:?}
      - MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD:?}
    command:
      - "--default-time-zone=Europe/Berlin"
      - "--character-set-server=utf8mb4"
      - "--collation-server=utf8mb4_unicode_520_ci"
      - "--init-connect=SET NAMES utf8mb4 COLLATE utf8mb4_unicode_520_ci"
    volumes:
      - "database:/var/lib/mysql"
      - sql-backup-load-vol:/docker-entrypoint-initdb.d

and make sure the database volume is empty while the sql-backup-load-vol volume contains a backup.sql.xz file.

Then following error will be produced:

sql-1  | 2024-05-05T16:48:40+02:00 2024-05-05 14:48:40+00:00 [Note] [Entrypoint]: Entrypoint script for MariaDB Server 1:10.11.7+maria~ubu2204 started.
sql-1  | 2024-05-05T16:48:42+02:00 2024-05-05 14:48:42+00:00 [Warn] [Entrypoint]: /sys/fs/cgroup///memory.pressure not writable, functionality unavailable to MariaDB
sql-1  | 2024-05-05T16:48:42+02:00 2024-05-05 14:48:42+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
sql-1  | 2024-05-05T16:48:43+02:00 2024-05-05 14:48:43+00:00 [Note] [Entrypoint]: Entrypoint script for MariaDB Server 1:10.11.7+maria~ubu2204 started.
sql-1  | 2024-05-05T16:48:48+02:00 2024-05-05 14:48:48+00:00 [Note] [Entrypoint]: Initializing database files
sql-1  | 2024-05-05T16:48:50+02:00 2024-05-05 14:48:50 0 [Warning] mariadbd: io_uring_queue_init() failed with ENOSYS: check seccomp filters, and the kernel version (newer than 5.1 required)
sql-1  | 2024-05-05T16:48:50+02:00 2024-05-05 14:48:50 0 [Warning] InnoDB: liburing disabled: falling back to innodb_use_native_aio=OFF
sql-1  | 2024-05-05T16:48:51+02:00 /usr/sbin/mariadbd: Too many arguments (first extra is 'NAMES').
sql-1  | 2024-05-05T16:48:51+02:00 2024-05-05 14:48:51 0 [ERROR] Aborting
sql-1  | 2024-05-05T16:48:54+02:00
sql-1  | 2024-05-05T16:48:54+02:00 Installation of system tables failed!  Examine the logs in
sql-1  | 2024-05-05T16:48:54+02:00 /var/lib/mysql/ for more information.
sql-1  | 2024-05-05T16:48:54+02:00
sql-1  | 2024-05-05T16:48:54+02:00 The problem could be conflicting information in an external
sql-1  | 2024-05-05T16:48:54+02:00 my.cnf files. You can ignore these by doing:
sql-1  | 2024-05-05T16:48:54+02:00
sql-1  | 2024-05-05T16:48:54+02:00     shell> /usr/bin/mariadb-install-db --defaults-file=~/.my.cnf
sql-1  | 2024-05-05T16:48:54+02:00
sql-1  | 2024-05-05T16:48:54+02:00 You can also try to start the mariadbd daemon with:
sql-1  | 2024-05-05T16:48:54+02:00
sql-1  | 2024-05-05T16:48:54+02:00     shell> /usr/sbin/mariadbd --skip-grant-tables --general-log &
sql-1  | 2024-05-05T16:48:54+02:00
sql-1  | 2024-05-05T16:48:54+02:00 and use the command line tool /usr/bin/mariadb
sql-1  | 2024-05-05T16:48:54+02:00 to connect to the mysql database and look at the grant tables:
sql-1  | 2024-05-05T16:48:54+02:00
sql-1  | 2024-05-05T16:48:54+02:00     shell> /usr/bin/mariadb -u root mysql
sql-1  | 2024-05-05T16:48:54+02:00     MariaDB> show tables;
sql-1  | 2024-05-05T16:48:54+02:00
sql-1  | 2024-05-05T16:48:54+02:00 Try '/usr/sbin/mariadbd --help' if you have problems with paths.  Using
sql-1  | 2024-05-05T16:48:54+02:00 --general-log gives you a log in /var/lib/mysql/ that may be helpful.
sql-1  | 2024-05-05T16:48:54+02:00
sql-1  | 2024-05-05T16:48:54+02:00 The latest information about mysql_install_db is available at
sql-1  | 2024-05-05T16:48:54+02:00 https://mariadb.com/kb/en/installing-system-tables-mysql_install_db
sql-1  | 2024-05-05T16:48:54+02:00 You can find the latest source at https://downloads.mariadb.org and
sql-1  | 2024-05-05T16:48:54+02:00 the maria-discuss email list at https://launchpad.net/~maria-discuss
sql-1  | 2024-05-05T16:48:54+02:00
sql-1  | 2024-05-05T16:48:54+02:00 Please check all of the above before submitting a bug report
sql-1  | 2024-05-05T16:48:54+02:00 at https://mariadb.org/jira
sql-1  | 2024-05-05T16:48:54+02:00

When the database is already init, this error does not occur. I think it is a problem with the entrypoint script, at the point where it tries to init the database and properly handling the whitespace of the init-connect argument.

@Alex1s
Copy link
Contributor Author

Alex1s commented May 5, 2024

So it seems that the docker-entrypoint.sh properly passes the arguments, to mariadb-install-db (source code here). But mariadb-install-db does some processing of the arguments which expands the argument with whitespace to multiple arguments before passing them to mariadbd (see here).
As mariadb-install-db is written in sh I don't know how to prevent the whitespace argument from expanding without changing to bash or something else ...

Another option would be to not pass the --init-connect argument to mariadb-install-db in the docker-entrypoint.sh.

@grooverdan
Copy link
Member

Yep, you got it right. The only real POSIX array is '$@' that can be manipulated with set -- $newargs ref. Looking again, this might be fixable upstream.

I'm still considering your workaround.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants