Merge pull request #409 from begriffs/ctrl-c

Release db connections on sigint
This commit is contained in:
Joe Nelson
2015-12-07 23:46:37 -08:00
3 changed files with 14 additions and 3 deletions
+1
View File
@@ -9,6 +9,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
- Miscalculation of time used for expiring tokens - @calebmer - Miscalculation of time used for expiring tokens - @calebmer
- Remove bcrypt dependency to fix Windows build - @begriffs - Remove bcrypt dependency to fix Windows build - @begriffs
- Detect relations event when authenticator does not have rights to intermediate tables - @ruslantalpa - Detect relations event when authenticator does not have rights to intermediate tables - @ruslantalpa
- Ensure db connections released on sigint - @begriffs
### Added ### Added
- Allow order by computed columns - @diogob - Allow order by computed columns - @diogob
+1
View File
@@ -61,6 +61,7 @@ executable postgrest
, HTTP, http-types , HTTP, http-types
, MissingH , MissingH
, Ranged-sets , Ranged-sets
, unix >= 2.7 && < 3
hs-source-dirs: src hs-source-dirs: src
other-modules: Paths_postgrest other-modules: Paths_postgrest
+12 -3
View File
@@ -6,11 +6,13 @@ import PostgREST.Config (AppConfig (..),
minimumPgVersion, minimumPgVersion,
prettyVersion, prettyVersion,
readOptions) readOptions)
import PostgREST.Error (pgErrResponse, PgError)
import PostgREST.Middleware
import PostgREST.DbStructure import PostgREST.DbStructure
import PostgREST.Error (PgError, pgErrResponse)
import PostgREST.Middleware
import Control.Monad (unless) import Control.Concurrent (myThreadId)
import Control.Exception.Base (throwTo, AsyncException(..))
import Control.Monad (unless, void)
import Control.Monad.IO.Class (liftIO) import Control.Monad.IO.Class (liftIO)
import Data.Aeson (encode) import Data.Aeson (encode)
import Data.Functor.Identity import Data.Functor.Identity
@@ -26,6 +28,7 @@ import Network.Wai.Middleware.RequestLogger (logStdout)
import System.IO (BufferMode (..), import System.IO (BufferMode (..),
hSetBuffering, stderr, hSetBuffering, stderr,
stdin, stdout) stdin, stdout)
import System.Posix.Signals
import Web.JWT (secret) import Web.JWT (secret)
isServerVersionSupported :: H.Session P.Postgres IO Bool isServerVersionSupported :: H.Session P.Postgres IO Bool
@@ -69,6 +72,12 @@ main = do
<> show minimumPgVersion) <> show minimumPgVersion)
) supportedOrError ) supportedOrError
tid <- myThreadId
void $ installHandler keyboardSignal (Catch $ do
H.releasePool pool
throwTo tid UserInterrupt
) Nothing
let txSettings = Just (H.ReadCommitted, Just True) let txSettings = Just (H.ReadCommitted, Just True)
dbOrError <- H.session pool $ H.tx txSettings $ getDbStructure (cs $ configSchema conf) dbOrError <- H.session pool $ H.tx txSettings $ getDbStructure (cs $ configSchema conf)
dbStructure <- either hasqlError return dbOrError dbStructure <- either hasqlError return dbOrError