Reject query immediately if connection is being terminated#1715
Closed
juliusza wants to merge 2 commits intobrianc:masterfrom
Closed
Reject query immediately if connection is being terminated#1715juliusza wants to merge 2 commits intobrianc:masterfrom
juliusza wants to merge 2 commits intobrianc:masterfrom
Conversation
Owner
|
Thanks! Could you write a test for this behavior? |
sehrope
reviewed
Sep 4, 2018
lib/client.js
Outdated
| if (query.callback) { | ||
| query.callback(new Error('Could not accept query, because connection has ended')) | ||
| } | ||
| return |
Contributor
There was a problem hiding this comment.
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).
Collaborator
|
This is fixed by #1503: @@ -389,6 +435,20 @@ Client.prototype.query = function (config, values, callback) {
query._result._getTypeParser = this._types.getTypeParser.bind(this._types)
}
+ if (!this._queryable) {
+ process.nextTick(() => {
+ query.handleError(new Error('Client has encountered a connection error and is not queryable'), this.connection)
+ })
+ return result
+ }
+
+ if (this._ending) {
+ process.nextTick(() => {
+ query.handleError(new Error('Client was closed and is not queryable'), this.connection)
+ })
+ return result
+ }
+
this.queryQueue.push(query)
this._pulseQueryQueue()
return result |
Author
|
Thanks a lot for comments and review. It has been noted that #1503 implements a similar fix as well. I will not pursue this further until the mentioned pull is rejected or merged. |
Collaborator
|
Fixed in pg 7.5.0. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Consider the following example:
Error will be emitted:
It's not exactly clear what's going on. Now it is much more obvious if we reject query early:
This is quite an edge case, but I'm debugging this exact issue on my production environment. It's hard to know if TCP connections just die or client is ended externally.