@@ -89,4 +89,46 @@ describe('error recovery', () => {
89
89
await client . end ( )
90
90
} )
91
91
} )
92
+
93
+ it ( 'should work if used after timeout error' , async ( ) => {
94
+ const pool = new Pool ( { max : 1 , connectionTimeoutMillis : 400 , statement_timeout : 400 } ) ;
95
+
96
+ const res1 = await pool . query ( 'SELECT 1 AS a' ) ;
97
+ assert . deepStrictEqual ( res1 . rows , [ { a :1 } ] ) ;
98
+
99
+ const query = new QueryStream ( 'SELECT 2 AS b' ) ;
100
+ const client = await pool . connect ( ) ;
101
+ const stream = await client . query ( query ) ;
102
+
103
+ await assert . rejects ( ( ) => pool . query ( 'SELECT TRUE' ) , { message : 'timeout exceeded when trying to connect' } ) ;
104
+
105
+ await stream . destroy ( ) ;
106
+ await client . release ( ) ;
107
+
108
+ const res2 = await pool . query ( 'SELECT 4 AS d' ) ;
109
+ assert . deepStrictEqual ( res2 . rows , [ { d :4 } ] ) ;
110
+
111
+ await pool . end ( ) ;
112
+ } )
113
+
114
+ it ( 'should work if used after syntax error' , async ( ) => {
115
+ const pool = new Pool ( { max : 1 , statement_timeout : 100 } ) ; // statement_timeout is required here, so maybe this is just another timeout error?
116
+
117
+ const res1 = await pool . query ( 'SELECT 1 AS a' ) ;
118
+ assert . deepStrictEqual ( res1 . rows , [ { a :1 } ] ) ;
119
+
120
+ const query = new QueryStream ( 'SELECT 2 AS b' ) ;
121
+ const client = await pool . connect ( ) ;
122
+ const stream = await client . query ( query ) ;
123
+
124
+ await new Promise ( resolve => setTimeout ( resolve , 10 ) ) ;
125
+
126
+ await stream . destroy ( ) ;
127
+ await client . release ( ) ;
128
+
129
+ const res2 = await pool . query ( 'SELECT 4 AS d' ) ;
130
+ assert . deepStrictEqual ( res2 . rows , [ { d :4 } ] ) ;
131
+
132
+ await pool . end ( ) ;
133
+ } )
92
134
} )
0 commit comments