File tree 3 files changed +26
-3
lines changed
3 files changed +26
-3
lines changed Original file line number Diff line number Diff line change @@ -163,13 +163,15 @@ Cursor.prototype._getRows = function(rows, cb) {
163
163
this . connection . flush ( )
164
164
}
165
165
166
- Cursor . prototype . end = function ( cb ) {
166
+ // users really shouldn't be calling 'end' here and terminating a connection to postgres
167
+ // via the low level connection.end api
168
+ Cursor . prototype . end = util . deprecate ( function ( cb ) {
167
169
if ( this . state !== 'initialized' ) {
168
170
this . connection . sync ( )
169
171
}
170
172
this . connection . once ( 'end' , cb )
171
173
this . connection . end ( )
172
- }
174
+ } , 'Cursor.end is deprecated. Call end on the client itself to end a connection to the database.' )
173
175
174
176
Cursor . prototype . close = function ( cb ) {
175
177
if ( this . state === 'done' ) {
Original file line number Diff line number Diff line change @@ -83,4 +83,25 @@ describe('pool', function() {
83
83
done ( )
84
84
} )
85
85
} )
86
+
87
+ it ( 'can close multiple times on a pool' , async function ( ) {
88
+ const pool = new pg . Pool ( { max : 1 } )
89
+ const run = async ( ) => {
90
+ const cursor = new Cursor ( text )
91
+ const client = await pool . connect ( )
92
+ client . query ( cursor )
93
+ new Promise ( resolve => {
94
+ cursor . read ( 25 , function ( err ) {
95
+ assert . ifError ( err )
96
+ cursor . close ( function ( err ) {
97
+ assert . ifError ( err )
98
+ client . release ( )
99
+ resolve ( )
100
+ } )
101
+ } )
102
+ } )
103
+ }
104
+ await Promise . all ( [ run ( ) , run ( ) , run ( ) ] )
105
+ await pool . end ( )
106
+ } )
86
107
} )
Original file line number Diff line number Diff line change @@ -28,7 +28,7 @@ describe('transactions', () => {
28
28
await client . end ( )
29
29
} )
30
30
31
- it . only ( 'can execute multiple statements in a transaction if no data' , async ( ) => {
31
+ it ( 'can execute multiple statements in a transaction if no data' , async ( ) => {
32
32
const client = new pg . Client ( )
33
33
await client . connect ( )
34
34
await client . query ( 'begin' )
You can’t perform that action at this time.
0 commit comments