Skip to content

Commit e29e17d

Browse files
committed
lsm-tree: do not close HasBlockIO in closeSession
`HasBlockIO` is passed into `openSession` by the user, so it should also be closed by the user. Otherwise, it would prevent reuse of `HasBlockIO`. This bug popped up in the test we add in the next commit.
1 parent 90c5542 commit e29e17d

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

src/Database/LSMTree/Internal/Unsafe.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,6 @@ closeSession Session{sessionState, sessionTracer} = do
512512
(void . swapMVar (sessionOpenTables seshEnv))
513513
mapM_ (delayedCommit reg . close) tables
514514

515-
delayedCommit reg $ FS.close (sessionHasBlockIO seshEnv)
516515
delayedCommit reg $ FS.hUnlock (sessionLockFile seshEnv)
517516

518517
pure SessionClosed

test/Test/Database/LSMTree/StateMachine.hs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ import NoThunks.Class
106106
import Prelude hiding (init)
107107
import System.Directory (removeDirectoryRecursive)
108108
import System.FS.API (FsError (..), HasFS, MountPoint (..), mkFsPath)
109-
import System.FS.BlockIO.API (HasBlockIO, defaultIOCtxParams)
109+
import System.FS.BlockIO.API (HasBlockIO, close, defaultIOCtxParams)
110110
import System.FS.BlockIO.IO (ioHasBlockIO)
111111
import System.FS.IO (HandleIO, ioHasFS)
112112
import qualified System.FS.Sim.Error as FSSim
@@ -297,7 +297,7 @@ propLockstep_RealImpl_RealFS_IO tr (QC.Fixed salt) =
297297
CheckRefs
298298
acquire
299299
release
300-
(\r (_, session, errsVar, logVar) -> do
300+
(\r (_, session, _, errsVar, logVar) -> do
301301
faultsVar <- newMutVar []
302302
let
303303
env :: RealEnv R.Table IO
@@ -314,18 +314,19 @@ propLockstep_RealImpl_RealFS_IO tr (QC.Fixed salt) =
314314
)
315315
tagFinalState'
316316
where
317-
acquire :: IO (FilePath, Class.Session R.Table IO, StrictTVar IO Errors, StrictTVar IO ErrorsLog)
317+
acquire :: IO (FilePath, Class.Session R.Table IO, HasBlockIO IO HandleIO, StrictTVar IO Errors, StrictTVar IO ErrorsLog)
318318
acquire = do
319319
(tmpDir, hasFS, hasBlockIO) <- createSystemTempDirectory "prop_lockstepIO_RealImpl_RealFS"
320320
session <- R.openSession tr hasFS hasBlockIO salt (mkFsPath [])
321321
errsVar <- newTVarIO FSSim.emptyErrors
322322
logVar <- newTVarIO emptyLog
323-
pure (tmpDir, session, errsVar, logVar)
323+
pure (tmpDir, session, hasBlockIO, errsVar, logVar)
324324

325-
release :: (FilePath, Class.Session R.Table IO, StrictTVar IO Errors, StrictTVar IO ErrorsLog) -> IO Property
326-
release (tmpDir, !session, _, _) = do
325+
release :: (FilePath, Class.Session R.Table IO, HasBlockIO IO HandleIO, StrictTVar IO Errors, StrictTVar IO ErrorsLog) -> IO Property
326+
release (tmpDir, !session, hasBlockIO, _, _) = do
327327
!prop <- propNoThunks session
328328
R.closeSession session
329+
close hasBlockIO
329330
removeDirectoryRecursive tmpDir
330331
pure prop
331332

0 commit comments

Comments
 (0)