#4851·gin

Pooled skippedNodes keeps the capacity captured at allocation, causing panic in getValue when routes are registered late

Author: hazyhaarCreated Sep 24, 2026Updated Sep 24, 2026

Summary

getValue grows the backtrack stack with a raw reslice (*skippedNodes)[:index+1], assuming capacity equals Engine.maxSections. However, skippedNodes capacity is captured when the context pool allocates it. Routes registered after a context is already created raise maxSections without resizing the pooled slice. The next request needing an additional backtrack frame panics with: runtime error: slice bounds out of range inside the router before any middleware or handler.

Steps to Reproduce

  1. Register GET /a and serve a warmup request (pooled context capacity = 1).
  2. Register additional nested routes: GET /x/y/z/w, GET /x/y/:id/w, GET /x/:id/z/w, GET /:id/y/z/w.
  3. Serve POST /x/y/z/w/extra with router.HandleMethodNotAllowed = true.
  4. Result: panic: runtime error: slice bounds out of range [:2] with capacity 1.

Proposed Fix

Grow skippedNodes with append instead of raw reslicing.

A Pull Request addressing this is submitted concurrently.