brianc / node-pg-copy-streams

COPY FROM / COPY TO for node-postgres. Stream from one database to another, and stuff.
331 stars 40 forks source link

Handling errors #74

Closed furstenheim closed 5 years ago

furstenheim commented 6 years ago

Hi, I'm using this library to pipe large csvs to db. It's been good so far, but It is not clear to me how to handle errors.

Basically I have a fileStream and a dbStream, first one reads from a csv, second one pipes to db

const dbStream = await client.query(from(someQuery))
fileStream.pipe(dbStream)

If fileStream is sucessful everything works out fine. However, if fileStream has an error (for example a timeout if file is over ftp), then dbStream remains dangling. If I connect to postres the query is marked as active. I've tried, dbStream.emit('error', e), or dbStream.destroy() to no avail.

Any idea?

One option would be to open a different connection to the db to do pg_cancel_backend but it really doesn't seem like the way.

Thanks

fluggo commented 5 years ago

Close the client. If you got the client from the pool, call client.release(err).

jeromew commented 5 years ago

I'll close the issue and consider it fixed by the previous comment. Feel free to reopen with a full test case if you need.