Pool query/execute prevents script from exiting
See original GitHub issueUsing this: mysql.js
function connection() {
try {
const mysql = require('mysql2');
const pool = mysql.createPool({
host: 'localhost',
user: '',
password: '',
database: '',
timezone: 'utc',
connectionLimit: 100,
waitForConnections: true,
queueLimit: 0
});
const promisePool = pool.promise();
return promisePool;
} catch (error) {
return console.log(`Could not connect - ${error}`);
}
}
const pool = connection();
module.exports = {
connection: async () => pool.getConnection(),
execute: (...params) => pool.execute(...params),
query: (...params) => pool.query(...params),
escape: (...params) => pool.escape(...params)
};
script.js
async function testPromises() {
test = [1, 2, 3, 4, 5, 6, 7, 3, 73, 7, 37, 7, 7];
await db.query('SELECT * FROM test LIMIT 10');
console.log('after query');
}
testPromises();
Script never exits and keeps all records in memory indefinitely, however everything after the query executes too so it doesn’t hang on this query. How can I prevent that? I also tried:
const db = require('./mysql');
async function testPromises() {
connection = await db.connection();
let test2 = await connection.query('SELECT * FROM test LIMIT 10');
connection.release();
console.log(test2);
}
testPromises();
Issue Analytics
- State:
- Created 4 years ago
- Comments:9 (5 by maintainers)
Top Results From Across the Web
QueryExecute - Adobe Support
This function simplifies the query execution in the CFScript block. This function lets you pass unnamed parameters to the query.
Read more >Database Queries - Learn Modern ColdFusion <CFML> in ...
A query is a request to a database. It returns a CFML query object containing a recordset and other metadata information about the...
Read more >How to execute large amount of sql queries asynchronous ...
RunspacePool is the way to go here, try this: $AllQueries = @( ... ) $MaxThreads = 5 # Each thread keeps its own...
Read more >HANA – analyzing runtime dumps - SAP Blogs
Python script. a FSD (FullSystemDump) only includes already existing RTE dumps => resulting in zip file; Q13. How can runtime dumps be ...
Read more >Article: Database Integration Guide: FAQ 2 - Boomi Community
In the Database Connection component, on the connection pool tab, ... Boomi keeps passing ? into the SQL query instead of the actual ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
For an HTTP server a common practice is to create a module which initializes the connection pool and exports it when it’s required, making use of Node’s module caching (effectively a singleton pattern). You can hook into something like
process.on("SIGINT", pool.end)
to try to gracefully quit. Otherwise keep your pool open for the duration of the process’s lifetime and query it as you wish. Mysql2 will tend to hang Node if you don’t release connections as well, so make good use offinally
and the query methods.in that case not much you can do to reduce memory pressure. Maybe use separate pool with a small number of max open connections, that way it’ll act as a semaphore reducing the maximum number of the simultaneous requests processing 300mb of data ( and maybe only release back connection when data processing is done, not after the data is received )