Skip to content

Commit 8655171

Browse files
kalleepgrafana-alloybot[bot]
authored andcommitted
fix(loki.source.file): Close file if we cannot find encoding (#5528)
### 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 (cherry picked from commit 56bcb26)
1 parent 2f43c91 commit 8655171

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)