{"record":{"id":"a3d7c3cd0896979e","repo":"grpc/grpc-go","slug":"failed-to-create-temp-file-v","errorCode":null,"errorMessage":"failed to create temp file: %v","messagePattern":"failed to create temp file: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"binarylog/sink.go","lineNumber":65,"sourceCode":"\t// is not specified, but should have sufficient information to rebuild the\n\t// entry. Some options are: proto bytes, or proto json.\n\t//\n\t// Note this function needs to be thread-safe.\n\tWrite(*binlogpb.GrpcLogEntry) error\n\t// Close closes this sink and cleans up resources (e.g. the flushing\n\t// goroutine).\n\tClose() error\n}\n\n// NewTempFileSink creates a temp file and returns a Sink that writes to this\n// file.\nfunc NewTempFileSink() (Sink, error) {\n\t// Two other options to replace this function:\n\t// 1. take filename as input.\n\t// 2. export NewBufferedSink().\n\ttempFile, err := os.CreateTemp(\"/tmp\", \"grpcgo_binarylog_*.txt\")\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to create temp file: %v\", err)\n\t}\n\treturn iblog.NewBufferedSink(tempFile), nil\n}\n","sourceCodeStart":47,"sourceCodeEnd":69,"githubUrl":"https://github.com/grpc/grpc-go/blob/0c51461d27177d997e14c642fe18c11668fc09a3/binarylog/sink.go#L47-L69","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nsink, err := binarylog.NewTempFileSink() // requires writable /tmp\n// after: write to your own file\nf, err := os.OpenFile(\"/var/log/grpc.binlog\", os.O_CREATE|os.O_WRONLY, 0644)\nif err != nil { log.Fatal(err) }\nbinarylog.SetSink(iblog.NewBufferedSink(f))","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"sink, err := binarylog.NewTempFileSink()\nif err != nil {\n    // fall back to your own sink or disable binary logging\n    log.Printf(\"binary log temp file unavailable: %v\", err)\n} else {\n    binarylog.SetSink(sink)\n}","preventionTips":["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."],"tags":["go","grpc","binarylog","filesystem","init"],"backgroundTag":null,"analyzedSha":"0c51461d27177d997e14c642fe18c11668fc09a3","analyzedAt":"2026-08-11T14:49:15.055Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}