@@ -164,6 +164,7 @@ export class PostgresServer {
164
164
// TODO: Remove this code once https://github.com/electric-sql/pglite/pull/294 is released in PGLite
165
165
export class PGliteExtendedQueryPatch {
166
166
isExtendedQuery = false ;
167
+ eqpErrored = false ;
167
168
168
169
constructor ( public connection : PostgresConnection ) { }
169
170
@@ -184,16 +185,21 @@ export class PGliteExtendedQueryPatch {
184
185
// 'Sync' indicates the end of an extended query
185
186
if ( message [ 0 ] === FrontendMessageCode . Sync ) {
186
187
this . isExtendedQuery = false ;
188
+ this . eqpErrored = false ;
187
189
188
190
// Manually inject 'ReadyForQuery' message at the end
189
191
return this . connection . createReadyForQuery ( ) ;
190
192
}
191
193
192
194
// A PGlite response can contain multiple messages
193
195
for await ( const message of getMessages ( response ) ) {
194
- // If a prepared statement leads to an error message, we need to end the pipeline.
195
- if ( message [ 0 ] === BackendMessageCode . ErrorMessage ) {
196
- this . isExtendedQuery = false ;
196
+ // After an ErrorMessage in extended query protocol, we should throw away messages until the next Sync
197
+ // (per https://www.postgresql.org/docs/current/protocol-flow.html#PROTOCOL-FLOW-EXT-QUERY:~:text=When%20an%20error,for%20each%20Sync.))
198
+ if ( this . eqpErrored ) {
199
+ continue ;
200
+ }
201
+ if ( this . isExtendedQuery && message [ 0 ] === BackendMessageCode . ErrorMessage ) {
202
+ this . eqpErrored = true ;
197
203
}
198
204
// Filter out incorrect `ReadyForQuery` messages during the extended query protocol
199
205
if ( this . isExtendedQuery && message [ 0 ] === BackendMessageCode . ReadyForQuery ) {
0 commit comments