geektutu/7days-golang · error
HTTPPool serving unexpected path: " + r.URL.Path
Error message
HTTPPool serving unexpected path: " + r.URL.Path
What it means
Same failure as error 91 in the day4-consistent-hash version: ServeHTTP panics when r.URL.Path lacks the p.basePath prefix ("/_geecache/"). Only peer-protocol requests under the base path are valid; anything else is a routing misconfiguration and panics by design.
Source
Thrown at gee-cache/day4-consistent-hash/geecache/http.go:35
}
// 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 only under its base path: http.Handle("/_geecache/", pool)
- Move health checks to a dedicated handler
- Preserve the /_geecache/ prefix through proxies
- Align client and server base paths
Example fix
// before
mux.Handle("/", pool) // panics on /anything
// after
mux.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
- Mount the pool only under /_geecache/
- Dedicated handlers for health checks and app routes
- Audit proxy rewrite rules for prefix stripping
- Keep base paths consistent across all nodes
When it happens
Trigger: Requests to any path outside /_geecache/ reach the HTTPPool handler — mux registration at "/", health probes on "/", reverse proxy stripping the prefix, or a client using the wrong base path.
Common situations: Kubernetes liveness probes on "/"; nginx/location rewrites; team member exposing the pool on the root route for convenience; client/server base-path mismatch.
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/761efd75d35d73b2.
Report an issue: GitHub.