I'm debugging a Haskell program using GHC's debugger (ghci
) or via stack ghci
, specifically with the Haskell GHCi Debug Adapter (Phoityne extension) in Visual Studio Code, and I'm encountering a major issue when stopping the debugger:
- If my program enters a long-running loop or gets stuck in a computation, clicking the "Stop" icon in my debugger interface causes my computer to freeze.
- The mouse and keyboard inputs become unresponsive, and eventually, the system slows down to the point where I cannot even open
htop
to identify which process is consuming resources. - I'm left with no option but to force a reboot.
I suspect that some resources (e.g., threads, memory allocations, or file handles) are not being properly released when stopping the debugger.
Some code
readMSet :: FilePath -> IO (MSet String)
readMSet fileName = do
content <- readFile fileName
let mset = processMSet content
return mset
processMSet :: String -> MSet String
processMSet content =
let ls = lines content
in foldl add (MS []) ls -- Create the multiset
main = do
m1 <- readMSet "path_to_file"
In particular, my debugger crashes in the main function, probably due to issues related to lazy evaluation. I suspect I might need to use DeepSeq to force evaluation, but that's not the principal issue for this topic.
System details
- GHC Version / Stack: GHC 8.8.4 / 3.1.1
- OS Version : Ubuntu 22.04.5 LTS
- IDE : Visual studio code with the Haskell GHCi Debug Adapter (Phoityne extension)
Any insights or workarounds would be greatly appreciated! Is there a specific setup or practice for handling such situations in Haskell debugging?
What i'm expecting:
Is there a way to set a timer or timeout to automatically clean up (free) resources if a computation gets stuck in a loop or runs for too long?
Can I configure the debugger (or
ghci
) to safely terminate processes and free up system resources when I quit using the stop button?
What i've tried:
- I've tried to manually interrupting with
Ctrl+C
, but the system still becomes unresponsive after stopping.
--ghc-options="+RTS -M1G"
(or whatever size is reasonable instead of1G
) to thestack ghci
invocation specified byghciCmd
in the Phoityne configuration.foldl
with eitherfoldl'
(the strict left fold) orfoldr
, depending on exactly what you are doing. See e.g. foldl versus foldr behavior with infinite lists.