Skip to content

Commit 91774ab

Browse files
committed
fix: shutdown should wait for in flight requests
1 parent b18b1a5 commit 91774ab

4 files changed

Lines changed: 12 additions & 5 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ All notable changes to this project will be documented in this file. From versio
1919
- Log error when `db-schemas` config contains schema `pg_catalog` or `information_schema` by @taimoorzaeem in #4359
2020
+ Now fails at startup. Prior to this, it failed with `PGRST205` on requests related to these schemas.
2121

22+
### Fixed
23+
24+
- Shutdown should wait for in flight requests by @mkleczek in #4702
25+
2226
## [14.6] - 2026-03-06
2327

2428
### Fixed

src/PostgREST/App.hs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import GHC.IO.Exception (IOErrorType (..))
2222
import System.IO.Error (ioeGetErrorType)
2323

2424
import Control.Monad.Except (liftEither)
25+
import Control.Monad.Extra (whenJust)
2526
import Data.Either.Combinators (mapLeft, whenLeft)
2627
import Data.Maybe (fromJust)
2728
import Data.String (IsString (..))
@@ -30,6 +31,7 @@ import Network.Wai.Handler.Warp (defaultSettings, setHost,
3031
setServerName)
3132

3233
import qualified Data.Text.Encoding as T
34+
import qualified Network.Socket as NS
3335
import qualified Network.Wai as Wai
3436
import qualified Network.Wai.Handler.Warp as Warp
3537

@@ -72,7 +74,10 @@ run appState = do
7274
conf@AppConfig{..} <- AppState.getConfig appState
7375

7476
AppState.schemaCacheLoader appState -- Loads the initial SchemaCache
75-
Unix.installSignalHandlers (AppState.getMainThreadId appState) (AppState.schemaCacheLoader appState) (AppState.readInDbConfig False appState)
77+
let closeSockets = do
78+
whenJust (AppState.getSocketAdmin appState) NS.close
79+
NS.close $ AppState.getSocketREST appState
80+
Unix.installSignalHandlers closeSockets (AppState.schemaCacheLoader appState) (AppState.readInDbConfig False appState)
7681

7782
Listener.runListener appState
7883

src/PostgREST/Unix.hs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,9 @@ import System.Directory (removeFile)
1818
import System.IO.Error (isDoesNotExistError)
1919

2020
-- | Set signal handlers, only for systems with signals
21-
installSignalHandlers :: ThreadId -> IO () -> IO () -> IO ()
21+
installSignalHandlers :: IO () -> IO () -> IO () -> IO ()
2222
#ifndef mingw32_HOST_OS
23-
installSignalHandlers tid usr1 usr2 = do
24-
let interrupt = throwTo tid UserInterrupt
23+
installSignalHandlers interrupt usr1 usr2 = do
2524
install Signals.sigINT interrupt
2625
install Signals.sigTERM interrupt
2726
install Signals.sigUSR1 usr1

test/io/test_io.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ def sleep():
105105
t.join()
106106

107107

108-
@pytest.mark.xfail(reason="Graceful shutdown is currently failing")
109108
def test_graceful_shutdown_waits_for_in_flight_request(defaultenv):
110109
"SIGTERM should allow in-flight requests to finish before exiting"
111110

0 commit comments

Comments
 (0)