-
Notifications
You must be signed in to change notification settings - Fork 101
Open
Description
Hi there,
As far as I understand, MariaDB closes the connection after some time.
MariaDB Log:
2025-10-10 2:03:44 5 [Warning] Aborted connection 5 to db: 'xxx' user: 'root' host: '172.19.0.16' (Got timeout reading communication packets)
Then my Service (NodeJs 24 in a docker container) crashes:
[2025-10-10 02:03:44] ERROR: SQL read ECONNRESET : [
Error: read ECONNRESET
at TCP.onStreamRead (node:internal/stream_base_commons:216:20) {
errno: -104,
code: 'ECONNRESET',
syscall: 'read',
fatal: true,
sqlState: 'HY000'
}
]
/app/node_modules/mariadb/lib/connection.js:1575
if (!avoidThrowError && !errorThrownByCmd) throw err;
^
Error: read ECONNRESET
at TCP.onStreamRead (node:internal/stream_base_commons:216:20) {
errno: -104,
code: 'ECONNRESET',
syscall: 'read',
fatal: true,
sqlState: 'HY000'
}
Node.js v24.9.0
[nodemon] app crashed - waiting for file changes before starting...
I wonder why, because:
I create the connection inside a try-catch call:
private async getDbConnection(): Promise<mariadb.Connection> {
try {
if (!this.db) {
this.db = await mariadb.createConnection({
host: process.env.MARIADB_HOST,
user: process.env.MARIADB_USER,
password: process.env.MARIADB_PASSWORD,
logParam: true,
logger: {
query: (msg: string) => {
Logger.debug('MariaDB Error - query:', msg);
},
warning: (msg: string) => {
Logger.warn('MariaDB Error - warning:', msg);
},
error: (err: Error) => {
Logger.error('MariaDB Error - error:', err);
},
},
database: process.env.MARIADB_SCHEMA,
initSql: `CREATE DATABASE IF NOT EXISTS \`${process.env.MARIADB_SCHEMA}\``,
});
}
return this.db;
} catch (e) {
Logger.error('getDbConnection()', e);
throw new Error('DB Connection failed');
}
}
Do I have to use Connection-Pools even for simple, long-running services?
Or, how do I catch these Error and reconnect, when the error doesn't get catched?
Thank you very much!
Metadata
Metadata
Assignees
Labels
No labels