Skip to content

[BUG] Orchestrion crashes (along with the go server) when we use Subrouter() function of mux server's router. #4129

@dhunav

Description

@dhunav

DESCRIPTION

Version of orchestrion
latest (1.6.1)

Describe what happened:

Orchestrion errors when route.Subrouter() function is used but works perfectly without it.
(Code shared below)

This is the error:

http: panic serving 10.253.12.171:38516: runtime error: invalid memory address or nil pointer dereference
goroutine 473 [running]:
net/http.(*conn).serve.func1()
	/agent/_work/_tool/go/1.24.6/arm64/src/net/http/server.go:1947 +0xb0
panic({0x12a2a00?, 0x2dc87a0?})
	/agent/_work/_tool/go/1.24.6/arm64/src/runtime/panic.go:792 +0x124
github.com/gorilla/mux.(*Router).ServeHTTP(0x40004186c0, {0x17d9610, 0x4001706940}, 0x400057cf00)
	<generated>:2 +0x34
github.com/DataDog/dd-trace-go/contrib/net/http/v2/internal/wrap.TraceAndServe({0x17c8780, 0x40004186c0}, {0x17d9940?, 0x400166e0e0?}, 0x4000f1aac8?, 0x86188?)
	/root/go/pkg/mod/github.com/!data!dog/dd-trace-go/contrib/net/http/[email protected]/internal/wrap/trace.go:23 +0x8c
github.com/DataDog/dd-trace-go/contrib/net/http/v2/internal/wrap.Handler.func1({0x17d9940, 0x400166e0e0}, 0x400057cdc0)
	/root/go/pkg/mod/github.com/!data!dog/dd-trace-go/contrib/net/http/[email protected]/internal/wrap/handler.go:48 +0x2e4
net/http.HandlerFunc.ServeHTTP(0x0?, {0x17d9940?, 0x400166e0e0?}, 0x4000f1ab60?)
	/agent/_work/_tool/go/1.24.6/arm64/src/net/http/server.go:2294 +0x38
net/http.serverHandler.ServeHTTP({0x4000ea0390?}, {0x17d9940?, 0x400166e0e0?}, 0x1?)
	/agent/_work/_tool/go/1.24.6/arm64/src/net/http/server.go:3301 +0xbc
net/http.(*conn).serve(0x400058ab40, {0x17dd350, 0x4000f09a10})
	/agent/_work/_tool/go/1.24.6/arm64/src/net/http/server.go:2102 +0x52c
created by net/http.(*Server).Serve in goroutine 160
	/agent/_work/_tool/go/1.24.6/arm64/src/net/http/server.go:3454 +0x45c


Describe what you expected:

Same result in both the cases.

Steps to reproduce the issue:

Here is an example code:

import (
	"context"
	"net/http"
	"strings"

	"github.com/gorilla/mux"
)

func (s *Server) SetRouter(prefix string) *mux.Router {
	router := mux.NewRouter()
	prefix = "/" + strings.Trim(prefix, "/")

	// ERRORS
	// if prefix != "/" {
	// 	router = router.PathPrefix(prefix).Subrouter()
	// }
	// router.HandleFunc("/healthz", s.HealthHandler)

	// WORKS
	router.HandleFunc(prefix+"/healthz", s.HealthHandler)
}

Additional environment details (Version of Go, Operating System, etc.):
Go version: 1.24
OS: Mac/Linux.

Metadata

Metadata

Assignees

Labels

bugunintended behavior that has to be fixed

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions