node-firebird icon indicating copy to clipboard operation
node-firebird copied to clipboard

Connection to firebird is not closed if there is an error in attach function

Open ferserc1 opened this issue 1 year ago • 0 comments

When a connection error occurs, e.g. because of access permissions, the socket is not closed properly and open connections are left on the server. This can be checked by querying the MON$ATTACHMENTS table:

SELECT MON$REMOTE_PROCESS
FROM MON$ATTACHMENTS
WHERE MON$REMOTE_PROCESS='/usr/local/bin/node'

I have modified the code of the attach function to have access from outside the driver to the connection, and I have managed to solve the problem by doing a detach to the db object, which I can access from the connection:

node-firebird:

exports.attach = function(options, callback) {

    var host = options.host || DEFAULT_HOST;
    var port = options.port || DEFAULT_PORT;
    var manager = options.manager || false;
    var cnx = this.connection = new Connection(host, port, function(err) {
            ...
    }, options);

    return cnx;  // Fix: get access to connection object outside node-firebird
};
const conn = Firebird.attach(this._config, (err, db) => {
    this._conn.push(conn);
    if (err) {
        // manually detach the connection in case of error
        conn.db.detach();
        ...

I understand that db.detach() should be done automatically in case of error.

ferserc1 avatar Mar 08 '23 08:03 ferserc1