Skip to content

Commit ccda4a5

Browse files
fix(loki.source.file): Close file if we cannot find encoding [backport] (#5531)
## Backport of #5528 This PR backports #5528 to release/v1.13. ### Original PR Author @kalleep ### Description ### Pull Request Details Noticed that we do not close file if we cannot get encoding. Review all other paths and we close file properly. I really wish go had something like [errdefer like zig does](https://ziglang.org/documentation/master/#errdefer). ### Issue(s) fixed by this Pull Request <!-- Uncomment the following line and fill in an issue number if you want a GitHub issue to be closed automatically when this PR gets merged. --> <!-- Fixes #issue_id --> ### Notes to the Reviewer <!-- Add any relevant notes for the reviewers and testers of this PR. --> ### PR Checklist <!-- Remove items that do not apply. For completed items, change [ ] to [x]. --> - [ ] Documentation added - [ ] Tests updated - [ ] Config converters updated --- *This backport was created automatically.* Co-authored-by: Karl Persson <23356117+kalleep@users.noreply.github.com>
1 parent 2f43c91 commit ccda4a5

1 file changed

Lines changed: 1 addition & 0 deletions

File tree

  • internal/component/loki/source/file/internal/tail

internal/component/loki/source/file/internal/tail/file.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ func NewFile(logger log.Logger, cfg *Config) (*File, error) {
2828

2929
encoding, err := getEncoding(cfg.Encoding)
3030
if err != nil {
31+
f.Close()
3132
return nil, err
3233
}
3334

0 commit comments

Comments
 (0)