-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
libpq: another command is already in progress #69
Comments
Shouldn't queries that receive an asynchronous exception do something like call Database.PostgreSQL.LibPQ.cancel on the connection? Also it looks like hasql has a regression test for this issue. |
The minimal repro from the comments returns timeout as expected now and seems to be fixed with versions:
The minimal repro was: {-# LANGUAGE OverloadedStrings, ScopedTypeVariables #-}
import Database.PostgreSQL.Simple
import System.Timeout
main :: IO ()
main = do
conn <- connectPostgreSQL "dbname='foo' user='bar' password='xxxx'"
res <- timeout 1000000 $ withTransaction conn (query_ conn "select pg_sleep(5)")
case res of
Just [Only x] -> putStrLn "Done." >> return x
Just _ -> error "Impossible."
Nothing -> putStrLn "Timed out." I'll post a minimal repro of my problem that still exists which is connections being returned to Data.Pool while a transaction has not been committed or rolled back as expected. |
Actually I'm not able to reproduce my issue either with just postgresql-simple: let connectionInfo :: ConnectInfo =
defaultConnectInfo
{ .. }
pool <- createPool (connect connectionInfo) close 1 10 1
threadId <- liftIO . Concurrent.forkIO $ withResource pool $ \conn -> do
_ :: [Only ()] <- query_ conn "select pg_sleep(20)"
pure ()
void $ Concurrent.killThread threadId
withResource pool $ \conn -> do
_ :: [Only ()] <- query_ conn "select pg_sleep(2)"
pure () For now I think this rules out postgresql-simple as the culprit for my bug, but perhaps that's not similar enough to my Persistent streaming code that exhibits this issue. TODO post stripped down persistent code Given that I'll create an issue upstream there but I'll leave this open in case others who commented experience this issue using postgresql-simple directly. Here is the related issue on the Persistent side for SqlBackend having issues that also seems related: yesodweb/persistent#981 |
Isn't it possible that in your sample above |
✨ This is an old work account. Please reference @brandonchinn178 for all future communication ✨ Are there any updates here? I'm still getting this issue. Adapting the initial repro gets me the same error: {-# LANGUAGE OverloadedStrings, TypeApplications #-}
import Database.PostgreSQL.Simple
import System.Timeout
main :: IO ()
main = do
conn <- connectPostgreSQL "..."
res <- timeout 1000000 $ withTransaction conn (query_ conn "select pg_sleep(5)")
case res of
Just [Only ()] -> putStrLn "Done."
Just _ -> error "Impossible."
Nothing -> putStrLn "Timed out."
withTransaction conn (query_ conn "select 1") >>= print @[Only Int]
I just tried #71, and this no longer errors. Maybe we can merge it sometime soon? @phadej @mzabani |
It's been a while, but as it is I think we shouldn't merge #71. IIUC it is not possible to reliably fix connection state for new queries to run when an exception interrupts a query, in general. My last comment in the PR suggests merging just the I don't know the best way forward. Merging |
✨ This is an old work account. Please reference @brandonchinn178 for all future communication ✨ ah wait never mind. We use |
So users that don't use pools but depend on transaction rollback?
Please do this. I'd like my team to be able to avoid maintain a fork with that PR. Then hopefully the deprecation warning will solicit feedback from affected users. Maybe linking to the create new issue page in the deprecation warning will increase chances of feedback. |
I thought a bit about this and I think there is another solution to this problem. We could add a new Then, before running any new queries with the same connection, we would cancel any running statements iff that value is set to This may even enable us to use concurrency and Existing I can implement this (in fact I hacked it quickly and it passes the tests I created), but I'd like to hear from others if this sounds reasonable first. @Yuras @phadej |
My team and others in the comments are still affected by this issue from lpsmith/postgresql-simple#177, so I'm copying it over here.
I hope to dig into the issue some more today and post back here but we'll see what happens.
The text was updated successfully, but these errors were encountered: