grpc/grpc-go · error
failed to create temp file
Error message
failed to create temp file: %v
What it means
NewTempFileSink creates an OS temp file under /tmp to buffer binary log entries (sink.go:59-66). If os.CreateTemp fails, the error is wrapped and returned to the caller. The sink is typically wired in during program initialization via binarylog.SetSink.
Solutions
- Ensure /tmp exists and is writable by the process, or run in an environment with a writable temp directory.
- Free disk space if /tmp is full.
- If /tmp is not usable, implement your own binarylog.Sink (e.g., writing to a path you control) and pass it to binarylog.SetSink instead of using NewTempFileSink.
Example fix
// before
sink, err := binarylog.NewTempFileSink() // requires writable /tmp
// after: write to your own file
f, err := os.OpenFile("/var/log/grpc.binlog", os.O_CREATE|os.O_WRONLY, 0644)
if err != nil { log.Fatal(err) }
binarylog.SetSink(iblog.NewBufferedSink(f)) Defensive patterns
Strategy: try-catch
Try / catch
sink, err := binarylog.NewTempFileSink()
if err != nil {
// fall back to your own sink or disable binary logging
log.Printf("binary log temp file unavailable: %v", err)
} else {
binarylog.SetSink(sink)
} Prevention
- Ensure /tmp is present and writable, or provide a custom Sink writing to a path you control.
- Call NewTempFileSink during init() so a failure surfaces at startup, not mid-RPC.
- In read-only containers, disable binary logging or ship a custom sink.
When it happens
Trigger: Calling binarylog.NewTempFileSink() when /tmp is not writable, does not exist, is full, or the process lacks permission. os.CreateTemp("/tmp", "grpcgo_binarylog_*.txt") returns a non-nil error.
Common situations: Running in a container/sandbox without /tmp or with a read-only filesystem; exhausted disk space; restrictive SELinux/AppArmor policy; a custom OS where TMPDIR is honored but /tmp is hardcoded here.
Related errors
- could not get resolver for default scheme
- empty string is not a valid method binary logging config
- failed to create JWT call credentials
- policyFile( ) read failed
- token file access error
AI-assisted analysis of grpc/grpc-go@0c51461d27 (2026-08-11).
Data as JSON: /api/errors/a3d7c3cd0896979e.
Report an issue: GitHub.
Appendix: source
Thrown at binarylog/sink.go:65
// is not specified, but should have sufficient information to rebuild the
// entry. Some options are: proto bytes, or proto json.
//
// Note this function needs to be thread-safe.
Write(*binlogpb.GrpcLogEntry) error
// Close closes this sink and cleans up resources (e.g. the flushing
// goroutine).
Close() error
}
// NewTempFileSink creates a temp file and returns a Sink that writes to this
// file.
func NewTempFileSink() (Sink, error) {
// Two other options to replace this function:
// 1. take filename as input.
// 2. export NewBufferedSink().
tempFile, err := os.CreateTemp("/tmp", "grpcgo_binarylog_*.txt")
if err != nil {
return nil, fmt.Errorf("failed to create temp file: %v", err)
}
return iblog.NewBufferedSink(tempFile), nil
}
View on GitHub (pinned to 0c51461d27)