Skip to content

Error when getting connection from pool #343

Open
@fabiobotsilva

Description

@fabiobotsilva

I have an express rest api, and sometimes I get a connection error after the requests, then I made an example to reproduce the error.
I would appreciate it if anyone knows how to avoid this error and can share, or confirm if it's really a bug.

I am aware of the asynchronous nature of the example, the position of the error varies, sometimes it is at the beginning, in the middle or at the end, sometimes everything works well. Please, try again if it works at the first time.

(Please, adjust the connection data for your database)

Thanks,

I'm using:
node: v20.15.1
node-firebird: 1.1.9

            const dbOptions: firebird.Options = {
                host: config.DB_HOST,
                port: config.DB_PORT,
                database: config.DB_DATABASE,
                user: config.DB_USER,
                password: config.DB_PASSWORD,
                lowercase_keys: true,
                pageSize: 8192,
                retryConnectionInterval: 1000
            };

            const dbPool = firebird.pool(20, dbOptions);
            console.log('--------------');
            console.log(' Pool created ');
            console.log('--------------');

            [0,1,2,3,4,5,6,7,8,9].forEach((elem: number) => {
                dbPool.get(function (err, db) {
                    if (err) throw 'get ' + elem + ' ' + err;
                    console.log(elem + ' : A - attach');

                    db.query('SELECT CURRENT_DATE FROM RDB$DATABASE', [], function (err, result) {
                        if (err) throw 'query ' + elem + ' ' + err;
                        console.log(elem + ' : Q - query');

                        db.detach(function (err) {
                            if (err) throw 'detach ' + elem + ' ' + err;
                            console.log(elem + ' : D - detach ');
                        });
                    });
                });
            });

Output: (It changes each time)

--------------
 Pool created
--------------
0 : A - attach
1 : A - attach
4 : A - attach
5 : A - attach
6 : A - attach
7 : A - attach
8 : A - attach
2024-08-26T13:59:09.819Z - :[error]: uncaughtException: get 2 Error: Your user name and password are not defined. Ask your database
administrator to set up a Firebird login

  No stack trace
2024-08-26T13:59:09.820Z - :[error]: uncaughtException: get 3 Error: Your user name and password are not defined. Ask your database
administrator to set up a Firebird login

  No stack trace
9 : A - attach
0 : Q - query
0 : D - detach
1 : Q - query
1 : D - detach
4 : Q - query
4 : D - detach
5 : Q - query
5 : D - detach
6 : Q - query
6 : D - detach
7 : Q - query
7 : D - detach
8 : Q - query
8 : D - detach
9 : Q - query
9 : D - detach

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions