{"record":{"id":"d96eae8c5f563ceb","repo":"hashicorp/nomad","slug":"failed-to-write-bytes-to-eventstream-json-bytes-w","errorCode":null,"errorMessage":"failed to write bytes to eventstream.json; bytes written: %d, Err: %w","messagePattern":"failed to write bytes to eventstream\\.json; bytes written: (.+?), Err: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"command/operator_debug.go","lineNumber":992,"sourceCode":"\t\t\tif event.IsHeartbeat() {\n\t\t\t\theartbeatCount++\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tfor _, e := range event.Events {\n\t\t\t\teventCount++\n\t\t\t\tc.verboseOutf(\"Event: %4d, Index: %d, Topic: %-10s, Type: %s, FilterKeys: %s\", eventCount, e.Index, e.Topic, e.Type, e.FilterKeys)\n\n\t\t\t\tbytes, err := json.Marshal(e)\n\t\t\t\tif err != nil {\n\t\t\t\t\terrCount++\n\t\t\t\t\tmErrs = multierror.Append(mErrs, fmt.Errorf(\"failed to marshal json from Topic: %s, Type: %s, Err: %w\", e.Topic, e.Type, err))\n\t\t\t\t}\n\n\t\t\t\tn, err := fh.Write(bytes)\n\t\t\t\tif err != nil {\n\t\t\t\t\terrCount++\n\t\t\t\t\tmErrs = multierror.Append(mErrs, fmt.Errorf(\"failed to write bytes to eventstream.json; bytes written: %d, Err: %w\", n, err))\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tn, err = fh.WriteString(\"\\n\")\n\t\t\t\tif err != nil {\n\t\t\t\t\terrCount++\n\t\t\t\t\tmErrs = multierror.Append(mErrs, fmt.Errorf(\"failed to write string to eventstream.json; chars written: %d, Err: %w\", n, err))\n\t\t\t\t}\n\t\t\t}\n\t\tcase <-c.ctx.Done():\n\t\t\tc.verboseOutf(\"Event stream captured %d events, %d frames, %d heartbeats, %d errors\", eventCount, channelEventCount, heartbeatCount, errCount)\n\t\t\treturn mErrs.ErrorOrNil()\n\t\t}\n\t}\n}\n\n// collectAgentHosts calls collectAgentHost for each selected node\nfunc (c *OperatorDebugCommand) collectAgentHosts(client *api.Client) {\n\tfor _, n := range c.nodeIDs {","sourceCodeStart":974,"sourceCodeEnd":1010,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/command/operator_debug.go#L974-L1010","documentation":"After successfully marshaling an event, captureEventStream writes the JSON bytes to the open eventstream.json file handle. If fh.Write fails (bytes may be partially written, n is reported in the message), the error is appended to the multierror and the event loop breaks out. This indicates the capture destination became unwritable mid-capture.","triggerScenarios":"fh.Write returns an error: disk full, capture directory removed while capturing, file descriptor closed, permission changed, or I/O error on the underlying filesystem.","commonSituations":"/tmp or the -output dir filling up during long captures; someone deleting the capture directory while debug runs; running on a read-only or quota-limited filesystem; container tmpfs size limits.","solutions":["Free disk space or point the capture at a directory with room (df -h; choose a larger -output target)","Check the partial byte count n in the message to assess how much of the event was written","Verify the capture directory still exists and is writable during the run (ls -ld, no concurrent cleanup jobs)","Re-run the capture after fixing storage; the multierror lists how many events were affected via errCount"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// preflight\nif st, err := os.Stat(outputDir); err != nil || !st.IsDir() {\n\treturn fmt.Errorf(\"output dir %s unavailable\", outputDir)\n}\nif du, err := checkFreeSpace(outputDir); err != nil || du < minBytes {\n\treturn fmt.Errorf(\"insufficient space in %s\", outputDir)\n}","typeGuard":null,"tryCatchPattern":"n, err := fh.Write(bytes)\nif err != nil {\n\terrs = multierror.Append(errs, fmt.Errorf(\"failed to write bytes to eventstream.json; bytes written: %d, Err: %w\", n, err))\n\tbreak // stop consuming a broken file handle\n}","preventionTips":["Ensure the output filesystem has ample free space before long captures","Don't delete or rotate the capture directory while the command runs","Avoid quota-limited/tmpfs volumes for capture output"],"tags":["filesystem","io","durability"],"backgroundTag":"file-write-failed","analyzedSha":"482b49bf1aec006f089bcfc7e632d8f6ac303e5e","analyzedAt":"2026-09-04T07:54:14.808Z","contentChangedAt":"2026-09-04T07:54:14.808Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}