NodeJS: What happens if you don't close the oracle connection

I am creating a NodeJS application that will connect to oracle database.

I am wondering what happens if I don't close the connection and call the function multiple times fiftycent()

?

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 has been running for a few days, will it cause a memory failure or something?

Please note that some of this example is taken from https://github.com/oracle/node-oracledb and they do not include

connection.release( function(err){
 if (err) console.error(err.message);
});

      

in your code.

Thanks in advance for your answers.

+3


source to share


1 answer


Every time you call getConnection

it creates a new (full) connection to your db. If you don't call release

, it could leak memory in your application as the connection is still allocated. And maybe depending on your db server settings you can achieve the maximum number of open open connections.

In this case, it would be better to combine your connections in connection pool

. The call release

will return the connection to the pool and make it available for other calls.



All examples use a function release

to release the connection. Take a look here

+3


source







All Articles