Skip to content

flow_path_dinf hangs forever on cyclic D-inf flow directions #2796

Description

@brendancol

Describe the bug

flow_path_dinf hangs forever when the D-infinity direction grid contains a cycle. The numpy/JIT tracing loop at xrspatial/hydro/flow_path_dinf.py:183 uses while True and only breaks on NaN, a pit (angle < 0), the grid edge, or out-of-bounds. There's no visited-cell guard and no step cap. A two-cell cycle like [[0, pi]] (cell 0 points east to cell 1, cell 1 points west back to cell 0) never terminates.

The Dask tracing loop at xrspatial/hydro/flow_path_dinf.py:303 has the same flaw, and it's worse there: each iteration appends to growing buffers, so a cyclic grid leaks memory until the process dies.

Expected behavior

Tracing a cyclic grid should terminate. A path can visit each cell at most once before it has to revisit one, so capping each path at H*W steps is enough to break any cycle. When tracing hits that cap, it should stop that path and move on instead of spinning forever.

Steps to reproduce

Build a direction grid like [[0, pi]], put a start point at cell (0,0), and call flow_path_dinf. It hangs.

Additional context

The fix needs to cover both the numpy/JIT loop and the Dask loop. A step cap of H*W per path plus a regression test that asserts termination (not a wall-clock timeout) would close this.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingseverity:highSweep finding: HIGH

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions