Skip to content

fix(pageserver): prevent stack overflow in count_deltas#12904

Open
AesaKamar wants to merge 1 commit into
neondatabase:mainfrom
AesaKamar:test-layer-map-overflow
Open

fix(pageserver): prevent stack overflow in count_deltas#12904
AesaKamar wants to merge 1 commit into
neondatabase:mainfrom
AesaKamar:test-layer-map-overflow

Conversation

@AesaKamar

Copy link
Copy Markdown

Summary

This PR fixes a stack overflow in the pageserver's LayerMap::count_deltas function (resolving #3711).

  1. Iterative Stack Machine: Converted the recursive DFS traversal of the historical layer map into an iterative, stack-based algorithm utilizing a heap-allocated task stack. This prevents call stack exhaustion when evaluating very deep delta layer maps (such as during active GC and compaction).
  2. Regression Test: Added test_count_deltas_stack_overflow in layer_map.rs which verifies that evaluating a stack of 10,000 delta layers completes successfully without crashing.

P.S. This is another contribution following up on my first PR! The iterative version runs safely and extremely fast (the regression test passes in <0.3s). I would love any feedback on the implementation!

@AesaKamar AesaKamar force-pushed the test-layer-map-overflow branch from c3a1d22 to 0c2c57e Compare June 2, 2026 16:14
@AesaKamar AesaKamar marked this pull request as ready for review June 2, 2026 16:17
@AesaKamar AesaKamar requested a review from a team as a code owner June 2, 2026 16:17
@AesaKamar AesaKamar requested a review from banks June 2, 2026 16:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant