File tree 2 files changed +16
-1
lines changed
2 files changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -86,6 +86,8 @@ class Cursor extends EventEmitter {
86
86
}
87
87
88
88
_closePortal ( ) {
89
+ if ( this . state === 'done' ) return
90
+
89
91
// because we opened a named portal to stream results
90
92
// we need to close the same named portal. Leaving a named portal
91
93
// open can lock tables for modification if inside a transaction.
@@ -97,6 +99,8 @@ class Cursor extends EventEmitter {
97
99
if ( this . state !== 'error' ) {
98
100
this . connection . sync ( )
99
101
}
102
+
103
+ this . state = 'done'
100
104
}
101
105
102
106
handleRowDescription ( msg ) {
@@ -213,7 +217,6 @@ class Cursor extends EventEmitter {
213
217
}
214
218
215
219
this . _closePortal ( )
216
- this . state = 'done'
217
220
this . connection . once ( 'readyForQuery' , function ( ) {
218
221
cb ( )
219
222
} )
Original file line number Diff line number Diff line change @@ -117,5 +117,17 @@ if (!process.version.startsWith('v8')) {
117
117
client . release ( )
118
118
await pool . end ( )
119
119
} )
120
+
121
+ it ( 'supports breaking with low watermark' , async function ( ) {
122
+ const pool = new pg . Pool ( { max : 1 } )
123
+ const client = await pool . connect ( )
124
+
125
+ for await ( const _ of client . query ( new QueryStream ( 'select TRUE' , [ ] , { highWaterMark : 1 } ) ) ) break
126
+ for await ( const _ of client . query ( new QueryStream ( 'select TRUE' , [ ] , { highWaterMark : 1 } ) ) ) break
127
+ for await ( const _ of client . query ( new QueryStream ( 'select TRUE' , [ ] , { highWaterMark : 1 } ) ) ) break
128
+
129
+ client . release ( )
130
+ await pool . end ( )
131
+ } )
120
132
} )
121
133
}
You can’t perform that action at this time.
0 commit comments