
On Wed, May 8, 2013 at 8:12 PM, Jason Dagit
On Wed, May 8, 2013 at 6:54 PM, Niklas Hambüchen
wrote: I have an annoying bug in a C binding that can be triggered like this:
handle <- open ...
prep <- makePreparedStatement handle "INSERT ..."
performGC
runStatement prep
close handle
If I run these steps one by one in ghci, garbage ends up in my handle as expected.
However, if I "let main = do ..." this whole block in order to pack it in a test case, it does not happen, neither in ghci nor ghc.
What might be the special magic in ghci's REPL that allows me to trigger my bug so easily there?
One thing to investigate: Thread Local Storage
By default ghci puts each action you run into a thread and executes it. If the underlying C code stores something (or accesses it) from thread local storage, then you will run into issues like this.
My point was meant to be, it's something to try but I have no idea if it's going to be the issue here. The caveat I forgot to add is: I've never seen the thread local storage issue affect GC. In particular, ghc might be running a finalizer in the case of individual actions because it doesn't know you are about to use the handle? Now that I think about it more, I suspect that is more likely to be the case. Jason