lpsmith / postgresql-simple

Mid-level client library for accessing PostgreSQL from Haskell
Other
206 stars 71 forks source link

Drop lock during getCopyData? #266

Open ryantrinkle opened 5 years ago

ryantrinkle commented 5 years ago

Would it be reasonable to drop the connection lock here? https://github.com/lpsmith/postgresql-simple/blob/14d00c22713aab7d55a81a81b47cc5bb7280398f/src/Database/PostgreSQL/Simple/Copy.hs#L135

I'm working on some code that needs to interleave (blocking) getCopyData and putCopyData. It seems to work for me when I manually break through the lock for putCopyData and flush, but I'm not sure whether that's actually OK.

lpsmith commented 5 years ago

Maybe? It's been a long time since I've worked or thought about this bit of code. Though we would need to adopt some of the techniques in the Notification module in order to avoid some race conditions.

I'm not yet familiar with such use cases. Do you have a pointer to some documentation I could look at?

ryantrinkle commented 5 years ago

I guess an alternative would be to explicitly support PGRES_COPY_BOTH mode. My specific use case is a replication connection, which requires the client to periodically send heartbeats to the server while continuing to (blockingly) wait on downstream content.

The documentation I'm following is here.