Skip to content

Commit 17e7e9e

Browse files
committed
Remove fix to fail tests
1 parent 9c678e1 commit 17e7e9e

File tree

1 file changed

+25
-27
lines changed

1 file changed

+25
-27
lines changed

packages/pg/lib/query.js

+25-27
Original file line numberDiff line numberDiff line change
@@ -97,24 +97,33 @@ class Query extends EventEmitter {
9797
}
9898
}
9999

100-
handleCommandComplete(msg, con) {
100+
handleCommandComplete(msg, connection) {
101101
this._checkForMultirow()
102102
this._result.addCommandComplete(msg)
103103
// need to sync after each command complete of a prepared statement
104-
if (this.isPreparedStatement && !this._hasSentSync) {
105-
this._hasSentSync = true
106-
con.sync()
107-
}
104+
this.maybeSync(connection)
108105
}
109106

110107
// if a named prepared statement is created with empty query text
111108
// the backend will send an emptyQuery message but *not* a command complete message
112109
// execution on the connection will hang until the backend receives a sync message
113-
handleEmptyQuery(con) {
114-
if (this.isPreparedStatement && !this._hasSentSync) {
115-
this._hasSentSync = true
116-
con.sync()
110+
handleEmptyQuery(connection) {
111+
this.maybeSync(connection)
112+
}
113+
114+
handleError(err, connection) {
115+
// need to sync after error during a prepared statement
116+
this.maybeSync(connection)
117+
if (this._canceledDueToError) {
118+
err = this._canceledDueToError
119+
this._canceledDueToError = false
120+
}
121+
// if callback supplied do not emit error event as uncaught error
122+
// events will bubble up to node process
123+
if (this.callback) {
124+
return this.callback(err)
117125
}
126+
this.emit('error', err)
118127
}
119128

120129
handleReadyForQuery(con) {
@@ -127,27 +136,16 @@ class Query extends EventEmitter {
127136
this.emit('end', this._results)
128137
}
129138

130-
handleError(err, connection) {
131-
// need to sync after error during a prepared statement
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."
137-
if (this.isPreparedStatement && !this._hasSentSync) {
139+
// in postgres 9.6 the backend sends both a command complete and error response
140+
// to a query which has timed out on rare, random occasions. If we send sync twice we will receive
141+
// to 'readyForQuery' events. I think this might be a bug in postgres 9.6, but I'm not sure...
142+
// the docs here: https://www.postgresql.org/docs/9.6/protocol-flow.html#PROTOCOL-FLOW-EXT-QUERY
143+
// 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."
144+
maybeSync(connection) {
145+
if (this.isPreparedStatement) {
138146
this._hasSentSync = true
139147
connection.sync()
140148
}
141-
if (this._canceledDueToError) {
142-
err = this._canceledDueToError
143-
this._canceledDueToError = false
144-
}
145-
// if callback supplied do not emit error event as uncaught error
146-
// events will bubble up to node process
147-
if (this.callback) {
148-
return this.callback(err)
149-
}
150-
this.emit('error', err)
151149
}
152150

153151
submit(connection) {

0 commit comments

Comments
 (0)