Skip to content

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

Description

@hazyhaar

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.

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions