NodeJS:如果不关闭 oracle 连接会发生什么

NodeJS : What happen if not close oracle connection

我正在构建一个将连接到 oracle 数据库的 NodeJS 应用程序。

我想知道如果我不关闭连接并多次调用 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();
}

节点服务器在运行几天后,会不会导致内存故障之类的?

请注意,此示例的部分内容来自 https://github.com/oracle/node-oracledb,不包括

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

在他们的代码中。

提前感谢您的回答。

每次调用 getConnection 时,它都会创建一个新的(完整的)连接到您的数据库。如果您不调用 release,它可能会导致您的应用程序内存泄漏,因为连接仍在分配中。也许根据您的数据库服务器设置,您可能会达到最大总打开连接数。

在这种情况下,最好将您的连接集中在 connection pool 中。调用 release 将 return 连接到池并使其可供其他调用使用。

所有示例都使用 release 函数来释放连接。看看here