Skip to content

Evict stale connections - #7924

Merged
sushantdhiman merged 9 commits into
sequelize:masterfrom
swordfish444:master
Aug 10, 2017
Merged

sushantdhiman merged 9 commits into
sequelize:masterfrom
swordfish444:master

Conversation

@swordfish444

@swordfish444 swordfish444 commented Jul 10, 2017 •

Copy link
Copy Markdown
Contributor

Pull Request check-list

  • 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?
  • 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

Adding a new option to defaultPoolingConfig for overiding the default evictionRunIntervalMillis when instantiating connection pools using node-pool. You can see how evictions are never ran if this setting remains 0 https://github.com/coopernurse/node-pool/blob/master/lib/Pool.js#L351

This PR is a bandaid for several recent "open" issues: #7884 and #7882 and possibly #7616

Added configuration property `evictionRunIntervalMillis` to node-pool instantiation to allow evictions to run against stale connections in the pool. The default value is set to 0 which prevents evictions all together. The added configuration will cause evictions to run every 60 seconds. The setting has been exposed in the Sequelize configuration options.
Corrected the existing default pooling options in `usage.md` and added new option for evict which controls the interval in which evictions run.
Adding `evictionTimeoutMillis` to remaining configuration areas within `connection-manager.js`
@swordfish444

swordfish444 commented Jul 10, 2017 •

Copy link
Copy Markdown
Contributor Author

@felixfbecker It looks like you broke the CI with this commit 8d4700f

Why are you committing directly to master to begin with? This is extremely risky and is bound to cause friction with both new PRs and on-going releases.

@codecov

codecov Bot commented Jul 11, 2017 •

Copy link
Copy Markdown

Codecov Report

Merging #7924 into master will not change coverage.
The diff coverage is n/a.

@felixfbecker

felixfbecker commented Jul 11, 2017 •

Copy link
Copy Markdown
Contributor

Why are you committing directly to master to begin with? This is extremely risky and is bound to cause friction with both new PRs and on-going releases.

I didn't. I merged a PR (which is linked in the commit message, btw) from Greenkeeper that updates ESLint, was approved by two other maintainers, passed locally and on CI on multiple jobs on Travis. It failed then on AppVeyor, Node 4, Windows, because for whatever black magic this line throws an error in that environment (but works on Linux Node 4, 6 and Windows Node 6). Apparently Node 4 is unable to parse JSON on Windows. Excuse me for valuing my free time in that moment higher than the absolute certainty of something so unpredictable not happening.

@janmeier janmeier left a comment •

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.

Please add the evict option to the sequelize constructor options

* @param {Object} [options.pool={}] Should sequelize use a connection pool. Default is true

@felixfbecker
felixfbecker requested a review from janmeier July 17, 2017 11:25
@janmeier

Copy link
Copy Markdown
Member

My comment is still pending, please add the option to the api docs :)

@felixfbecker

Copy link
Copy Markdown
Contributor

Sorry for pinging you!

Updating the comment which documents the configuration parameters available when constructing a new _Sequelize_ object.
Updating the grammar for simplify the understanding of this option.
@swordfish444

Copy link
Copy Markdown
Contributor Author

@janmeier Thanks for taking the time to review this PR and apologies for the lapse in time before addressing your feedback.

I've updated the api docs in lib/sequelize.js. Are we clear to ship?

@euqen

euqen commented Aug 9, 2017

Copy link
Copy Markdown
Contributor

@sushantdhiman @janmeier Hi guys, can you please proceed with review, we need to merge it ASAP, otherwise we will need to downgrade sequelize version because of this issue: sidorares/node-mysql2#447

@eseliger eseliger left a comment

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.

Lgtm

@sushantdhiman

Copy link
Copy Markdown
Contributor

@euqen I will do the merge once CI shows the green flag :)

@euqen

euqen commented Aug 9, 2017

Copy link
Copy Markdown
Contributor

@sushantdhiman great, thank you!

@sushantdhiman

Copy link
Copy Markdown
Contributor

Failing MSSQL builds should now be fixed after 05f3c6d

I have updated this branch, its pretty late here in India 23:51 😆 , so any one with merge rights should merge this branch as soon as it gets green.

@euqen

euqen commented Aug 10, 2017

Copy link
Copy Markdown
Contributor

@sushantdhiman thanks for merging. Can you please clarify for me when are you planning to create new release which includes this changes? Thanks

@dtjohnson

Copy link
Copy Markdown

Thanks for getting this released, but is this fix actually working for anyone else? The eviction scheduler doesn't seem to be getting called at all for me. I tracked it down to the autostart: false config setting on the pool on line 113. From the pool docs it seems this flag is necessary to start the pool automatically. The default behavior is true but this setting turns it off. If I change this to true it works as expected and evicts connections.

@sushantdhiman

Copy link
Copy Markdown
Contributor

#8126 addresses this issue, but we cant just set autostart: true. AFAIR other dialect pool will be initialized, need to verify at least

@dtjohnson

Copy link
Copy Markdown

Looks like calling this will fix it in the meantime:

sequelize.connectionManager.pool.start();

I'm seeing the connections get evicted as expected now.

@xdamman

xdamman commented Sep 5, 2017 •

Copy link
Copy Markdown

This PR will also solve #8133 I think.

(I'm also impacted by this using Sequelize 4.8.0 and Sequelize-cli 2.8.0, I tried the line above but it says that sequelize.connectionManager is undefined. Where do you run this inside a migration file?)

@kchokhawala

kchokhawala commented Feb 6, 2018 •

Copy link
Copy Markdown

@dtjohnson : Man, you saved my life. Past 2 days I am was breaking my head over this.
putting autostart: true in pool object, made it work smooth as I would love it to be.

Just in case if I am missing anything let me know.
I am using MSSQL v4.1.0 and was still seeing the error.

Thanks,

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.

9 participants