GeezerVison is showing github.com — Add connection lifetime limit option and tests by ChrisWritable · Pull Request #2698 · brianc/node-postgres
Conversation
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Thanks! Will merge after tests pass. ❤️
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
|
this.log('new client connected')
|
|
|
|
|
|
if (this.options.maxLifetimeSeconds !== 0) {
|
|
|
setTimeout(() => {
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because of missing unref, this effectively disables allowExitOnIdle feature.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
marcbachmann reacted with thumbs up emoji
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the unit test need to be updated? The test passed.
✓ unrefs the connections and timeouts so the program can exit when idle when the allowExitOnIdle option is set (151ms)
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
polomsky
Feb 11, 2022
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. maxLifetimeSeconds should be set there to some higher value, e.g. 60.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
hempels
Feb 15, 2022
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually I think an additional test is needed in idle-timeout.js since allowExitOnIdle should be tested under both conditions (maxLifetimeSeconds is disabled and maxLifetimeSeconds is a longer time period than idleTimeoutMillis.)
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry to also comment on this, but this is preventing a clean shutdown even when client.end() is called.
Can't we just use .unref() on the timeout or
const timeout = setTimeout(....)
client.once('end', () => clearTimeout(timeout))
Maybe even both
Edit: Something like that
const maxLifetimeTid = setTimeout(() => {
this.log('ending client due to expired lifetime')
this._expired.add(client)
const idleIndex = this._idle.findIndex((idleItem) => idleItem.client === client)
if (idleIndex !== -1) {
this._acquireClient(
client,
new PendingItem((err, client, clientRelease) => clientRelease()),
idleListener,
false
)
}
}, this.options.maxLifetimeSeconds * 1000)
client.once('end', () => clearTimeout(maxLifetimeTid))
if (this.options.allowExitOnIdle) {
maxLifetimeTid.unref()
}
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
polomsky reacted with thumbs up emoji
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's probably worth noting that the default setting for maxLifetimeSeconds is 0 (aka: disabled) and none of these issues appear unless you set it to a non-zero value. That doesn't resolve the issues, but it is important to be aware of since there is a simple workaround (set it back to 0.) It seems like the need to utilize maxLifetimeSeconds would be minimal in cases where clients are being explicitly disconnected (the feature was added primarily to support long-running services in load-balanced DB environments.)
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
marcbachmann reacted with thumbs up emoji
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exactly my use case (for faster recovery after a failover to a replica) 😊
I just ran into some issue with some local scripts, we're I'm using the same config. I might do a PR to fix it in the next few days, unless anybody else is on it. But haven't seen any PRs.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This was referenced Aug 23, 2024
Reviewers
3 more reviewers
hempels
hempels left review comments
Reviewers whose approvals may not affect merge requirements
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|