Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Suppress errors on EBADF when unlocking files (open-telemetry#35706)
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description This error is harmless and happens regularly when `delete_after_read` is set. This is because we acquire the lock right at the start of the `ReadToEnd` function and then defer the unlock, but that function also performs the delete. So, by the time it returns and the defer runs the file descriptor is no longer valid. <!--Describe what testing was performed and which tests were added.--> #### Testing Tested manually on a laptop running MacOS. When using `acquire_fs_locks` in conjunction with `delete_after_read` I observe this error in the logs *before applying this change*: ``` 2024-10-08T14:30:23.626-0700 error reader/reader_unix.go:28 Failed to unlock {"kind": "receiver", "name": "filelog", "data_type": "logs", "component": "fileconsumer", "path": "<redacted>", "error": "bad file descriptor"} github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/fileconsumer/internal/reader.(*Reader).unlockFile github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza@v0.111.0/fileconsumer/internal/reader/reader_unix.go:28 github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/fileconsumer/internal/reader.(*Reader).ReadToEnd github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza@v0.111.0/fileconsumer/internal/reader/reader.go:126 github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/fileconsumer.(*Manager).consume.func1 github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza@v0.111.0/fileconsumer/file.go:160 ``` Performing the same test with this changed applied eliminates the error. --------- Co-authored-by: Bogdan Drutu <bogdandrutu@gmail.com>
- Loading branch information