If I add query_timeout to the example:
const pg = require('pg')
var pool = new pg.Pool({
query_timeout: 10000,
})
const QueryStream = require('pg-query-stream')
const JSONStream = require('JSONStream')
//pipe 1,000,000 rows to stdout without blowing up your memory usage
pool.connect((err, client, done) => {
if (err) throw err
const query = new QueryStream('SELECT * FROM generate_series(0, $1) num', [1000])
const stream = client.query(query)
//release the client when the stream is finished
stream.on('end', done)
stream.pipe(JSONStream.stringify()).pipe(process.stdout)
})
readTimeoutTimer is not released because the query callback isn't called.
Process hangs and does not exit until readTimeout expires. Then it will throw the timeout error.
This seems to an oversight in the implementation, but I might be missing something, not sure where the callback should be called to release the timer.
Maybe in _destroy call the callback?
public _destroy(_err: Error, cb: Function) {
this.callback?(_err);
this.cursor.close((err?: Error) => {
cb(err || _err)
})
}
If I add
query_timeoutto the example:readTimeoutTimeris not released because the querycallbackisn't called.Process hangs and does not exit until readTimeout expires. Then it will throw the timeout error.
This seems to an oversight in the implementation, but I might be missing something, not sure where the callback should be called to release the timer.
Maybe in _destroy call the callback?