Repository navigation
Cancel running Statistics task when its workspace closes - #3282
Merged
Merged
Conversation
A Statistics algorithm holds the graph read lock for its entire run. If the workspace/project is closed while one is still running, nothing signalled it to stop, so shutdown could hang indefinitely waiting on that lock. Mirror LayoutControllerImpl.close(Workspace) by cancelling any running Statistics LongTask when its workspace closes. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2 of 3 tasks
pull Bot
pushed a commit
to kp-forks/gephi
that referenced
this pull request
Aug 31, 2026
Follow-up to gephi#3282, which cancels a running Statistics task when its workspace closes but only wired the trigger. Several algorithms didn't actually honor that signal: - ConnectedComponents' directed-graph path (Tarjan's SCC) and parts of ClusteringCoefficient never checked the cancellation flag, so cancelling had no effect on them. - Modularity, ConnectedComponents, and StatisticalInferenceClustering reset their cancellation flag a second time inside a helper called under the read lock, silently erasing a cancel requested in the narrow window between the outer reset and the lock acquisition. - Cancelling ClusteringCoefficient, Modularity, or StatisticalInferenceClustering mid-run could leave partially-built result state that NPE'd when read back, popping an error dialog during what should be a silent shutdown-time cancellation. They now return early with no result instead. - All cancellation flags in this module were plain, non-volatile booleans, with no guaranteed visibility across the thread that requests cancellation and the thread running the algorithm; made them all volatile. - Dynamic statistics (e.g. DynamicClusteringCoefficient) weren't wired to the cancel signal at all: the per-tick loop checked a separate DynamicLongTask flag rather than the wrapped statistic's own cancel state. Added a default DynamicStatistics#isCancelled(), overridden by the LongTask-implementing dynamic statistics, and had DynamicLongTask check it too. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.
Description
A Statistics algorithm (e.g. GraphDistance, Modularity, PageRank, ClusteringCoefficient) holds the graph read lock for its entire run. Previously, nothing signalled a running Statistics task to stop when its workspace/project closed —
StatisticsTopComponent'sWorkspaceListener.closewas an empty no-op. If the workspace closed while a statistic was still running, shutdown could hang indefinitely waiting on that lock.This mirrors the existing precedent in
LayoutControllerImpl.close(Workspace), which cancels a running layout on workspace close:StatisticsTopComponent.close(Workspace)now cancels any currently runningStatistics(that implementsLongTask) for that workspace via a newStatisticsModelUIImpl#getRunning()accessor.Cancellation is intentionally only wired into
close, notunselect—unselectfires on ordinary workspace switching too, and a running statistic should keep running when the user just navigates to another workspace.Known follow-ups, deliberately out of scope for this PR:
ConnectedComponents's directed-graph path, parts ofClusteringCoefficient) don't check their cancellation flag throughout their locked computation, so cancellation may not unwind promptly for those.StatisticsPluginaren'tvolatile.ProjectControllerImplfiresUNSELECTfor the whole project beforeCLOSEfor any workspace, and some other component'sunselecthandler can itself block on the graph write lock before ourclosehandler runs — so this doesn't close every possible variant of the hang.Checklist
Added tests?
Added to documentation?