Skip to content

Commit 28f6c13

Browse files
committed
(copy-from) fix 6.0.0 issue with node 14 (_destroy / _final race)
1 parent 8bd8c49 commit 28f6c13

File tree

5 files changed

+45
-44
lines changed

5 files changed

+45
-44
lines changed

.travis.yml

+5
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ jobs:
1212
postgresql: '9.6'
1313
env:
1414
- PGVERSION=9.6 PGUSER=postgres PGDATABASE=postgres
15+
- node_js: '14'
16+
addons:
17+
postgresql: '9.6'
18+
env:
19+
- PGVERSION=9.6 PGUSER=postgres PGDATABASE=postgres
1520
- node_js: '10'
1621
addons:
1722
postgresql: '11'

copy-from.js

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ class CopyStreamQuery extends Writable {
4646
// send a CopyFail message that will rollback the COPY operation.
4747
// the cb will be called only after the ErrorResponse message is received
4848
// from the backend
49+
if (this.cb_ReadyForQuery) return cb(err)
4950
this.cb_destroy = cb
5051
const msg = err ? err.message : 'NODE-PG-COPY-STREAMS destroy() was called'
5152
const self = this

package-lock.json

+30-39
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"heroku-env": "~0.1.1",
3737
"lodash": "^4.17.19",
3838
"mocha": "^7.1.2",
39-
"pg": "^7.8.2",
39+
"pg": "^8.7.1",
4040
"prettier": "^2.0.5"
4141
},
4242
"prettier": {

test/copy-from.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -328,18 +328,20 @@ describe('copy-from', () => {
328328
createCopyFromQuery('tablename', '(field1 int)', (client, copyFromStream) => {
329329
spyOnEmitCalls(copyFromStream)
330330
const pt = new PassThrough()
331-
pipeline(pt, copyFromStream, (err) => {
331+
copyFromStream.on('error', (err) => {
332332
assert.equal(copyFromStream.emits['error'].length, 1)
333333
const expectedMessage = /COPY from stdin failed/
334334
assert.notEqual(
335335
copyFromStream.emits['error'][0].toString().search(expectedMessage),
336336
-1,
337337
'Error message should mention that COPY failed'
338338
)
339-
assert.ok(err)
340339
client.end()
341340
done()
342341
})
342+
pipeline(pt, copyFromStream, (err) => {
343+
assert.ok(err)
344+
})
343345
pt.emit('error', new Error('pipelineError'))
344346
})
345347
})
@@ -348,18 +350,20 @@ describe('copy-from', () => {
348350
createCopyFromQuery('tablename', '(field1 int)', (client, copyFromStream) => {
349351
spyOnEmitCalls(copyFromStream)
350352
const pt = new PassThrough()
351-
pipeline(pt, copyFromStream, (err) => {
353+
copyFromStream.on('error', (err) => {
352354
assert.equal(copyFromStream.emits['error'].length, 1)
353355
const expectedMessage = /COPY from stdin failed/
354356
assert.notEqual(
355357
copyFromStream.emits['error'][0].toString().search(expectedMessage),
356358
-1,
357359
'Error message should mention that COPY failed'
358360
)
359-
assert.ok(err)
360361
client.end()
361362
done()
362363
})
364+
pipeline(pt, copyFromStream, (err) => {
365+
assert.ok(err)
366+
})
363367
client.connection.once('copyInResponse', () => {
364368
pt.emit('error', new Error('pipelineError'))
365369
})

0 commit comments

Comments
 (0)