1.22.0 ServeMux HandleFunc infinite loop

371 views
Skip to first unread message

Péter Szarvas

unread,
Feb 7, 2024, 4:21:00 PMFeb 7
to golang-nuts
Hello,

I noticed if you set up a route like /something/{id}/{$}, it results in an infinite loop if I navigate to /someting/ (with the trailing slash). I got a redirect to Location: /something/, and so on. Finally the page breaks after multiple rounds.

Example:
mux := http.NewServeMux()
mux.HandleFunc("/something/{id}/{$}", func...))

Should I raise and issue or am I doing something wrong here?

Thanks,
Peter

Patricia Decker

unread,
Feb 8, 2024, 12:03:46 PMFeb 8
to golang-nuts
I haven't played around with it yet, but have you tried to separately register /something/ ?

mux := http.NewServeMux()
mux.HandleFunc("/something/", func...)
mux.HandleFunc("/something/{id}/{$}", func...)

Jason Phillips

unread,
Feb 8, 2024, 1:30:48 PMFeb 8
to golang-nuts
Can you create a small self-contained program that reproduces the issue? The following program returns 404 locally, as I'd expect, but does get killed in the Go playground: https://go.dev/play/p/FigBLK8KrAK

Perhaps there's an issue with the Playground networking implementation that's incompatible with the 1.22 changes?

Kyle Shannon

unread,
Feb 8, 2024, 1:59:04 PMFeb 8
to Jason Phillips, golang-nuts
On 2/8/24 11:30, Jason Phillips wrote:
Can you create a small self-contained program that reproduces the issue? The following program returns 404 locally, as I'd expect, but does get killed in the Go playground: https://go.dev/play/p/FigBLK8KrAK
Perhaps a simpler reproduction that's runnable on the playground:

https://go.dev/play/p/gmQGJsyNCT6

This returns 301 with a Location of /x/.  Note the trailing slash in the mux pattern, which was missing in your example.

Perhaps there's an issue with the Playground networking implementation that's incompatible with the 1.22 changes?

On Thursday, February 8, 2024 at 12:03:46 PM UTC-5 Patricia Decker wrote:
I haven't played around with it yet, but have you tried to separately register /something/ ?

mux := http.NewServeMux()
mux.HandleFunc("/something/", func...)
mux.HandleFunc("/something/{id}/{$}", func...)

On Wednesday, February 7, 2024 at 1:21:00 PM UTC-8 Péter Szarvas wrote:
Hello,

I noticed if you set up a route like /something/{id}/{$}, it results in an infinite loop if I navigate to /someting/ (with the trailing slash). I got a redirect to Location: /something/, and so on. Finally the page breaks after multiple rounds.

Example:
mux := http.NewServeMux()
mux.HandleFunc("/something/{id}/{$}", func...))

Should I raise and issue or am I doing something wrong here?

Thanks,
Peter
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/445d31e9-e9ce-407a-985c-ad448da9f786n%40googlegroups.com.

-- 
Kyle

Patricia Decker

unread,
Feb 8, 2024, 3:30:15 PMFeb 8
to Kyle Shannon, Jason Phillips, golang-nuts
Thanks for that! Adding the additional HandleFunc for "/x/" does result in a 200: https://go.dev/play/p/5upNoAhAlPs

You received this message because you are subscribed to a topic in the Google Groups "golang-nuts" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/golang-nuts/vbmvPMVhhjk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/85cdc8ae-66cb-45e0-8ba5-b0380cee9df1%40pobox.com.

Sean Liao

unread,
Feb 8, 2024, 5:43:11 PMFeb 8
to golang-nuts

Péter Szarvas

unread,
Feb 12, 2024, 4:08:02 PMFeb 12
to golang-nuts
Wonderful news, thanks for the quick issue opening. I will follow this on github
Reply all
Reply to author
Forward
0 new messages