yesodweb / yesodweb/persistent

libpq: another command in progress

Open
#1,408 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Haskell
Stars
486
Forks
306
PR merge metrics
No merged PRs in 30d

Description

#1199 is marked done, but we still saw an instance of this error on persistent-postgresql-2.13.5.0.

#1199 mentioned an issue in postgresql-simple, but I commented that it's unrelated, because persistent uses its own transaction logic: https://github.com/haskellari/postgresql-simple/issues/69#issuecomment-1167982755

I was able to make a repro for postgresql-simple that fails with postgresql-simple, but making an equivalent repro using persistent-postgresql works fine:

{-# LANGUAGE OverloadedStrings, TypeApplications #-}

import Control.Monad.IO.Class (liftIO)
import Control.Monad.Logger (runNoLoggingT)
import Control.Monad.Reader (ReaderT (..), runReaderT)
import Database.Persist.Postgresql
import Database.Persist.Sql
import UnliftIO.Async (race)
import UnliftIO.Concurrent (threadDelay)

main :: IO ()
main =
  runNoLoggingT . withPostgresqlConn "..." $ \conn ->
    (`runSqlConn` conn) $ do
      res <- race (threadDelay 1000000) (rawSql "select pg_sleep(5)" [])
      case res of
        Left () -> liftIO $ putStrLn "Timed out."
        Right [Single PersistNull] -> liftIO $ putStrLn "Done."
        Right _ -> error "Impossible."
      rawSql "select 1" [] >>= liftIO . print @[Single PersistValue]

So it seems like something else is causing this libpq error other than the naive kill-query-mid-transaction.

cc @codygman

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the supplied persistent-postgresql reproduction around withPostgresqlConn, runSqlConn, and rawSql, then compare it with the reported postgresql-simple reproduction. Inspect how persistent-postgresql handles transaction cancellation and connection reuse, and trace the libpq “another command in progress” error. Done means identifying a reproducible trigger distinct from the issue in #1199 and documenting or fixing it with a regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
haskell, postgresql
Domain
backend, databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.