{"record":{"id":"9fa6c62ac50ece3b","repo":"crowdsecurity/crowdsec","slug":"failed-to-read-gz-s-w","errorCode":null,"errorMessage":"failed to read gz %s: %w","messagePattern":"failed to read gz (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/acquisition/modules/file/run.go","lineNumber":385,"sourceCode":"}\n\nfunc (s *Source) readFile(ctx context.Context, filename string, out chan pipeline.Event) error {\n\tvar scanner *bufio.Scanner\n\n\tlogger := s.logger.WithField(\"oneshot\", filename)\n\n\tfd, err := os.Open(filename)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed opening %s: %w\", filename, err)\n\t}\n\n\tdefer fd.Close()\n\n\tif strings.HasSuffix(filename, \".gz\") {\n\t\tgz, err := gzip.NewReader(fd)\n\t\tif err != nil {\n\t\t\tlogger.Errorf(\"Failed to read gz file: %s\", err)\n\t\t\treturn fmt.Errorf(\"failed to read gz %s: %w\", filename, err)\n\t\t}\n\n\t\tdefer gz.Close()\n\n\t\tscanner = bufio.NewScanner(gz)\n\t} else {\n\t\tscanner = bufio.NewScanner(fd)\n\t}\n\n\tscanner.Split(bufio.ScanLines)\n\n\tif s.config.MaxBufferSize > 0 {\n\t\tbuf := make([]byte, 0, 64*1024)\n\t\tscanner.Buffer(buf, s.config.MaxBufferSize)\n\t}\n\n\tfor scanner.Scan() {\n\t\tselect {","sourceCodeStart":367,"sourceCodeEnd":403,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/acquisition/modules/file/run.go#L367-L403","documentation":"When the one-shot filename ends in .gz, readFile wraps it in gzip.NewReader before scanning. If the gzip stream is corrupt or the file isn't valid gzip data, it logs 'Failed to read gz file' and returns \"failed to read gz %s: %w\".","triggerScenarios":"gzip.NewReader(fd) errors in readFile when filename has a .gz suffix during OneShot replay.","commonSituations":"File named .gz but not actually gzip-compressed (renamed plain text); partially written/truncated rotation (rotation compressed mid-write); corrupted download.","solutions":["Verify the file integrity: `gzip -t /path/to/file.gz`.","Confirm the file is real gzip: `file /path/to/file.gz` — if not gzip, rename to drop .gz and replay as plain text.","If truncated by a bad rotation job, obtain the complete log from backup.","Re-decompress and replay the uncompressed file if gzip repair fails."],"exampleFix":"// before\nmv app.log app.log.gz  # renamed plain text\n// after\ngzip app.log  # actually compress it, or keep .log and replay uncompressed","handlingStrategy":"validation","validationCode":"// validate gzip integrity before replay\ngzip -t /path/to/file.gz && crowdsec -file /path/to/file.gz -type syslog","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never rename plain-text logs to .gz; compress them properly.","Ensure log rotation finishes compressing before replaying archives.","Run `file` on the archive to confirm it is gzip data."],"tags":["file-io","gzip","oneshot","go"],"backgroundTag":"invalid-gzip-file","analyzedSha":"909b5157986a2b2c2163300fdaef5ed01289f7d2","analyzedAt":"2026-09-06T12:27:26.012Z","contentChangedAt":"2026-09-06T12:27:26.012Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}