You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: packages/pg/lib/query.js
+12-3
Original file line number
Diff line number
Diff line change
@@ -31,6 +31,7 @@ class Query extends EventEmitter {
31
31
this.isPreparedStatement=false
32
32
this._canceledDueToError=false
33
33
this._promise=null
34
+
this._hasSentSync=false
34
35
}
35
36
36
37
requiresPreparation(){
@@ -100,7 +101,8 @@ class Query extends EventEmitter {
100
101
this._checkForMultirow()
101
102
this._result.addCommandComplete(msg)
102
103
// need to sync after each command complete of a prepared statement
103
-
if(this.isPreparedStatement){
104
+
if(this.isPreparedStatement&&!this._hasSentSync){
105
+
this._hasSentSync=true
104
106
con.sync()
105
107
}
106
108
}
@@ -109,7 +111,8 @@ class Query extends EventEmitter {
109
111
// the backend will send an emptyQuery message but *not* a command complete message
110
112
// execution on the connection will hang until the backend receives a sync message
111
113
handleEmptyQuery(con){
112
-
if(this.isPreparedStatement){
114
+
if(this.isPreparedStatement&&!this._hasSentSync){
115
+
this._hasSentSync=true
113
116
con.sync()
114
117
}
115
118
}
@@ -126,7 +129,13 @@ class Query extends EventEmitter {
126
129
127
130
handleError(err,connection){
128
131
// need to sync after error during a prepared statement
129
-
if(this.isPreparedStatement){
132
+
// in postgres 9.6 the backend sends both a command complete and error response
133
+
// to a query which has timed out on rare, random occasions. If we send sync twice we will receive
134
+
// to 'readyForQuery' events. I think this might be a bug in postgres 9.6, but I'm not sure...
135
+
// the docs here: https://www.postgresql.org/docs/9.6/protocol-flow.html#PROTOCOL-FLOW-EXT-QUERY
136
+
// say "Therefore, an Execute phase is always terminated by the appearance of exactly one of these messages: CommandComplete, EmptyQueryResponse (if the portal was created from an empty query string), ErrorResponse, or PortalSuspended."
0 commit comments