Use async-safe bracket for withTempFileName
commit4a0b05a38731aabc120645b828d59e67a246cda0
authorRobert Vollmert <rob@vllmrt.net>
Fri, 28 Jan 2022 23:18:04 +0000 (29 00:18 +0100)
committermergify-bot <noreply@mergify.com>
Wed, 23 Feb 2022 08:19:22 +0000 (23 08:19 +0000)
tree876c5bb5a617a454307ed862c571265cfd5b9097
parentdeca6e7bcc76a510a0794630b701c00f3817ee50
Use async-safe bracket for withTempFileName

If `withTempFileName` receives an asynchronous exception (e.g.
a canceled async), the bracket cleanup handler will attempt to
remove the temporary file. This can fail with an IO exception.

Regular bracket then throws that IO exception, swallowing the
asynchronous exception. To calling code, this appears no different
from an IO exception thrown from the body, and it won't be able
to tell that it should be exiting promptly.

This manifests concretely during temporary file clean-up of
`asyncFetchPackages` on Windows (seen during unit testing in CI),
where temporary file removal fails (on GHC 8.4), which leads
to `concurrently` failing to cancel the outstanding download
because it's handled like a regular download failure.
cabal-install/src/Distribution/Client/Utils.hs