Skip to content

Different behavior calling .end() on a non connected Client between 7.17 and 7.18 #2108

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

Closed
InExtremaRes opened this issue Feb 20, 2020 · 2 comments · Fixed by #2109
Closed

Comments

@InExtremaRes
Copy link

Calling client.end() on a Client not connected in [email protected] fails with an error message

Socket is closed

However in [email protected] the same call just hangs indefinitely. I'm using the promise-based call (without the callback) and awaiting the promise to fulfil.

Is this an expected change?

If the context matters, I have a wrapper around a Client and I'm "unit testing" that a call to its closing function throws if the wrapped client is not connected. Before I was just calling .end() on the inner client but now the test fails since the promise never fulfilled.

If the change is expected, is there a way of knowing if a given Client is connected?

@brianc
Copy link
Owner

brianc commented Feb 20, 2020 via email

@InExtremaRes
Copy link
Author

Yep. As long a it is consistent and documented a noop looks good to me. But still I think there should be a public way of knowing if a client is connected. I think there is a _connected property but seems to be private.

In our case we do want to throw in that case since it can only happen due a developer mistake and not as a normal flow path; our wrapper can throw if the inner client is not connected and pg.Client can then just do nothing if .end() is called. Is that possible?

brianc added a commit that referenced this issue Feb 20, 2020
brianc added a commit that referenced this issue Feb 25, 2020
* Call callback when end called on unconnected client

Closes #2108

* Revert a bit of the change

* Use readyState because pending doesn't exist in node 8.x

* Update packages/pg/lib/client.js

use bring your own promise

Co-Authored-By: Charmander <[email protected]>

Co-authored-by: Charmander <[email protected]>
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 a pull request may close this issue.

2 participants