{"record":{"id":"5d937011885ddaa0","repo":"vitessio/vitess","slug":"err-error-template-execute-failure","errorCode":null,"errorMessage":"err.Error() (template execute failure)","messagePattern":"err\\.Error\\(\\) \\(template execute failure\\)","errorType":"http","errorClass":null,"httpStatus":500,"severity":"error","filePath":"go/vt/vtgate/executor_scatter_stats.go","lineNumber":133,"sourceCode":"\tlogz.StartHTMLTable(w)\n\tdefer logz.EndHTMLTable(w)\n\n\tresults, err := e.gatherScatterStats()\n\tif err != nil {\n\t\thttp.Error(w, err.Error(), 500)\n\t\treturn\n\t}\n\n\tt := template.New(\"template\")\n\tt, err = t.Parse(statsHTML)\n\tif err != nil {\n\t\thttp.Error(w, err.Error(), 500)\n\t\treturn\n\t}\n\n\terr = t.Execute(w, results)\n\tif err != nil {\n\t\thttp.Error(w, err.Error(), 500)\n\t}\n\n\t_, err = fmt.Fprintf(w, \"Percentage of time spent on scatter queries: %2.2f%%\", results.PercentTimeScatter)\n\tif err != nil {\n\t\thttp.Error(w, err.Error(), 500)\n\t}\n}\n\nconst statsHTML = `\n<thead>\n\t<tr>\n\t\t<th>Query</th>\n\t\t<th># of executions</th>\n\t\t<th>Avg time/query</th>\n\t\t<th>% time of reads</th>\n\t\t<th>% time of scatters</th>\n\t\t<th>% of reads</th>\n\t\t<th>% of scatters</th>","sourceCodeStart":115,"sourceCodeEnd":151,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/vtgate/executor_scatter_stats.go#L115-L151","documentation":"WriteScatterStats renders the scatter-query statistics debug page by executing an HTML template against gathered results. If t.Execute fails while writing to the HTTP response (template data mismatch, or the client connection is broken mid-write), the handler calls http.Error with the raw error text and a 500 status. This surfaces internal template-execution or network-write failures to the operator's browser.","triggerScenarios":"Hitting the /scatterStats debug endpoint on VTGate when the template execution fails: the underlying writer errors out (client disconnects mid-response), or the template cannot render the gathered ScatterStats results. Note the handler does not return after this http.Error, so a second write may also be attempted.","commonSituations":"Monitoring or a browser tab polling /scatterStats closes the connection while the page is still streaming; the response body has already been partially written so the 500 status line cannot actually be delivered.","solutions":["Check vtgate logs for the underlying template/write error to confirm whether it was a client disconnect (benign) or a template bug","Retry the request with the connection held open; verify the full page renders","If it reproduces with a live connection, file/inspect a vitess issue — the template and results types are internal and should always match","Verify no proxy/load-balancer between client and vtgate is cutting long responses early"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"// before calling the endpoint, verify it is reachable\nresp, err := http.Get(\"http://vtgate:15001/scatterStats\")\nif err != nil || resp.StatusCode != 200 {\n\t// fall back to vtgate /debug/vars scatter counters\n}","typeGuard":null,"tryCatchPattern":"// client-side\nresp, err := http.Get(url)\nif err != nil {\n\tlog.Warn(\"scatterStats fetch failed\", slog.Any(\"error\", err))\n\treturn fallbackStats()\n}\ndefer resp.Body.Close()","preventionTips":["Keep scraping clients connected with generous read timeouts","Avoid scraping /scatterStats through proxies that cut long responses","Prefer programmatic stats from /debug/vars for automation","Check vtgate logs to distinguish client disconnects from real template bugs"],"tags":["http","vtgate","template","debug-endpoint"],"backgroundTag":"http-response-write-failed","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}