Turn off MariaDB verbose logging when you're done

2023-11-23 09:03:26 +0100 +0100

tl;dr: Make sure you switch off verbose logging for MariaDB once you've finished debugging.

Last month I was troubleshooting some connection issues with a NodeJS app. I kept seeing a mysterious error when running a maintenance script in for the app: [Warning] Aborted connection 54 to db: 'unconnected' user: 'root' host: 'localhost' (Got an error reading communication packets).

MariaDB has some nice options for debugging SQL statements and connections, so I enabled them:

general_log = 1
general_log_file = /opt/homebrew/var/mysql/general.log

log_warnings = 9

This results in a highly verbose logging output. Which was helpful for me to realize that the mysterious error was not NodeJS library versions, nor Docker networks, or my host system firewall, or perhaps MariaDB engine incompatibility, etc, but a routine PEBKAC issue instead.

What happened: in the recent past, we had refactored some NodeJS scripts in the app to export functions, such that instead of calling node some-file.js, one should instead run node -e "require('./some-file.js).init();" .

The refactored bash orchestration script for calling various Node scripts was correct. My personal shell history was not. (I rely heavily on Ctrl+r for running commands.) So when I attempted to run a single NodeJS script, I'd see no output except for Got an error reading communication packets when using Ctrl+c to close the file.

Why the error? At the top of some-file.js are these lines:

const dbPool = mariadb.createPool({
    host: process.env.MYSQL_HOST,
    user: process.env.MYSQL_ROOT_USER,
    password: process.env.MYSQL_ROOT_PASSWORD,
    port: process.env.MYSQL_PORT

We invoke (and eventually close) the pool connection when the caller runs init() on the file. If you just run node create-users.js, we only create the pool connection. So then when you run Ctrl+r after calling mariadb.createPool() you'll see Got an error reading communication packets because the connection was closed improperly.

Having realized that, all was well… except that I didn't adjust my.cnf to switch off logging. Which led some weeks later to 646.2 GB of log space used on my laptop. Thank you to DaisyDisk for helping me find those files.


Lessons learned: Double check the commands one runs from bash history & disable MariaDB verbose logging after use.