File tree Expand file tree Collapse file tree 2 files changed +16
-1
lines changed Expand file tree Collapse file tree 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 {
8686 }
8787
8888 _closePortal ( ) {
89+ if ( this . state === 'done' ) return
90+
8991 // because we opened a named portal to stream results
9092 // we need to close the same named portal. Leaving a named portal
9193 // open can lock tables for modification if inside a transaction.
@@ -97,6 +99,8 @@ class Cursor extends EventEmitter {
9799 if ( this . state !== 'error' ) {
98100 this . connection . sync ( )
99101 }
102+
103+ this . state = 'done'
100104 }
101105
102106 handleRowDescription ( msg ) {
@@ -213,7 +217,6 @@ class Cursor extends EventEmitter {
213217 }
214218
215219 this . _closePortal ( )
216- this . state = 'done'
217220 this . connection . once ( 'readyForQuery' , function ( ) {
218221 cb ( )
219222 } )
Original file line number Diff line number Diff line change @@ -117,5 +117,17 @@ if (!process.version.startsWith('v8')) {
117117 client . release ( )
118118 await pool . end ( )
119119 } )
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+ } )
120132 } )
121133}
You can’t perform that action at this time.
0 commit comments