Skip to content

Cancel running Statistics task when its workspace closes - #3282

Merged
mbastian merged 1 commit into
masterfrom
fix/statistics-cancel-on-workspace-close
Aug 31, 2026
Merged

mbastian merged 1 commit into
masterfrom
fix/statistics-cancel-on-workspace-close

Conversation

@mbastian

Copy link
Copy Markdown
Member

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's WorkspaceListener.close was 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 running Statistics (that implements LongTask) for that workspace via a new StatisticsModelUIImpl#getRunning() accessor.

Cancellation is intentionally only wired into close, not unselect — unselect fires 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:

  • Some Statistics implementations (e.g. ConnectedComponents's directed-graph path, parts of ClusteringCoefficient) don't check their cancellation flag throughout their locked computation, so cancellation may not unwind promptly for those.
  • Cancellation flags in StatisticsPlugin aren't volatile.
  • ProjectControllerImpl fires UNSELECT for the whole project before CLOSE for any workspace, and some other component's unselect handler can itself block on the graph write lock before our close handler runs — so this doesn't close every possible variant of the hang.

Checklist

  • Merged with master beforehand

Added tests?

  • 👍 yes

Added to documentation?

  • 🙅 no, because they aren't needed

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>
@mbastian
mbastian merged commit bd6ea0c into master Aug 31, 2026
3 checks passed
@mbastian mbastian added this to the 0.11.3 milestone Aug 31, 2026
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>
@mbastian
mbastian deleted the fix/statistics-cancel-on-workspace-close branch November 17, 2026 19:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant