diff --git a/app/src/App/CLI/Purs.purs b/app/src/App/CLI/Purs.purs index b32d1801..c6f2bad2 100644 --- a/app/src/App/CLI/Purs.purs +++ b/app/src/App/CLI/Purs.purs @@ -205,7 +205,9 @@ isCompilerRaceCondition failure = case failure of _ -> false -- | Compile PureScript source files with automatic retry for transient errors. --- | Retries up to 3 times when the "Unexpected end of JSON input" race condition occurs. +-- | Uses bounded retries when the "Unexpected end of JSON input" race condition occurs. +-- | Package builds that exhaust the heap get one serial, compacting attempt with +-- | the same heap limit, using the profile already used for whole package sets. compile :: forall r . { globs :: Array FilePath, profile :: CompileProfile, version :: Maybe Version, cwd :: Maybe FilePath } @@ -218,6 +220,11 @@ compile { globs, profile, version, cwd } = go 1 go attempt = do result <- Run.liftAff $ callCompiler { command: Compile { globs, profile }, version, cwd } case result of + Left err | isCompilerHeapExhaustion err -> case profile of + PackageBuild -> do + Log.warn "Compiler heap exhausted; retrying once with serial compilation and compacting GC at the same heap limit." + Run.liftAff $ callCompiler { command: Compile { globs, profile: PackageSetBuild }, version, cwd } + PackageSetBuild -> pure result Left err | isCompilerRaceCondition err && attempt < maxRetries -> do Log.warn $ "Compiler race condition detected (attempt " <> show attempt <> "/" <> show maxRetries <> "), retrying..." go (attempt + 1)