From 1d8d9341572901b77841589b1efd042cb7ae5649 Mon Sep 17 00:00:00 2001 From: Puru Gupta Date: Fri, 7 Jul 2023 04:29:49 +0530 Subject: [PATCH] server: fix race condition in `reloadAppContext` PR-URL: https://github.com/hasura/graphql-engine-mono/pull/9788 GitOrigin-RevId: c6b9441e4f4e12fea6ad4e5b336f3231fc4494d2 --- server/src-lib/Hasura/Server/AppStateRef.hs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/server/src-lib/Hasura/Server/AppStateRef.hs b/server/src-lib/Hasura/Server/AppStateRef.hs index cad6a206de1..a8cb0cba8f2 100644 --- a/server/src-lib/Hasura/Server/AppStateRef.hs +++ b/server/src-lib/Hasura/Server/AppStateRef.hs @@ -276,11 +276,12 @@ updateAppStateRef :: (MonadIO m, MonadBaseControl IO m) => AppStateRef impl -> L.Logger L.Hasura -> - RebuildableAppContext impl -> - RebuildableSchemaCache -> + (RebuildableAppContext impl -> m (RebuildableAppContext impl, RebuildableSchemaCache)) -> m () -updateAppStateRef (AppStateRef lock cacheRef metadataVersionGauge) logger !newAppCtx !newSC = +updateAppStateRef appStateRef@(AppStateRef lock cacheRef metadataVersionGauge) logger action = withMVarMasked lock $ const do + rebuildableAppContext <- liftIO $ readAppContextRef appStateRef + (!newAppCtx, !newSC) <- action rebuildableAppContext liftIO do -- update schemacache in IO reference modifyIORef' cacheRef $ \appState ->