geektutu/7days-golang · error
HTTPPool serving unexpected path: " + r.URL.Path
Error message
HTTPPool serving unexpected path: " + r.URL.Path
What it means
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.
Source
Thrown at gee-cache/day5-multi-nodes/geecache/http.go:45
}
// NewHTTPPool initializes an HTTP pool of peers.
func NewHTTPPool(self string) *HTTPPool {
return &HTTPPool{
self: self,
basePath: defaultBasePath,
}
}
// Log info with server name
func (p *HTTPPool) Log(format string, v ...interface{}) {
log.Printf("[Server %s] %s", p.self, fmt.Sprintf(format, v...))
}
// ServeHTTP handle all http requests
func (p *HTTPPool) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if !strings.HasPrefix(r.URL.Path, p.basePath) {
panic("HTTPPool serving unexpected path: " + r.URL.Path)
}
p.Log("%s %s", r.Method, r.URL.Path)
// /<basepath>/<groupname>/<key> required
parts := strings.SplitN(r.URL.Path[len(p.basePath):], "/", 2)
if len(parts) != 2 {
http.Error(w, "bad request", http.StatusBadRequest)
return
}
groupName := parts[0]
key := parts[1]
group := GetGroup(groupName)
if group == nil {
http.Error(w, "no such group: "+groupName, http.StatusNotFound)
return
}
View on GitHub (pinned to cf36443821)
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
Example fix
// before
http.HandleFunc("/", pool.ServeHTTP) // panics on non-cache paths
// after
http.Handle("/_geecache/", pool) Defensive patterns
Strategy: validation
Validate before calling
if !strings.HasPrefix(r.URL.Path, "/_geecache/") {
http.NotFound(w, r)
return
}
pool.ServeHTTP(w, r) Try / catch
defer func() {
if rec := recover(); rec != nil {
if s, ok := rec.(string); ok && strings.HasPrefix(s, "HTTPPool serving unexpected path") {
http.NotFound(w, r)
return
}
panic(rec)
}
}() Prevention
- 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
When it happens
Trigger: 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.
Common situations: Multi-node demos where one mux serves both app routes and the cache pool; load balancer probes; proxy prefix stripping between nodes.
Related errors
- HTTPPool serving unexpected path: " + r.URL.Path
- HTTPPool serving unexpected path: " + r.URL.Path
- HTTPPool serving unexpected path: " + r.URL.Path
- HTTPPool serving unexpected path: " + r.URL.Path
- unexpected HTTP response:
AI-assisted analysis of geektutu/7days-golang@cf36443821 (2026-09-03).
Data as JSON: /api/errors/280ea0cdb1a0a946.
Report an issue: GitHub.