[CONJS-242] mariadb.createPool: UncaughtException error Created: 2023-02-24  Updated: 2023-03-01  Resolved: 2023-03-01

Status: Closed
Project: MariaDB Connector/node.js
Component/s: pool
Affects Version/s: 3.1.0
Fix Version/s: 3.1.1

Type: Bug Priority: Minor
Reporter: Rino Rabe Assignee: Diego Dupin
Resolution: Duplicate Votes: 0
Labels: crash
Environment:

node@19.6.0
nodemon@2.0.20
mariadb@3.1.0
MariaDB SQL server: 10.10.3

MariaDB SQL server in a docker container. Tested with both node & nodemon. OS: Windows 10



 Description   

If Node w/mariadb connector & mariadb server losses connection between them, an 'UncaughtException' error will happen. Maybe I'm too new at this, but it seems like there might be an error in the createPool. Desire is to catch the error and let the pool try to reconnect in X time.

Assuming "ClientOptions" are valid and MariaDB server is running, the following will create a pool in Node.js:
const pool = mariadb.createPool(clientOptions)

That is working, but if I simulate that the MariaDB server dies/losing connection (i.e. stops the docker container):
Node will crash after a few seconds with an 'UncaughtException' error.
Seems like createPool is not a promise itself, but it's service is. So not sure how to catch the error and let it try to connect again in X time.

I have tried to listen to events:

  • pool.on('error' ... This gives a error message 'ECONNREFUSED'
  • process.on('uncaughtException' ... This gives a error message 'ECONNREFUSED'
    In both cases Node.js exits, and there seems no possible way to recover from this (beside PM2 or forever; not tested these)

Detailed error message:
node:internal/process/promises:289
triggerUncaughtException(err, true /* fromPromise */);

Error: connect ECONNREFUSED ::1:3306
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1494:16)
From event:
at D:\Code\node-db-boilerplate\node_modules\mariadb\lib\connection.js:133:13
at new Promise (<anonymous>)
at Connection.connect (D:\Code\node-db-boilerplate\node_modules\mariadb\lib\connection.js:121:12)
at Pool._createConnection (D:\Code\node-db-boilerplate\node_modules\mariadb\lib\pool.js:402:16)
at Pool._doCreateConnection (D:\Code\node-db-boilerplate\node_modules\mariadb\lib\pool.js:40:10)
at listOnTimeout (node:internal/timers:568:17)
at process.processTimers (node:internal/timers:511:7)
Emitted 'error' event on PoolPromise instance at:
at Pool.emit (node:events:512:28)
at D:\Code\node-db-boilerplate\node_modules\mariadb\lib\pool.js:258:22
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

{ errno: -4078, code: 'ECONNREFUSED', syscall: 'connect', address: '::1', port: 3306, fatal: true, sqlState: 'HY000' }

 Comments   
Comment by Rino Rabe [ 2023-02-24 ]

Setting the priority to 'Minor' as I've succesfully managed to use events to intercept the crash error (and handle it).

Comment by Diego Dupin [ 2023-03-01 ]

Closing it dupplicate of CONJS-246 that will be corrected in next version.

About minor, you're kind, i've set it as a blocker, since crashing application is serious, even if workaround is easy to implement.

Generated at Thu Feb 08 03:23:48 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.