husobee/vestigo

Hangs at 100% CPU

ernestoalejo opened this issue · 6 comments

When adding the /:lang/foo route any request that should end in a 404 (e.g. /hello/world) hangs instead without returning anything and maxing the CPU for the process.

package main

import (
	"fmt"
	"net/http"

	"github.com/husobee/vestigo"
)

func main() {
	r := vestigo.NewRouter()
	http.Handle("/", r)

	r.Get("/foo", func(w http.ResponseWriter, r *http.Request) { fmt.Fprintln(w, "foo") })
	r.Get("/:lang/foo", func(w http.ResponseWriter, r *http.Request) { fmt.Fprintln(w, "foo") })

	http.ListenAndServe(":8080", nil)
}

Looking into this now. Thanks for the report.

#65 should fix it @ernestoalejo. Sorry about this, when backtracking to sibling nodes you found a case where the same node gets traversed and then backtracked in an infinte loop. That PR corrects this, and I added a test. If you dont mind trying my issue-64 branch I would appreciate a second set of eyes.

Going to merge that fix into master now.

Merged #65 into master.

It seems to fix the issue both in the minimal reproduction example and the original application where I found the problem.

PD: Thank you!

Great to hear, and again, sorry for introducing that one. We should leave this open for a few days incase others find the same issue. I will close this in a few days.