refactor: move pool release on shutdown out of signal handler

This changes behaviour somewhat in that:
- We now consistently release the pool on shutdown, even on non-Unix
  platforms, and including for CmdDumpConfig.
- We release the pool *after* interrupting `App.run`, which will
  rather cause more than fewer connection to be closed properly.
  (Previously any in-use connections would not have been caught by
  `releasePool`, though *maybe* the `UserInterrupt` handling in
  the web handler ends up closing the connections properly already
  anyway).

(The main aim of the change is to make it clearer when and why the
pool is released.)
This commit is contained in:
Robert Vollmert
2022-08-03 19:02:33 +02:00
committed by Robert
parent c5849ecbe0
commit 92d00749a3
3 changed files with 18 additions and 13 deletions
+1 -5
View File
@@ -43,11 +43,7 @@ runAppWithSocket settings app socketFileMode socketFilePath =
-- | Set signal handlers, only for systems with signals
installSignalHandlers :: AppState.AppState -> IO ()
installSignalHandlers appState = do
-- Releases the connection pool whenever the program is terminated,
-- see https://github.com/PostgREST/postgrest/issues/268
let interrupt = do
AppState.releasePool appState
throwTo (AppState.getMainThreadId appState) UserInterrupt
let interrupt = throwTo (AppState.getMainThreadId appState) UserInterrupt
install Signals.sigINT interrupt
install Signals.sigTERM interrupt