Skip to content

Cabal writes and rewrites dist/setup-config, causing access denied #11619

@Bodigrim

Description

@Bodigrim

-- | After running configure, output the 'LocalBuildInfo' to the
-- 'localBuildInfoFile'.
writePersistBuildConfig
:: Maybe (SymbolicPath CWD (Dir Pkg))
-- ^ Working directory
-> SymbolicPath Pkg (Dir Dist)
-- ^ The @dist@ directory path.
-> LocalBuildInfo
-- ^ The 'LocalBuildInfo' to write.
-> IO ()
writePersistBuildConfig mbWorkDir distPref lbi = do
createDirectoryIfMissing False (i distPref)
writeFileAtomic (i $ localBuildInfoFile distPref) $
BLC8.unlines [showHeader pkgId, structuredEncode lbi]
where
i = interpretSymbolicPath mbWorkDir -- See Note [Symbolic paths] in Distribution.Utils.Path
pkgId = localPackage lbi

While working on #10938, I noticed that writePersistBuildConfig is the most common source of race for file I/O. It seems like not only writePersistBuildConfig is executed more than once during the same build process, but it can happen to be executed concurrently from multiple Cabal threads, leading to self-imposed file access violation.

(localBuildInfoFile corresponds to dist/setup-config file)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions