Repository navigation
Destroying a copy read stream frees the connection - #1306
Conversation
|
Thanks Efe, great find. cancel(item.query) doesn’t send a cancel here though. The copy query is already settled once it resolved with the stream, so cancel() takes the quiet branch and returns. What frees the connection is the resume(), which reads the rest and drops it: a destroyed 5 GB export takes 9.1 s to free the connection against 7.8 s to read it in full, and in a transaction the next query still succeeds, so it isn’t rolled back. |
|
Thanks, you're right, it only drains. I dropped the cancel line and added a changelog entry, and the PR text now describes draining. On PostgreSQL 15, in a transaction, the next query and the commit both succeed after a destroyed copy. All 15 tests in |
|
Nice - thank you |
Destroying the stream from
copy ... to stdouthangs the connection for good. Afterdestroy(),push()returns false and_readis never called again, soCopyDatapauses the frames and the socket and nothing resumes them. The query behind it never runs, and in a pool the connection is lost. It happens withreadable.destroy(), breaking out offor await, or apipelinewhose destination fails, such as a client disconnecting during an export.The stream now has a
destroythat resumes reading, so the rest of the copy is read and dropped. The query is not canceled, so the connection is free once the server has sent the rest, and in a transaction the next query and the commit still succeed.Test: added
Destroying a copy read stream frees the connectiontotests/copy.js. It times out onmasterand passes with the fix. On PostgreSQL 15 and Node 22 all 15 tests incopy.jspass, as do the unit tests andsimulate.js. I did not run the rest of the integration suite for this change.