Skip to content

Commit 66c7e04

Browse files
workaround while abiosoft/colima#71 is open
1 parent ccf0d90 commit 66c7e04

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

persistent-postgresql/Database/Persist/Postgresql.hs

+10-2
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ import qualified Database.PostgreSQL.Simple.Transaction as PG
7171
import qualified Database.PostgreSQL.Simple.Types as PG
7272

7373
import Control.Arrow
74-
import Control.Exception (Exception, throw, throwIO)
74+
import Control.Exception (Exception, throw, throwIO, catches, Handler (Handler))
7575
import Control.Monad
7676
import Control.Monad.Except
7777
import Control.Monad.IO.Unlift (MonadIO(..), MonadUnliftIO)
@@ -119,6 +119,9 @@ import Database.Persist.Postgresql.Internal
119119
import Database.Persist.Sql
120120
import qualified Database.Persist.Sql.Util as Util
121121
import Database.Persist.SqlBackend
122+
import Database.PostgreSQL.Simple (SqlError)
123+
import System.IO (hPutStr, stderr)
124+
import Control.Concurrent (threadDelay)
122125

123126
-- | A @libpq@ connection string. A simple example of connection
124127
-- string would be @\"host=localhost port=5432 user=test
@@ -288,7 +291,12 @@ open'
288291
-- pass in 'withRawConnection'.
289292
-> ConnectionString -> LogFunc -> IO backend
290293
open' modConn getVer constructor cstr logFunc = do
291-
conn <- PG.connectPostgreSQL cstr
294+
conn <- fix $ \loop' ->
295+
PG.connectPostgreSQL cstr `catches` [
296+
Handler (\ (ex :: IOError) -> hPutStr stderr ("Warning: DB not ready (PQ.PollingFailed)" ++ ": " ++ show ex)
297+
>> threadDelay 3000000 >> loop'),
298+
Handler (\ (ex :: SqlError) -> hPutStr stderr ("Warning: DB not ready (fatalError)" ++ ": " ++ show ex)
299+
>> threadDelay 3000000 >> loop')]
292300
modConn conn
293301
ver <- getVer conn
294302
smap <- newIORef $ Map.empty

0 commit comments

Comments
 (0)