Skip to content

fix(connection): fixing mssql reconnect bug - #8022

Closed
codyseibert wants to merge 13 commits into
sequelize:masterfrom
codyseibert:bug/fixing_reconnect_after_db_restart
Closed

codyseibert wants to merge 13 commits into
sequelize:masterfrom
codyseibert:bug/fixing_reconnect_after_db_restart

Conversation

@codyseibert

@codyseibert codyseibert commented Jul 27, 2017 •

Copy link
Copy Markdown

Pull Request check-list

Please make sure to review and check all of these items:

  • Does npm run test or npm run test-DIALECT pass with this change (including linting)?
  • Does the description below contain a link to an existing issue (Closes #[issue]) or a description of the issue you are solving?
  • Have you added new tests to prevent regressions?
  • Is a documentation update included (if this change modifies existing APIs, or introduces new ones)?
  • Did you follow the commit message conventions explained in CONTRIBUTING.md?

Description of change

Original Issue:
#8014

There is currently a bug where if you restart a mssql database,
sequelize will lock the pool resources. Once those are locked, all
future requests to .acquire will throw a ResourceRequest timed out
error. This commit wraps all the connect logic in a retry to prevent an
inifite loop of trying to connect, and also watchins for an 'end' event
in the mssql adapter to properly reject the promise if 'end' is sent
before 'connect' is fired.

There is currently a bug where if you restart a mssql database,
sequelize will lock the pool resources.  Once those are locked, all
future requests to .acquire will throw a ResourceRequest timed out
error.  This commit wraps all the connect logic in a retry to prevent an
inifite loop of trying to connect, and also watchins for an 'end' event
in the mssql adapter to properly reject the promise if 'end' is sent
before 'connect' is fired.
@codecov

codecov Bot commented Jul 28, 2017 •

Copy link
Copy Markdown

Codecov Report

Merging #8022 into master will increase coverage by 0.03%.
The diff coverage is 81.25%.

@codyseibert

Copy link
Copy Markdown
Author

Anyone want to enlighten me as to what this "codecov/patch" failure is? I assume I need to have 95% coverage over the changes I added or something?

retry(() => this._connect(config), {
max: config.pool.connectRetries
})
.then(resolve)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can just return the promise, no need to wrap into another

})
.catch(e => {
this.poolError = e;
reject(e);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

debug('connection acquired');
resolve(connection);
});

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unnecessary new line

@eseliger

Copy link
Copy Markdown
Member

@codyseibert What happened here? 🙈

@codyseibert

Copy link
Copy Markdown
Author

@eseliger I don't know how to re-run the tests without closing and opening the PR. All these tests passed once before, but now they seem to be failing on arbitrary failures.

@eseliger

Copy link
Copy Markdown
Member

You can amend on your current commit and then force push on your branch to retrigger this

@codyseibert

codyseibert commented Jul 31, 2017 •

Copy link
Copy Markdown
Author

ok, I will try that for now on. Any clue what these coverage failures are?

both continuous-integration/travis-ci/pr and continuous-integration/appveyor/pr passed in the past...

@eseliger

Copy link
Copy Markdown
Member

You mean the codecov check?
It's purpose is to remind you the average coverage is 95.34%, your PR just has 81.25% coverage on changed or added lines.

@codyseibert

codyseibert commented Jul 31, 2017 •

Copy link
Copy Markdown
Author

that, but more specifically the "continuous-integration/appveyor/pr" and "continuous-integration/travis-ci/pr" jobs fail randomly at times, but pass on other runs. They don't fail on individual unit / integration tests, but instead they seem to fail on removing coverage files or finding a database...

appveyor

npm ERR! Windows_NT 6.3.9600
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "test-integration"
npm ERR! node v4.8.4
npm ERR! npm  v2.15.11
npm ERR! code ELIFECYCLE
npm ERR! [email protected] test-integration: `mocha --globals setImmediate,clearImmediate --ui tdd --check-leaks --colors -t 30000 --reporter spec "test/integration/**/*.test.js"`
npm ERR! Exit status 3221225477
npm ERR! 
npm ERR! Failed at the [email protected] test-integration script 'mocha --globals setImmediate,clearImmediate --ui tdd --check-leaks --colors -t 30000 --reporter spec "test/integration/**/*.test.js"'.
npm ERR! This is most likely a problem with the sequelize package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     mocha --globals setImmediate,clearImmediate --ui tdd --check-leaks --colors -t 30000 --reporter spec "test/integration/**/*.test.js"
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs sequelize
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! 
npm ERR!     npm owner ls sequelize
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR!     C:\projects\sequelize\npm-debug.log
npm ERR! Test failed.  See above for more details.
Command exited with code 1

@eseliger

Copy link
Copy Markdown
Member

Unfortunately, some times the tests fail due to timeouts and so on, for now, restarting them is the simplest solution, which is most easily done by just triggering another push as I wrote 2 messages ago

@codyseibert

Copy link
Copy Markdown
Author

@eseliger what do you recommend I run in npm to test and increase my codecov/patch coverage? I added a unit tests but it didn't seem to increase my codecov/patch report...

@codecov-io

codecov-io commented Jul 31, 2017 •

Copy link
Copy Markdown

Codecov Report

Merging #8022 into master will increase coverage by 5.34%.
The diff coverage is 81.25%.

@eseliger

Copy link
Copy Markdown
Member

You can see the uncovered lines directly here on codecov. I only see the error cases left. For me, that would be ok.

@codyseibert

codyseibert commented Jul 31, 2017 •

Copy link
Copy Markdown
Author

@eseliger I'm not sure why it says line 77 is not covered. I wrote a unit tests to cover that specifically and it passes fine. Does codecov print for integration tests?

@Vratislav

Copy link
Copy Markdown

@codyseibert we have tested this in our codebase and it solves our issue we are facing when the sequelize never reconnects to the database that was restarted.

We have also tested both #7924 and #7922 None of those solve the ResourceRequest timed out that we are facing.

@eseliger @codyseibert Can we help in any way to get this merged?

@prokopsimek

Copy link
Copy Markdown

Still broken. The same issue ResourceRequest timed out.

@prokopsimek

Copy link
Copy Markdown

Possible ref.: coopernurse/node-pool#155

@smithdalec

Copy link
Copy Markdown

This fix solves the ResourceRequest timed out error for me. Is there anything in particular we're waiting on in order to merge?

@depoulo

depoulo commented Aug 30, 2017

Copy link
Copy Markdown

This fix solves the ResourceRequest timed out error for me as well (MySQL/MariaDB here). Switched to using the PR in my package.json for now, hope this will be merged some day. After all it's a severe regression from v3.x

@stale

stale Bot commented Sep 29, 2017

Copy link
Copy Markdown

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is still an issue, just leave a comment 🙂

@stale stale Bot added the stale label Sep 29, 2017
@jasonfma

Copy link
Copy Markdown

We are still seeing this error as well. Any update here?

@stale stale Bot removed the stale label Sep 29, 2017
@tylerjwatson

Copy link
Copy Markdown
Contributor

We've had a couple of problems that appear to be around this in production, the latest one just now where to recover the pool we've had to restart the server. It looks like the pool has almost completely drained apart from a couple of active connections.

I know it seems like nagging at this point, but it's becoming a pressing issue. Can we please kick the can along on this patch again? Is there anything I can do to help it get across the line?

@benjohnson

Copy link
Copy Markdown

We're also in the same boat. I'm not sure what else is needed to get this merged, but we're happy to lend a hand if there's something in particular this PR is missing.

@ADumaine

Copy link
Copy Markdown

Is there a workaround for this while we are waiting for it to be merged?

This is affecting our tracking system. It is growing fast and the dead connections are becoming more of an issue every day.

@aviranco

Copy link
Copy Markdown

This fix is also relevant for PostgreSQL or only for mysql?

@depoulo

depoulo commented Jan 17, 2018 •

Copy link
Copy Markdown

@ADumaine we're still at this state, yes, since August!

Switched to using the PR in my package.json for now

I even tried to rebase this once, but quickly gave up - I think this needs to be done by someone with more knowledge of Sequelizes ConnectionManager (@codyseibert cough cough)

@guyellis

Copy link
Copy Markdown
Contributor

Has this PR been superseded by #8815?

@depoulo

depoulo commented Jan 17, 2018

Copy link
Copy Markdown

@guyellis looks like. Currently updating my project from using this PR to using the new one (and adopting all changes that happened to Sequelize in the past 6 months). The new PR fixes the issue for me.

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

Successfully merging this pull request may close these issues.