Don't leave nodes Running forever when a subtree is cancelled - #133
Merged
Merged
Conversation
…atus - Also use STM rather than polling in waitForAllNodesDone
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
printFailureReportwalks every node callingwaitForTree, which retries onNotStartedandRunning. After a cancelled run some nodes were left un-Donefor good, so it hung forever — 4.5 hours on CI before I killed it.Cause
Two gaps, both needed to close it:
runInAsyncinstalledwithException (recordExceptionInStatus ...)inside the action passed tomanagedAsyncWithUnmask, which wraps it inbracketedAction. That bookkeeping has an interruptibleatomically, so an exception delivered as the thread started killed it before the handler existed: nothing wrote a status and the parent'sRunningstood forever.cancelAllChildrenWithonly marked a subtree when the immediate child wasNotStarted. If the child wasRunningit got cancelled, but its own un-started descendants were left behind. It also runs on a thread that is itself unwinding, so it could be interrupted partway and abandon the rest of its children.f09656d fixed part of (2); the CI hang was (1).
Changes
managedAsyncWithUnmaskAndHandler: installs the handler around the whole thread body, bookkeeping included.runInAsyncuses it.markUnfinishedNodesDone(RunTree.hs): give a terminal status to everything in a subtree that lacks one. Used bycancelAllChildrenWithandcancelNode, in afinallyunderuninterruptibleMask_so it survives being interrupted mid-cancel.runNodesConcurrently: its sync-exception path used a baremapM_ cancel asyncs, which had gap (2); routed throughcancelAllChildrenWith.runInAsynconly writesRunningif the node is stillNotStarted, so a finalized subtree can't be resurrected. Retires the-- TODO: fix race condition with writing to runTreeStatuscomment.optionsWarnOnLongExecutionMs/optionsCancelOnLongExecutionMs, previously command-line only, so the test can set them.Test
CancelOnLongExecution.hs: the CI shape (oneintroduceWith, 8-lane pool, 60 tests) run 20 times with a 200ms cancel, asserting nothing is left un-Done. ~6s. Fails 6/6 runs unfixed, passes 15/15 fixed. Fixing only (1) leavesNotStartedstragglers in 3/10 runs.Not touched:
printFailureReportstill callswaitForTreeper node from a finalizer, where blocking is never right — by thenSandwich.hshas waited on the roots and every formatter async.Formatters/Print.hstoo. Better as its own change.