bestlong / node-red-contrib-mssql-plus

A Node-RED node to read and write to Microsoft MS SQL Databases
MIT License
31 stars 18 forks source link

Uncaught Exception while stopping flows (during deploy) #91

Open bombjackit opened 6 months ago

bombjackit commented 6 months ago

Current Behavior

Node-red crashed with this dump (while deploying)

20 Dec 16:57:05 - [red] Uncaught Exception: 20 Dec 16:57:05 - [error] ConnectionError: Cannot close a pool while it is connecting at ConnectionPool._close (S:.node-red\node_modules\mssql\lib\base\connection-pool.js:538:30) at S:.node-red\node_modules\mssql\lib\base\connection-pool.js:521:12 at new Promise () at ConnectionPool.close (S:.node-red\node_modules\mssql\lib\base\connection-pool.js:520:12) at node.connectionCleanup (S:.node-red\node_modules\node-red-contrib-mssql-plus\src\mssql.js:335:42) at node.disconnect (S:.node-red\node_modules\node-red-contrib-mssql-plus\src\mssql.js:459:22) at mssql. (S:.node-red\node_modules\node-red-contrib-mssql-plus\src\mssql.js:834:21) at Node.close (S:\AppData\Roaming\npm\node_modules\node-red\node_modules\@node-red\runtime\lib\nodes\Node.js:340:26) at stopNode (S:\AppData\Roaming\npm\node_modules\node-red\node_modules\@node-red\runtime\lib\flows\Flow.js:745:31) at Flow.stop (S:\AppData\Roaming\npm\node_modules\node-red\node_modules\@node-red\runtime\lib\flows\Flow.js:387:35)

Expected Behavior

Node-red must not crash for this unacaught exception

Steps To Reproduce

In my nodered I had a flow that 1 time a second do an update to some tables in sql server (on localhost), maybe this cause the exception (Cannot close a pool while it is connecting) but the problem is that node-red does must not crash with an exception, only report.

Environment

bombjackit commented 6 months ago

Going deeper, the problem might be this line

https://github.com/bestlong/node-red-contrib-mssql-plus/blob/64f78f4d929179301fd0c7daf4a22a16c2d1661e/src/mssql.js#L335

because node.pool.close() is a promise without catch

maybe a change like this can resolve

if (node.pool) {
  const p = node.pool.close();
  p.catch(e => { console.error(e); });
}