diff --git a/CHANGELOG.md b/CHANGELOG.md
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,9 @@
 # Revision history for pms-infrastructure
 
+## 0.0.2.0 -- 2025-06-15
+
+* Added finally to expect to ensure the lock is released.
+
 ## 0.0.1.0 -- 2025-05-31
 
-* First version. Released on an unsuspecting world.
+* First version.
diff --git a/pms-infrastructure.cabal b/pms-infrastructure.cabal
--- a/pms-infrastructure.cabal
+++ b/pms-infrastructure.cabal
@@ -20,7 +20,7 @@
 -- PVP summary:     +-+------- breaking API changes
 --                  | | +----- non-breaking API additions
 --                  | | | +--- code changes with no API change
-version:            0.0.1.0
+version:            0.0.2.0
 
 -- A short (one-line) description of the package.
 synopsis:           pms-infrastructure
diff --git a/src/PMS/Infrastructure/DS/Core.hs b/src/PMS/Infrastructure/DS/Core.hs
--- a/src/PMS/Infrastructure/DS/Core.hs
+++ b/src/PMS/Infrastructure/DS/Core.hs
@@ -319,19 +319,32 @@
     errHdl :: E.SomeException -> IO ()
     errHdl e = callback (ExitFailure 1) "" (show e)
 
-
 -- |
 --
 expect :: STM.TMVar () -> Pty -> [String] -> IO (Maybe String)
-expect lock pms prompts = do
-  m <- STM.atomically $ STM.tryTakeTMVar lock
-  case m of
-    Nothing -> return Nothing
-    Just () -> do
-      hPutStrLn stderr $ "[INFO] expect: " ++ show prompts
-      output <- readUntilPrompt pms prompts
-      STM.atomically $ STM.putTMVar lock ()
-      return $ Just $ T.unpack $ TE.decodeUtf8 output
+expect lock pty prompts = STM.atomically (STM.tryTakeTMVar lock) >>= \case
+  Nothing -> do
+    hPutStrLn stderr "[INFO] expect running. skip."
+    return Nothing
+  Just () -> flip E.catchAny exception $ flip E.finally finalize $ do
+    hPutStrLn stderr $ "[INFO] expect: " ++ show prompts
+    output <- readUntilPrompt pty prompts
+    let result = T.unpack (TE.decodeUtf8 output)
+    return (Just result)
+
+  where
+    -- |
+    --
+    exception :: E.SomeException -> IO (Maybe String)
+    exception e = do
+      hPutStrLn stderr $ "[ERROR] expect exception: " ++ show e
+      return . Just . show $ e
+
+    -- |
+    --
+    finalize :: IO ()
+    finalize = STM.atomically $ STM.putTMVar lock ()
+
 
 -- |
 --
