Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ferserc1 opened this issue Mar 8, 2023 · 0 comments

Comments

@ferserc1
Copy link

ferserc1 commented Mar 8, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant