Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add configurable query timeout #1760

Merged
merged 11 commits into from Nov 29, 2018
Merged

Add configurable query timeout #1760

merged 11 commits into from Nov 29, 2018

Conversation

edevil
Copy link
Contributor

@edevil edevil commented Nov 2, 2018

Addresses #1713
Based on work from @juliusza

@edevil
Copy link
Contributor Author

edevil commented Nov 4, 2018

@brianc Any feedback on this?

@juliusza
Copy link

juliusza commented Nov 5, 2018

Nice! I have briefly tested my code with query timeout enabled in production and it seemed to work fine.

Eventually I found that the issue was caused by misconfigured tcp proxy, and decided not to pursue this. Regardless, this could be very useful to recover stuck TCP sessions due to lossy network conditions @brianc. Also this is completely optional, and the lib will function as it did without the setting enabled.

Please note that if PR is accepted, documentation needs to be updated here: https://node-postgres.com/api/client

@edevil
Copy link
Contributor Author

edevil commented Nov 5, 2018

@juliusza Is that documentation in some other repository?

@edevil edevil mentioned this pull request Nov 7, 2018
@abenhamdine
Copy link
Contributor

@juliusza Is that documentation in some other repository?

Unfortunately, so far the docs are not available for contributions.

@brianc
Copy link
Owner

brianc commented Nov 7, 2018

Unfortunately, so far the docs are not available for contributions.

I'm thinking of porting them to https://www.gitbook.com so it's easier to contribute.

@edevil
Copy link
Contributor Author

edevil commented Nov 8, 2018

@brianc what about this PR?

@brianc
Copy link
Owner

brianc commented Nov 8, 2018 via email

@abenhamdine
Copy link
Contributor

Have the flu in bed.

Winter is coming 😷

@edevil
Copy link
Contributor Author

edevil commented Nov 17, 2018

@brianc how’s that flu coming along? :)

@brianc
Copy link
Owner

brianc commented Nov 20, 2018

The flu suuuuuuuuuuuuuuucked! Thanks for asking. 😄 It cleared up early last week & now I just have left-over bronchitis. Definitely going to get the flu shot from here on out. Now...lemme look at this PR! Sorry for the review (thanks for pinging me gently on it!)

Copy link
Owner

@brianc brianc left a comment

Choose a reason for hiding this comment

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

This is great, thanks! I'll get this merged & push out a new minor version today. ❤️

@abenhamdine
Copy link
Contributor

This is great, thanks! I'll get this merged & push out a new minor version today. heart

That's great 👍 Could you also bump the version of pg-pool to 2.0.4, in order to be able to benefit from brianc/node-pg-pool@1871d0f ? thx !

@brianc
Copy link
Owner

brianc commented Nov 20, 2018

@abenhamdine you bet!

@neylsongularte
Copy link

I'm looking forward to this functionality

@edevil
Copy link
Contributor Author

edevil commented Nov 27, 2018

@brianc Hello! Any news on this?

@brianc
Copy link
Owner

brianc commented Nov 29, 2018

omg totally slipped my mind....releasing now

@brianc brianc merged commit eb076db into brianc:master Nov 29, 2018
@kibertoad
Copy link
Contributor

@brianc Is pg-pool bump also happening?

@brianc
Copy link
Owner

brianc commented Nov 29, 2018

@kibertoad yah definitely, right after this

published pg@7.7.0

@brianc
Copy link
Owner

brianc commented Nov 29, 2018

pg-pool is already published at 2.0.4 as of a few weeks ago. Am I missing something / are you not able to install it?

@kibertoad
Copy link
Contributor

@brianc It's listed in package.json as "pg-pool": "~2.0.3" which means that projects with package-lock.json are not going to pick it up unless you regenerate entire lock file.

@brianc
Copy link
Owner

brianc commented Nov 29, 2018 via email

@brianc
Copy link
Owner

brianc commented Nov 29, 2018

should I just change it to pg-pool:^2.0.3? I think that'd be better.

@brianc
Copy link
Owner

brianc commented Nov 29, 2018

hmmm wait the ~2.0.3 doesn't prevent you from installing 2.0.4 it just doesn't upgrade it if you already have 2.0.3 installed. K, i'll just bump it.

@brianc
Copy link
Owner

brianc commented Nov 29, 2018

K published pg@7.7.1 bumping the min version for pg-pool to 2.0.4

@abenhamdine
Copy link
Contributor

great, thx @brianc !

@kibertoad
Copy link
Contributor

Thank you!

@jfromaniello
Copy link

Does this actually cancel the query in the server once it timedout in the client side? isn't clear from the diff.

Thank you!

@juliusza
Copy link

Hey @jfromaniello, this does not cancel query on the server. It would be reasonable to configure both query_timeout and statement_timeout, making the statement_timeout slightly longer so that it times out right after the client stopped waiting for response.

@jfromaniello
Copy link

@juliusza thank you very much!

@johan13
Copy link

johan13 commented Jul 16, 2019

How is the documentation for this feature coming?

The query_timeout property is missing from the typescript typings, and the typings seem to be based on the docs, so I thought I'd start here before I send a merge request to DefinitelyTyped.

@brianc
Copy link
Owner

brianc commented Jul 25, 2019 via email

@tmtron
Copy link

tmtron commented Dec 13, 2019

Hey @jfromaniello, this does not cancel query on the server. It would be reasonable to configure both query_timeout and statement_timeout, making the statement_timeout slightly longer so that it times out right after the client stopped waiting for response.

I am quite sure that it should be the other way around: the query-timeout should be slightly longer than the statement-timeout: see Stackoverflow: How to set query_timeout in relation to statement_timeout?

`

@juliusza
Copy link

Yes @tmtron, make sense to have query-timeout longer than statement-timeout.

[CRITICAL] TypeError: Cannot read property 'handleCommandComplete' of null at Connection.<anonymous> (/opt/acn/release_20190925/api/node_modules/pg/lib/client.js:325:22)

I found that sometimes I get this error on production. Because pg lib is event based, there's no proper stack trace to work with. Obviously we haven't thought of a certain edge case here, that causes above error to crash node process.

I no longer need the query-timeout setting, so I don't think I'll want to spend time working on a fix.

2ns2os added a commit to 2ns2os/sequelize that referenced this pull request Sep 3, 2021
This option has existed in pg since v7.7 - see discussion at brianc/node-postgres#1760
Adding to properties to be passed to new connection config so it can be used with sequelize
2ns2os added a commit to 2ns2os/sequelize that referenced this pull request Sep 3, 2021
This option has existed in pg since v7.7 - see discussion at brianc/node-postgres#1760
Adding to properties to be passed to new connection config so it can be used with sequelize
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.

None yet

10 participants