{"record":{"id":"280ea0cdb1a0a946","repo":"geektutu/7days-golang","slug":"httppool-serving-unexpected-path-r-url-path-280ea0","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/day5-multi-nodes/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/day5-multi-nodes/geecache/http.go#L27-L63","documentation":"Same as errors 91/93, in the day5-multi-nodes version: HTTPPool.ServeHTTP panics when the incoming request path does not begin with p.basePath (\"/_geecache/\"). The pool only serves the internal peer protocol; foreign paths indicate a routing misconfiguration and panic by design.","triggerScenarios":"http.Handle(\"/\", pool) or proxy/health-check traffic reaching the pool on paths like \"/\" or \"/api/...\"; client peers configured with a different base path than the server.","commonSituations":"Multi-node demos where one mux serves both app routes and the cache pool; load balancer probes; proxy prefix stripping between nodes.","solutions":["Register the pool under /_geecache/ only: http.Handle(\"/_geecache/\", pool)","Give health probes their own handler","Keep the /_geecache/ prefix intact through any proxy","Use identical base paths on all nodes"],"exampleFix":"// before\nhttp.HandleFunc(\"/\", pool.ServeHTTP) // panics on non-cache paths\n// after\nhttp.Handle(\"/_geecache/\", pool)","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":["Register the pool only at /_geecache/ on every node","Route probes and app traffic to their own handlers","Preserve prefixes in proxy configurations","Verify all peers share the same base path in tests"],"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"}