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

Reject query immediately if connection is being terminated #1715

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,13 @@ Client.prototype.query = function (config, values, callback) {
}
}

if (this._ending) {
if (query.callback) {
query.callback(new Error('Could not accept query, because connection has ended'))
}
return
Copy link
Contributor

Choose a reason for hiding this comment

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

The non-callback case should return a rejected Promise. Otherwise await client.query(...) would resolve to undefined. I think all that needs to be changed is the return clause on L376 to:

return result

I haven't actually tried out the patch but that jumped out at me so figured to comment now if you're going to pursue this further. Could include both styles in a test as well (i.e. with callback and without).

}

if (this.binary && !query.binary) {
query.binary = true
}
Expand Down