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

Support statement_timeout #1436

Merged
merged 7 commits into from Sep 3, 2017
Merged

Support statement_timeout #1436

merged 7 commits into from Sep 3, 2017

Conversation

jkennedy1980
Copy link
Contributor

We need the ability to set statement_timeout for a given connection so that all queries timeout instead of running to completion. This is really important when running nodejs/postgres on Heroku because they have http connection limits that timeout at 30 seconds. I want my SQL queries to stop at this boundary too since the waiting http connection will have already been closed.

I was not able to add this feature to the native side of things because postgres does not seem to support statement timeouts via pgsql connection strings.

.gitignore Outdated
@@ -5,3 +5,4 @@ build/
node_modules/
package-lock.json
*.swp
/.idea
Copy link
Collaborator

Choose a reason for hiding this comment

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

You can put this in a global gitignore instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I removed this. I often checkin the webstorm files in my own repos which is why I added it here. Not a problem.


function getConInfo (override) {
var newConInfo = {}
Object.keys(conInfo).forEach(function (k) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

return Object.assign(
  {},
  conInfo,
  override
);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My bad, I started with the appname-tests.js file as a starting point. I've updated this function in both files.

package.json Outdated
"pg-connection-string": "0.1.3",
"pg-native": "^2.2.0",
Copy link
Contributor

Choose a reason for hiding this comment

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

Why this addition of pg-native ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah shit. The tests seem to be adding that when they are run. I'll remove it.

`npm run test` seems to be adding this
@brianc
Copy link
Owner

brianc commented Aug 30, 2017

Ohhhh this is nice!

done()
})
})
}
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like the tests only check for the correct configuration of statement_timeout.
I think we miss a test for checking if the timeout is actually used, by using a query with pg_sleep(whicheverValueAboveTimeout)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure. But isn't that testing Postgres itself? The tests already confirmed that the setting is set on the connection.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sure. But isn't that testing Postgres itself? The tests already confirmed that the setting is set on the connection.

You may have a point here, but the test seems pretty simple to write, so IMHO it's better to add it.
Whatsoever @brianc has the final word.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've written it. Travis is running so I'm hoping the error response from postgres is the same from all the versions you guys support. I asserted the error code only with the hope that is will be less fragile than expecting a particular error message.

.gitignore Outdated
@@ -4,4 +4,4 @@ build/
*.log
node_modules/
package-lock.json
*.swp
*.swp
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks like an unwanted edit.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've added a newline to the end of the file to remove this change

@jkennedy1980
Copy link
Contributor Author

Once this PR is approved, I'd be be happy to help with documentation. I'll be camping for the next few days so i'll go silent and come back online Saturday afternoon.

@brianc
Copy link
Owner

brianc commented Sep 1, 2017

Thanks for all the help & work on this! I'll merge it this weekend, push a new minor version, and document it! ❤️

@brianc brianc merged commit ecab41c into brianc:master Sep 3, 2017
charmander added a commit to charmander/node-postgres that referenced this pull request Oct 16, 2017
…sts with npm 5

Should save some confusion in future pull requests (brianc#1465, brianc#1436, brianc#1363).
brianc pushed a commit that referenced this pull request Nov 4, 2017
…sts with npm 5

Should save some confusion in future pull requests (#1465, #1436, #1363).
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

5 participants