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.
Describe the bug
flow_path_dinfhangs forever when the D-infinity direction grid contains a cycle. The numpy/JIT tracing loop atxrspatial/hydro/flow_path_dinf.py:183useswhile Trueand 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:303has 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 callflow_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.