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
- Register
GET /aand serve a warmup request (pooled context capacity = 1). - Register additional nested routes:
GET /x/y/z/w,GET /x/y/:id/w,GET /x/:id/z/w,GET /:id/y/z/w. - Serve
POST /x/y/z/w/extrawithrouter.HandleMethodNotAllowed = true. - 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.
Source: gin-gonic/gin