Skip to content

net/http: server mux says two routes conflict when they don't #69760

@rwrobe

Description

@rwrobe

Go version

go 1.22.4

Output of go env in your module/workspace:

GO111MODULE='on'
GOARCH='arm64'
GOBIN=''
GOCACHE='/Users/user/Library/Caches/go-build'
GOENV='/Users/user/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/user/go/1.22.4/pkg/mod'
GONOPROXY='gitlab.com/feltgis'
GONOSUMDB='gitlab.com/feltgis'
GOOS='darwin'
GOPATH='/Users/user/go/1.22.4'
GOPRIVATE='gitlab.com/feltgis'
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/Users/user/go/1.22.4/pkg/mod/golang.org/toolchain@v0.0.1-go1.23.0.darwin-arm64'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/Users/user/go/1.22.4/pkg/mod/golang.org/toolchain@v0.0.1-go1.23.0.darwin-arm64/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.23.0'
GODEBUG=''
GOTELEMETRY='local'
GOTELEMETRYDIR='/Users/user/Library/Application Support/go/telemetry'
GCCGO='gccgo'
GOARM64='v8.0'
AR='ar'
CC='clang'
CXX='clang++'
CGO_ENABLED='1'
GOMOD='/Users/user/Dev/feltgis/go/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/9x/8_5z0gq139g8px0h08h02yvm0000gn/T/go-build147542617=/tmp/go-build -gno-record-gcc-switches -fno-common'

What did you do?

Adding some routes to a server (the API design is bad, but it isn't mine and I need to match the contract):

	mux.Handle("/v1/rsrc/path1/{geoID}/path2/{orderID}/", ...
	mux.Handle("/v1/rsrc/{geoID}/path2/{orderID}/", ...

What did you see happen?

panic: pattern "/v1/rsrc/{geoID}/path2/{orderID}/" (registered at /Users/user/Dev/feltgis/go/pkg/introspectmux/introspect_mux.go:32) conflicts with pattern "/v1/rsrc/path1/{geoID}/path2/{orderID}/" (registered at /Users/user/Dev/feltgis/go/pkg/introspectmux/introspect_mux.go:32):
	/v1/rsrc/{geoID}/path2/{orderID}/ and /v1/rsrc/path1/{geoID}/path2/{orderID}/ both match some paths, like "/v1/rsrc/path1/path2/path2/orderID/".
	But neither is more specific than the other.
	/v1/rsrc/{geoID}/path2/{orderID}/ matches "/v1/rsrc/geoID/path2/orderID/", but /v1/rsrc/path1/{geoID}/path2/{orderID}/ doesn't.
	/v1/rsrc/path1/{geoID}/path2/{orderID}/ matches "/v1/rsrc/path1/geoID/path2/orderID/", but /v1/rsrc/{geoID}/path2/{orderID}/ doesn't.

What did you expect to see?

The paths should not conflict because the routes refer to different resources. Of course, the better design for this API is:

	mux.Handle("/v1/path1/{geoID}/path2/{orderID}/", ...
	mux.Handle("/v1/rsrc/{geoID}/path2/{orderID}/", ...

But I'm constrained to use this one to satisfy legacy contracts:

	mux.Handle("/v1/rsrc/path1/{geoID}/path2/{orderID}/", ...
	mux.Handle("/v1/rsrc/{geoID}/path2/{orderID}/", ...

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions