{"record":{"id":"da77369e05d4b32d","repo":"geektutu/7days-golang","slug":"httppool-serving-unexpected-path-r-url-path-da7736","errorCode":null,"errorMessage":"HTTPPool serving unexpected path: \" + r.URL.Path","messagePattern":"HTTPPool serving unexpected path: \" \\+ r\\.URL\\.Path","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"gee-cache/day6-single-flight/geecache/http.go","lineNumber":45,"sourceCode":"}\n\n// NewHTTPPool initializes an HTTP pool of peers.\nfunc NewHTTPPool(self string) *HTTPPool {\n\treturn &HTTPPool{\n\t\tself:     self,\n\t\tbasePath: defaultBasePath,\n\t}\n}\n\n// Log info with server name\nfunc (p *HTTPPool) Log(format string, v ...interface{}) {\n\tlog.Printf(\"[Server %s] %s\", p.self, fmt.Sprintf(format, v...))\n}\n\n// ServeHTTP handle all http requests\nfunc (p *HTTPPool) ServeHTTP(w http.ResponseWriter, r *http.Request) {\n\tif !strings.HasPrefix(r.URL.Path, p.basePath) {\n\t\tpanic(\"HTTPPool serving unexpected path: \" + r.URL.Path)\n\t}\n\tp.Log(\"%s %s\", r.Method, r.URL.Path)\n\t// /<basepath>/<groupname>/<key> required\n\tparts := strings.SplitN(r.URL.Path[len(p.basePath):], \"/\", 2)\n\tif len(parts) != 2 {\n\t\thttp.Error(w, \"bad request\", http.StatusBadRequest)\n\t\treturn\n\t}\n\n\tgroupName := parts[0]\n\tkey := parts[1]\n\n\tgroup := GetGroup(groupName)\n\tif group == nil {\n\t\thttp.Error(w, \"no such group: \"+groupName, http.StatusNotFound)\n\t\treturn\n\t}\n","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/geektutu/7days-golang/blob/cf3644382101dc13e7fd92e8f5c66cabc51bcd3b/gee-cache/day6-single-flight/geecache/http.go#L27-L63","documentation":"Same as errors 91/93/96, in the day6-single-flight version: HTTPPool.ServeHTTP panics when r.URL.Path does not start with p.basePath (\"/_geecache/\"). Only requests matching /<basePath>/<group>/<key> are valid peer-protocol calls; all other paths are treated as routing bugs and panic.","triggerScenarios":"The pool's handler receives \"/\" or app paths — mux registration at root, health probes, reverse proxy stripping the prefix, or clients with a mismatched base path.","commonSituations":"Single binary serving UI + cache API on one mux; Docker/K8s health checks on \"/\"; load balancer rewrites removing /_geecache/.","solutions":["Mount the pool only at its base path: http.Handle(\"/_geecache/\", pool)","Serve health checks from a separate handler","Configure proxies to preserve the /_geecache/ prefix","Ensure all peers use the same base path"],"exampleFix":"// before\nhttp.Handle(\"/\", pool) // any non-cache path panics\n// after\nhttp.Handle(\"/_geecache/\", pool)\nhttp.HandleFunc(\"/healthz\", func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK) })","handlingStrategy":"validation","validationCode":"if !strings.HasPrefix(r.URL.Path, \"/_geecache/\") {\n    http.NotFound(w, r)\n    return\n}\npool.ServeHTTP(w, r)","typeGuard":null,"tryCatchPattern":"defer func() {\n    if rec := recover(); rec != nil {\n        if s, ok := rec.(string); ok && strings.HasPrefix(s, \"HTTPPool serving unexpected path\") {\n            http.NotFound(w, r)\n            return\n        }\n        panic(rec)\n    }\n}()","preventionTips":["Mount HTTPPool only under /_geecache/ in every deployment","Separate handlers for healthz and application routes","Check load balancer/proxy rewrite rules for prefix removal","Standardize the base path across client and server pools"],"tags":["go","http","panic","routing"],"backgroundTag":"unexpected-http-path","analyzedSha":"cf3644382101dc13e7fd92e8f5c66cabc51bcd3b","analyzedAt":"2026-09-03T18:31:24.087Z","contentChangedAt":"2026-09-03T18:31:24.087Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}