New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
withTempDirectory doesn't always delete the temporary directory #3
Comments
They are, but unfortunately, that's impossible; see here. That said, you bring up a very good point, which probably deserves its own section in that article. I agree with your reasoning and would accept a pull request that implements (1) and documents this semantics in the haddocks. |
Hey @bitc, I added a test that check that withTempDirectory deletes its directory. The test passes without any changes to the code (such as I think this because both If you disagree with my analysis, I'd be curious to see a test case that demonstrates this possibility. |
I still believe that what I originally wrote still applies. But:
|
Looking at your test, I have a feeling that 100 temporary files may not be enough. Maybe try bumping that number up to a much much higher number? |
This function uses
bracket
which splits it up into three stages:Consider the following scenario:
This is not good. "with-style" functions are expected to guarantee proper and complete clean up of their resources. And this is not just a theoretical issue: there is a significant likelihood that the problem can occur in practice, for example with a program that uses a temporary directory with many files and the user presses Ctrl-C.
I have 3 ideas:
Idea (2) has the attractive quality of avoiding the use of scary "uninterruptibleMask". But it is dangerous because it can leave behind the temporary directory in unexpected ways. For example, with this approach, the trivial program
main = withTempDirectory "/tmp" "tmp" (pure ())
might not delete the temporary directory if Ctrl-C is pressed just at the right moment.I believe that idea (1) is the best solution. Note that, in a sense, the current code already uses "uninterruptibleMask" for each individual file delete operation (they are blocking FFI calls). So switching to one big scary "uninterruptibleMask" does not morally change anything about the interruptible-ness property of the function.
The text was updated successfully, but these errors were encountered: