AI & Agent Dev Bug Sandbox logo
AI & Agent Dev Bug Sandbox
Back to Radar

Turbopack OutputFileTracingIncludes Glob Walk Crashes With ELOOP On Pnpm Nested Workspace Symlink Cycles

When `outputFileTracingIncludes` is configured, the include-glob walk traverses the entire tracing root and follows symlinks without robust cycle detection. In legal pnpm workspaces where a package nested inside another declares its ancestor as dependency, this creates a self-embedding symlink chain that triggers ELOOP and fails the build.

highConfidence 85%Next.js (Turbopack)Affected V16.3.0Affected V16.3.1Affected V16.3.1-Canary.22

Origin Analysis

`resolve_symlink_safely` in `read_glob.rs` only checks whether a symlink's target is an ancestor of the symlink's virtual path. For multi-hop cycles entered through hoisted paths like `app/node_modules/shared`, neither target is an ancestor, so the detection never fires and recursion continues until the OS returns ELOOP.
1. Clone https://github.com/Stanzilla/turbopack-symlink-cycle-repro\n2. Run `pnpm install`\n3. Run `pnpm --filter app exec next build`\nObserve `TurbopackInternalError: Failed to write app endpoint /page` with `Too many levels of symbolic links`.

Fixing Code Block

Edge Case Audit

Canonicalizing every directory may add filesystem overhead, especially on large monorepos. The fallback to non-canonical root on error could still miss a cycle if canonicalization fails transiently. The visited set is per `read_glob` invocation and is not thread-safe, so concurrent reads are isolated. The change modifies the glob walk behavior: entries after the first occurrence of a cycle target are silently skipped, which could omit legitimate assets if the build relied on symlink traversal for pattern matching. Rolling back to previous behavior is possible by reverting this patch, but then builds with cyclic symlinks will fail again. For persistent defense, consider using inode/dev pairs on Unix and file IDs on Windows instead of canonical path strings, and add tests for nested pnpm layouts.

Ecosystem Topology