vitessio/vitess · error
failed to render config to tempfile: %v
Error message
failed to render config to tempfile: %v
What it means
The viperutil debug HTTP handler renders the current config to a temp file because viper lacks WriteConfigTo(w io.Writer). If os.CreateTemp fails, it returns 500 with 'failed to render config to tempfile'. This means the environment cannot supply a temp file at all.
Source
Thrown at go/viperutil/debug/handler.go:65
acl.SendError(w, err)
return
}
v := registry.Combined()
format := strings.ToLower(r.URL.Query().Get("format"))
switch {
case format == "":
v.DebugTo(w)
case slice.Any(viper.SupportedExts, func(ext string) bool { return ext == format }):
// Got a supported format; write the config to a tempfile in that format,
// then copy it to the response.
//
// (Sadly, viper does not yet have a WriteConfigTo(w io.Writer), so we have
// to do this little hacky workaround).
v.SetConfigType(format)
tmp, err := os.CreateTemp("", "viper_debug")
if err != nil {
http.Error(w, fmt.Sprintf("failed to render config to tempfile: %v", err), http.StatusInternalServerError)
return
}
defer os.Remove(tmp.Name())
if err := v.WriteConfigAs(tmp.Name()); err != nil {
http.Error(w, fmt.Sprintf("failed to render config to tempfile: %v", err), http.StatusInternalServerError)
return
}
if _, err := io.Copy(w, tmp); err != nil {
http.Error(w, fmt.Sprintf("failed to write rendered config: %v", err), http.StatusInternalServerError)
return
}
default:
http.Error(w, "unsupported config format", http.StatusBadRequest)
}
}
View on GitHub (pinned to 01a25a7d17)
Solutions
- Ensure TMPDIR points to a writable directory (or mount a writable tmpfs at /tmp) and restart the process.
- Free disk space on the partition backing the temp directory.
- Check permissions on the temp directory for the process user.
- As a workaround, view the config via other debug endpoints or logs if temp files cannot be enabled.
Example fix
// before (docker run) docker run --read-only vitess/lite ... // after docker run --read-only --tmpfs /tmp:rw,size=64m vitess/lite ...
Defensive patterns
Strategy: validation
Validate before calling
tmp := os.TempDir()
if fi, err := os.Stat(tmp); err != nil || !fi.IsDir() {
return fmt.Errorf("temp dir %s unusable: %v", tmp, err)
}
test, err := os.CreateTemp(tmp, "probe")
if err != nil {
return err
}
test.Close()
os.Remove(test.Name()) Prevention
- Set TMPDIR to a writable volume in containers, especially with read-only root filesystems.
- Monitor disk space on the temp partition.
- Add a startup health check that creates and removes a temp file.
When it happens
Trigger: Hitting the debug config endpoint (HandlerFunc) when os.CreateTemp("", "viper_debug") fails — typically /tmp not existing, being full, or permission denied for the process.
Common situations: Containers with read-only root filesystem and no writable TMPDIR; disk-full on /tmp; TMPDIR pointing to a nonexistent directory; hardened sandboxes blocking temp file creation.
Related errors
- could not create temp file: %v
- could not read existing file %v: %v
- unsupported config format
- cell mode should be handled by the gateway, not the balancer
- failed to create file-based writer for --opentsdb-uri %s: %v
AI-assisted analysis of vitessio/vitess@01a25a7d17 (2026-09-01).
Data as JSON: /api/errors/8d9c46c6b0db7925.
Report an issue: GitHub.