Skip to content

Add configurable query timeout#1760

Merged
brianc merged 11 commits into
brianc:masterfrom
edevil:query_timeout
Nov 29, 2018
Merged

Add configurable query timeout#1760
brianc merged 11 commits into
brianc:masterfrom
edevil:query_timeout

Conversation

@edevil

@edevil edevil commented Nov 2, 2018

Copy link
Copy Markdown
Contributor

Addresses #1713
Based on work from @juliusza

Comment thread test/integration/client/api-tests.js
Comment thread test/integration/client/api-tests.js Outdated
Comment thread lib/client.js
@edevil

edevil commented Nov 4, 2018

Copy link
Copy Markdown
Contributor Author

@brianc Any feedback on this?

@juliusza

juliusza commented Nov 5, 2018

Copy link
Copy Markdown

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

edevil commented Nov 5, 2018

Copy link
Copy Markdown
Contributor Author

@juliusza Is that documentation in some other repository?

@edevil edevil mentioned this pull request Nov 7, 2018
@abenhamdine

Copy link
Copy Markdown
Contributor

@juliusza Is that documentation in some other repository?

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

@brianc

brianc commented Nov 7, 2018

Copy link
Copy Markdown
Owner

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

edevil commented Nov 8, 2018

Copy link
Copy Markdown
Contributor Author

@brianc what about this PR?

@brianc

brianc commented Nov 8, 2018 via email

Copy link
Copy Markdown
Owner

@abenhamdine

Copy link
Copy Markdown
Contributor

Have the flu in bed.

Winter is coming 😷

@edevil

edevil commented Nov 17, 2018

Copy link
Copy Markdown
Contributor Author

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

@brianc

brianc commented Nov 20, 2018

Copy link
Copy Markdown
Owner

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!)

@brianc brianc left a comment

Copy link
Copy Markdown
Owner

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
Copy Markdown
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

brianc commented Nov 20, 2018

Copy link
Copy Markdown
Owner

@abenhamdine you bet!

@neylsongularte

Copy link
Copy Markdown

I'm looking forward to this functionality

@edevil

edevil commented Nov 27, 2018

Copy link
Copy Markdown
Contributor Author

@brianc Hello! Any news on this?

@brianc

brianc commented Nov 29, 2018

Copy link
Copy Markdown
Owner

omg totally slipped my mind....releasing now

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

Copy link
Copy Markdown
Contributor

@brianc Is pg-pool bump also happening?

@brianc

brianc commented Nov 29, 2018

Copy link
Copy Markdown
Owner

@kibertoad yah definitely, right after this

published pg@7.7.0

@brianc

brianc commented Nov 29, 2018

Copy link
Copy Markdown
Owner

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
Copy Markdown
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

brianc commented Nov 29, 2018 via email

Copy link
Copy Markdown
Owner

@brianc

brianc commented Nov 29, 2018

Copy link
Copy Markdown
Owner

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

@brianc

brianc commented Nov 29, 2018

Copy link
Copy Markdown
Owner

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

brianc commented Nov 29, 2018

Copy link
Copy Markdown
Owner

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

@abenhamdine

Copy link
Copy Markdown
Contributor

great, thx @brianc !

@kibertoad

Copy link
Copy Markdown
Contributor

Thank you!

@jfromaniello

Copy link
Copy Markdown

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
Copy Markdown

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
Copy Markdown

@juliusza thank you very much!

@johan13

johan13 commented Jul 16, 2019

Copy link
Copy Markdown

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

brianc commented Jul 25, 2019 via email

Copy link
Copy Markdown
Owner

@tmtron

tmtron commented Dec 13, 2019

Copy link
Copy Markdown

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
Copy Markdown

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.

10 participants