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

Catch errors thrown by connect #3004

Closed
wants to merge 1 commit into from
Closed

Catch errors thrown by connect #3004

wants to merge 1 commit into from

Conversation

xvello
Copy link

@xvello xvello commented Jun 8, 2023

We had a user submit a PG connstring with ?ssl=off, while this is invalid, it's not failing the parsing, and connect() throws on:

Cannot use 'in' operator to search for 'key' in off TypeError: Cannot use 'in' operator to search for 'key' in off at Socket. (/Users/xavier/git/node-postgres/packages/pg/lib/connection.js:90:19)

Because Connection extends EventEmitter, that exception is not catch-able with a try / catch around the call to client.connect(). I am following on the footsteps of #2569, and making sure that exception is properly caught internally.

Ideally, this ?ssl=off value should trigger a validation error, but:

  • I'm not certain not to break compat by adding a stricter input validation
  • With this PR, we're possibly covering other edge cases

Added a unit test, that fails if connection.js is not patched: an unhandled exception bubbles up.

@xvello
Copy link
Author

xvello commented Jun 19, 2023

Heya @charmander would you have a moment to review this one? It's a pretty small change.

Copy link
Collaborator

@charmander charmander left a comment

Choose a reason for hiding this comment

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

Ideally, this ?ssl=off value should trigger a validation error, but:

  • I'm not certain not to break compat by adding a stricter input validation
  • With this PR, we're possibly covering other edge cases

This strikes me as the bad kind of defensive programming. An early, strict validation of the value of ssl would be better. We can note the compatibility and the edge cases properly then.

@xvello xvello closed this Sep 5, 2023
@xvello xvello deleted the xvello/ssl-off branch September 5, 2023 09:47
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

2 participants