Skip to content

fix abstract/connection-manager.js pool configuration problem - #7922

Closed
v0y4g3r wants to merge 4 commits into
sequelize:masterfrom
v0y4g3r:master
Closed

v0y4g3r wants to merge 4 commits into
sequelize:masterfrom
v0y4g3r:master

Conversation

@v0y4g3r

@v0y4g3r v0y4g3r commented Jul 10, 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? no test needed
  • Is a documentation update included (if this change modifies existing APIs, or introduces new ones)? no changes to public APIs
  • Did you follow the commit message conventions explained in CONTRIBUTING.md?

Description of change

As described in issue #7882 , current pool confiuration in /lib/dialects/abstract/connection-manager.js initPool method sets autostart to false when no replication is configured, which causes generic-pool _scheduleEvictorRun check routine never gets invoked. As a result idle connections never get evicted even if the database server's already closed the connection.
To fix that problem, simply set autostart option to true and the evict check routine gets scheduled.
As documented in node-pool, the softIdleTimeoutMillis(default to -1 ) is checked before idleTimeoutMillis, so if softIdleTimeoutMillis is not set, the connection will be considered stale no matter what idleTimeoutMillis is

@swordfish444 swordfish444 left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@RayneHwang Your code is failing the lint. You need to add a space after softIdleTimeoutMillis: ! Can you review the open issues and link any of the ones that are caused by this issue? This will help us identify and consolidate them.

@codecov

codecov Bot commented Jul 10, 2017 •

Copy link
Copy Markdown

Codecov Report

Merging #7922 into master will increase coverage by 5.35%.
The diff coverage is n/a.

@swordfish444

Copy link
Copy Markdown
Contributor

@RayneHwang That was fast!

@v0y4g3r

v0y4g3r commented Jul 10, 2017

Copy link
Copy Markdown
Author

@swordfish444 😄

@swordfish444 swordfish444 left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@RayneHwang The config autostart doesn't appear the issue for evictions not being checked. Instead, have you considered adding evictionRunIntervalMillis: 60000 to the configuration? The default evictionRunIntervalMillis is set to never process evictions. By setting it to 60000, we can process evictions every minute. 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

softIdleTimeoutMillis is not needed as idleTimeoutMillis supercedes it. It's not changing the pool configuration and can be removed.

I'm not sure why the spec is failing, it appears unrelated to your PR though and something to do with the code coverage report.

@mphilpot Can you take a look?

@swordfish444

Copy link
Copy Markdown
Contributor

@RayneHwang I've opened #7924 to resolve for stale connections by ensuring evictions are ran.

@v0y4g3r

v0y4g3r commented Jul 11, 2017 •

Copy link
Copy Markdown
Author

@swordfish444 I've tested your PR in my project, doesn't seem to successfully evict stale connections.

  • autostart must be true
    The default value of autostart is true, but in asbtract/connection-manager.js autostart is manually set to false.
    In generic-pool constructor ,if autostart is not set to true, the evict routine won't be called for the first time, and the following check relies on setTimeout inside the _scheduleEvictorRun ,so no evict will be scheduled.

  • softIdleTimeoutMillis must be set
    Though node-pool doc claims that idleTimeoutMillis supercedes softIdleTimeoutMillis, but in the default evictor implementation softIdleTimeoutMillis is checked before idleTimeoutMillis. If softIdleTimeoutMillis is not set, the default value( -1 ) always makes the connection stale, when availableObjectsCount is larger than config.min

if (config.softIdleTimeoutMillis < idleTime && config.min < availableObjectsCount) {
     return true; // because softIdleTimeoutMillis is -1, always return true when still have connections available in pool
}
if (config.idleTimeoutMillis < idleTime) {
    return true;
}

So every time _scheduleEvictorRun gets ran, the connection will be evicted, no matter what idleTimeoutMillis is. It's really a confusing option.

  • evictionRunIntervalMillis
    Sorry I forgot to commit that option. I will push some updates.

@sushantdhiman

Copy link
Copy Markdown
Contributor

autostart: false is not acceptable, this will be fixed by coopernurse/node-pool#201

As a workaround you can call start from pooling library to initialize evictor #7924 (comment)

@DiegoRBaquero

DiegoRBaquero commented Jan 17, 2019 •

Copy link
Copy Markdown

The softIdleTimeoutMillis thing is still a bug, which thens marks all connections as idle.

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.

6 participants