GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Add connection lifetime limit option and tests by ChrisWritable · Pull Request #2698 · brianc/node-postgres

Conversation

@ChrisWritable

@ChrisWritable ChrisWritable commented Jan 28, 2022

Copy link
Copy Markdown
Contributor

Here's a rebased version based on your comments here: #2668 (comment)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@ChrisG0x20 @ChrisWritable
Add connection lifetime limit option and tests
da510a7
@ChrisWritable ChrisWritable mentioned this pull request Jan 28, 2022
Add optional maximum connection lifetime parameter #2027
Closed
@brianc

brianc commented Jan 28, 2022

Copy link
Copy Markdown
Owner

Thanks! Will merge after tests pass. ❤️

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@brianc
brianc merged commit 8392918 into brianc:master Jan 28, 2022
polomsky
polomsky reviewed Feb 10, 2022
View reviewed changes
Comment thread packages/pg-pool/index.js
this.log('new client connected')

if (this.options.maxLifetimeSeconds !== 0) {
setTimeout(() => {

@polomsky polomsky Feb 10, 2022

Copy link
Copy Markdown

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
All reactions
  • 👍 1 reaction

@ChrisWritable ChrisWritable Feb 11, 2022

Copy link
Copy Markdown
Contributor Author

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.

All reactions

@polomsky polomsky Feb 11, 2022 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

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.

All reactions

@hempels hempels Feb 15, 2022 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

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.

All reactions

@marcbachmann marcbachmann Mar 12, 2022 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

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
All reactions
  • 👍 1 reaction

@hempels hempels Mar 12, 2022

Copy link
Copy Markdown

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
All reactions
  • 👍 1 reaction

@marcbachmann marcbachmann Mar 12, 2022 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

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.

All reactions
@johanneswuerbach johanneswuerbach mentioned this pull request Mar 2, 2022
feat: support max lifetime vitaly-t/pg-promise#826
Merged
@ChrisWritable ChrisWritable mentioned this pull request Mar 16, 2022
Immediately unref() maxLifetimeSeconds Timeout object to prevent blocking allowExitOnIdle #2721
Merged
@sehrope sehrope mentioned this pull request Apr 24, 2023
Connection TTL #2965
Open
@jackwotherspoon jackwotherspoon mentioned this pull request Jun 26, 2024
Add support for lazy certificate refresh GoogleCloudPlatform/cloud-sql-nodejs-connector#285
Open
This was referenced Aug 23, 2024
[pg] expiredCount DefinitelyTyped/DefinitelyTyped#70368
Merged
[pg] pool.options DefinitelyTyped/DefinitelyTyped#70371
Merged
@birjj birjj mentioned this pull request Jun 10, 2025
docs(pg.Pool): describe maxLifetimeSeconds config option #3484
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

3 more reviewers
@hempels hempels hempels left review comments
@marcbachmann marcbachmann marcbachmann left review comments
@polomsky polomsky polomsky 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

Labels

None yet

Projects

None yet

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.

6 participants

@ChrisWritable @brianc @hempels @marcbachmann @polomsky @ChrisG0x20
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.