Skip to content

Commit 1961125

Browse files
committed
Update pg-cursor
pg-cursor no longer returns the empty array 'done' signal to the callback until the cursor recieves a readyForQuery message. This means pg-query-stream will not emit 'close' or 'end' events until the server is __truly__ ready for the next query. This fixes some race-conditions where some queries are triggered off of the `end` event of the query-stream closes #3
1 parent 0a7da37 commit 1961125

2 files changed

Lines changed: 33 additions & 1 deletion

File tree

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@
3333
"mocha": "~1.17.1"
3434
},
3535
"dependencies": {
36-
"pg-cursor": "~0.1.2"
36+
"pg-cursor": "0.1.3"
3737
}
3838
}

‎test/issue-3.js‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
var pg = require('pg.js')
2+
var QueryStream = require('../')
3+
describe('end semantics race condition', function() {
4+
before(function(done) {
5+
var client = new pg.Client()
6+
client.connect()
7+
client.on('drain', client.end.bind(client))
8+
client.on('end', done)
9+
client.query('create table IF NOT EXISTS p(id serial primary key)')
10+
client.query('create table IF NOT EXISTS c(id int primary key references p)')
11+
})
12+
it('works', function(done) {
13+
var client1 = new pg.Client()
14+
client1.connect()
15+
var client2 = new pg.Client()
16+
client2.connect()
17+
18+
var qr = new QueryStream("INSERT INTO p DEFAULT VALUES RETURNING id")
19+
client1.query(qr)
20+
var id = null
21+
qr.on('data', function(row) {
22+
id = row.id
23+
})
24+
qr.on('end', function () {
25+
client2.query("INSERT INTO c(id) VALUES ($1)", [id], function (err, rows) {
26+
client1.end()
27+
client2.end()
28+
done(err)
29+
})
30+
})
31+
})
32+
})

0 commit comments

Comments
 (0)