Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net/http: ServeMux behaves inconsistently across operating systems #66288

Closed
vlence opened this issue Mar 13, 2024 · 3 comments
Closed

net/http: ServeMux behaves inconsistently across operating systems #66288

vlence opened this issue Mar 13, 2024 · 3 comments
Labels
WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.

Comments

@vlence
Copy link

vlence commented Mar 13, 2024

Go version

go version go1.22.1 windows/amd64

Output of go env in your module/workspace:

set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\victo\AppData\Local\go-build
set GOENV=C:\Users\victo\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\victo\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\victo\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\Program Files\Go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLCHAIN=auto
set GOTOOLDIR=C:\Program Files\Go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.22.1
set GCCGO=gccgo
set GOAMD64=v1
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=C:\Users\victo\personal-projects\enhance-rewrite\go.mod
set GOWORK=
set CGO_CFLAGS=-O2 -g
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-O2 -g
set CGO_FFLAGS=-O2 -g
set CGO_LDFLAGS=-O2 -g
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=C:\Users\victo\AppData\Local\Temp\go-build3178868854=/tmp/go-build -gno-record-gcc-switches

What did you do?

I decided to try the new http.ServeMux but it seems the pattern matching behaves inconsistently across operating systems. Basically my route never gets matched and a 404 gets returned, even though the request has the exact same method and path as the one configured for the route.

I am developing on a Windows 10 machine but when I try the same code on a Linux machine I get a different result. I don't have a Linux machine at hand so I ran the code on the Go playground, which I'm assuming is running on Linux servers (a quick loop of os.Environ() in Go playground also suggests this).

Here's a small example to demonstrate the problem.

package main

import (
	"log"
	"net/http"
	"net/url"
)

func main() {
	mux := http.NewServeMux()
	h := func(w http.ResponseWriter, r *http.Request) {}
	mux.HandleFunc("GET /some/path", h)
	r := &http.Request{
		Method: "GET",
		URL:    &url.URL{Path: "/some/path"},
	}
	_, pattern := mux.Handler(r)

	log.Printf("pattern: \"%s\"\n", pattern)
}

What did you see happen?

I get the following output.

$ pattern: ""

I want to emphasize again that this seems to happen only on Windows.

What did you expect to see?

I expected the following output.

$ pattern: "GET /some/path"

I get this output only in Go playground which I'm assuming is running Linux.

@seankhliao
Copy link
Member

please show your go.mod files for both environments.

@seankhliao seankhliao added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Mar 13, 2024
@vlence
Copy link
Author

vlence commented Mar 13, 2024

Here's my go.mod in my Windows 10 machine.

module github.com/vlence/httpserver

go 1.21.5

require (
	github.com/gorilla/mux v1.8.1
	github.com/mattn/go-sqlite3 v1.14.19
)

require github.com/jmoiron/sqlx v1.3.5

I copied the code straight into Go playground so no go.mod file there.

@vlence
Copy link
Author

vlence commented Mar 13, 2024

Ah gg the go directive.

Didn't know how it worked.

Now I know.

Thanks for your time.

@vlence vlence closed this as completed Mar 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

2 participants