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

Infinite pool error event #464

Closed
eugene2005 opened this issue May 4, 2017 · 4 comments
Closed

Infinite pool error event #464

eugene2005 opened this issue May 4, 2017 · 4 comments

Comments

@eugene2005
Copy link

eugene2005 commented May 4, 2017

Here is the code


import * as sql from 'mssql';

const pool = new sql.ConnectionPool(config.msSqlConfig);

pool.connect(error => {
    if (error) {
        logger.crit('Database connection error.', error.toString());
    }
});

pool.on('error', error => {
    if (error) {
        logger.crit('Pool error.', error.toString());
    }
});

function registerUser(user) {
    return pool.request()
        .input('name', Sql.SqlTypes.NVarChar(255), user.name)
        .input('email', Sql.SqlTypes.NVarChar(255), user.email)
        .input('password', Sql.SqlTypes.NVarChar(Sql.SqlTypes.MAX), user.password)
        .execute('registerUser')
        .then(result => {
        })
        .catch(error => {
           logger.crit('Query error.', error.toString());
        });
}

When the pool is initialized connection is available. Once connection is established I intentionally shutdown Sql Server and try to execute registerUser.
Here is what I get in my log:
...
2017-05-04 15:13:15 EDT - crit: Pool error. ConnectionError: Failed to connect to 192.168.1.116:1433 - connect ECONNREFUSED 192.168.1.116:1433
2017-05-04 15:13:16 EDT - crit: Pool error. ConnectionError: Failed to connect to 192.168.1.116:1433 - connect ECONNREFUSED 192.168.1.116:1433
2017-05-04 15:13:16 EDT - crit: Pool error. ConnectionError: Failed to connect to 192.168.1.116:1433 - connect ECONNREFUSED 192.168.1.116:1433
2017-05-04 15:13:17 EDT - crit: Pool error. ConnectionError: Failed to connect to 192.168.1.116:1433 - connect ECONNREFUSED 192.168.1.116:1433
2017-05-04 15:13:17 EDT - crit: Pool error. ConnectionError: Failed to connect to 192.168.1.116:1433 - connect ECONNREFUSED 192.168.1.116:1433
...
Messages never stop. It just keeps loging errors indefinitly.
If I don't sign up for pool error event I get
UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): ConnectionError: Failed to connect to 192.168.1.116:1433 - connect ECONNREFUSED 192.168.1.116:1433

@ruimgoncalves
Copy link

I have something similar, in my case ESOCK error when the network goes down.
Has a workaround I managed to break the loop by throwing an exception in the pool.on('error' ...

pool.on('error', error => {
   this.err = error
   throw new Error('Socket error, thown expcetion to prevent error loop')
})

@Halt001
Copy link

Halt001 commented Oct 24, 2017

Can you explain where you catch that exception?

@dhensby
Copy link
Collaborator

dhensby commented Mar 8, 2019

This is due to a problem with thee way generic-pool tries to acquire good connections. It is now fixed in v5 (by adding a retry backoff) and v6 (by removing generic-pool)

@dhensby dhensby closed this as completed Mar 8, 2019
@dhensby
Copy link
Collaborator

dhensby commented Mar 8, 2019

see #808 and #806

Also duplicate of #470

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

4 participants