Skip to content

Traversal without unique() never terminates on cycles (OOMs test suite) #10

Closed

Description

@michaeloboyle

Problem

TraversalQuery.toArray() only consults visited when .unique() is set (src/query/TraversalQuery.ts:235). Without .unique() and without maxDepth, any cycle makes the BFS queue grow forever.

Repro:

const g = new GraphDatabase(':memory:');
const x = g.createNode('T', {}), y = g.createNode('T', {});
g.createEdge(x.id, 'CYC', y.id); g.createEdge(y.id, 'CYC', x.id);
g.traverse(x.id).out('CYC').toArray(); // never returns

With maxDepth(6) it returns 6 rows for 2 distinct nodes and re-includes the start node.

Impact

  • tests/unit/TraversalQuery.test.ts OOMs at ~4 GB (the fixture has an F→C cycle; tests at lines 288, 321, 382 call toArray() without maxDepth).
  • tests/integration/graph-operations.test.ts times out.
  • Masked by CI || true (separate issue).

Expected

Non-unique traversal keeps returning a node once per distinct path (test should work without unique() - allow duplicates), but must not revisit a node already on the current path. That terminates on every finite graph.

Benchmark report: 2026-11-02, Apple M2 Pro, Node 22, at a7f9ea7.

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 working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions