Reputation: 43
I'm building a NodeJS Application that will connect to an oracle Database.
I'm wondering what happen if I don't close connection and I call the fiftycent()
function many times ?
var i=50;
function fiftycent() {
var oracledb = require('oracledb');
oracledb.getConnection(
{
user : "hr",
password : "welcome",
connectString : "localhost/XE"
},
function(err, connection)
{
if (err) {
console.error(err.message);
return;
}
connection.execute(
"SELECT department_id, department_name "
+ "FROM departments "
+ "WHERE department_id = :did",
[180],
function(err, result)
{
if (err) {
console.error(err.message);
return;
}
console.log(result.rows);
});
});
i=i-1;
if (i>0) fiftycent();
}
After the node server is being running during days, will it cause memory failure or something like that ?
Please note that part of this example is taken from https://github.com/oracle/node-oracledb and they don't include
connection.release( function(err){
if (err) console.error(err.message);
});
in their code.
Thanks in advance for your answers.
Upvotes: 3
Views: 5846
Reputation: 2498
Every time you call getConnection
it creates a new (complete) connection to your db. If you don't call release
it could lead to memory leaks in your application, because the connection is still allocated. And maybe depending on your db server settings, you could reach the maximum number of total open connections.
In this case it would be better to pool your connections in a connection pool
. Calling release
will return the connection to the pool and makes it available to other calls.
All the examples use the release
function to free the connection. Take a look here
Upvotes: 4