{"record":{"id":"c4e1f6c672c3fcf7","repo":"golang/go","slug":"failed-to-stat-trace-file-v","errorCode":null,"errorMessage":"failed to stat trace file: %v","messagePattern":"failed to stat trace file: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/trace/main.go","lineNumber":105,"sourceCode":"\tcase 1:\n\t\ttraceFile = flag.Arg(0)\n\tcase 2:\n\t\tprogramBinary = flag.Arg(0)\n\t\ttraceFile = flag.Arg(1)\n\tdefault:\n\t\tflag.Usage()\n\t}\n\n\ttracef, err := os.Open(traceFile)\n\tif err != nil {\n\t\tlogAndDie(fmt.Errorf(\"failed to read trace file: %w\", err))\n\t}\n\tdefer tracef.Close()\n\n\t// Get the size of the trace file.\n\tfi, err := tracef.Stat()\n\tif err != nil {\n\t\tlogAndDie(fmt.Errorf(\"failed to stat trace file: %v\", err))\n\t}\n\ttraceSize := fi.Size()\n\n\t// Handle requests for profiles.\n\tif *pprofFlag != \"\" {\n\t\tparsed, err := parseTrace(tracef, traceSize)\n\t\tif err != nil {\n\t\t\tlogAndDie(err)\n\t\t}\n\t\tvar f traceviewer.ProfileFunc\n\t\tswitch *pprofFlag {\n\t\tcase \"net\":\n\t\t\tf = pprofByGoroutine(computePprofIO(), parsed)\n\t\tcase \"sync\":\n\t\t\tf = pprofByGoroutine(computePprofBlock(), parsed)\n\t\tcase \"syscall\":\n\t\t\tf = pprofByGoroutine(computePprofSyscall(), parsed)\n\t\tcase \"sched\":","sourceCodeStart":87,"sourceCodeEnd":123,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/trace/main.go#L87-L123","documentation":"The `go tool trace` command successfully opened the trace file but `os.File.Stat()` failed on the open file handle. The stat result is used to determine the file size (`traceSize`) which is needed for subsequent trace parsing. A stat failure on an already-open file is unusual and typically indicates a filesystem-level problem.","triggerScenarios":"Fires at trace/main.go:103-105 when `tracef.Stat()` returns an error after the file was successfully opened. The file handle is already open (open succeeded at line 96). `traceSize` from the stat is passed to `parseTrace` later for size-bounded processing.","commonSituations":"The file was deleted between the open and stat calls (race condition). The file is on a network filesystem (NFS, CIFS) that became unreachable. A FUSE filesystem that doesn't support stat on open files. The file descriptor was closed by another goroutine (concurrency issue). OS-level file handle corruption.","solutions":["Copy the trace file to local storage (e.g., /tmp) and retry: `cp trace.out /tmp/ && go tool trace /tmp/trace.out`.","If on a network filesystem, ensure the connection is stable and remount if necessary.","Verify the file still exists and is accessible: `ls -la <trace_file> && stat <trace_file>`.","Regenerate the trace file if it may have been corrupted or partially deleted.","Check system logs (`dmesg`, `/var/log/syslog`) for filesystem errors."],"exampleFix":"# Before: trace file on unstable network filesystem\ngo tool trace /nfs/share/trace.out\n\n# After: copy to local storage first\ncp /nfs/share/trace.out /tmp/trace.out\ngo tool trace /tmp/trace.out","handlingStrategy":"validation","validationCode":"// Validate trace file stability before analysis (avoid network FS issues)\ninfo, err := os.Stat(traceFile)\nif err != nil {\n    log.Fatalf(\"Cannot stat trace file: %v\", err)\n}\n// If on network filesystem, copy to local first\nif isNetworkMount(traceFile) {\n    localCopy := filepath.Join(os.TempDir(), filepath.Base(traceFile))\n    if err := copyFile(traceFile, localCopy); err != nil {\n        log.Fatalf(\"Cannot copy trace to local storage: %v\", err)\n    }\n    traceFile = localCopy\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Copy trace files from network filesystems to local storage before analysis.","Ensure stable network connections when reading from remote mounts.","Regenerate trace files if they may have been corrupted.","Check system logs for filesystem errors if stat fails on an open file."],"tags":["trace","file-io","stat","runtime-trace","filesystem"],"backgroundTag":null,"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}