Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The changes in this PR prevent close(2) from being called multiple times against a single file descriptor. On Linux, but not necessarily other posix boxen, calling
close()is considered "wrong" (their words):The PR changes here provide a speculative fix to issues such as this one in osquery. The error from RocksDB in osquery is EISDIR, an unexpected error in this context (see log). This has the distinct smell of an incorrect file descriptor in use. I hypothesize this is down to a call to ::Close(...) returning an IOStatus error and not setting fd to -1 and then subsequently, the destructors for
PosixRandomRWFileand/orPosixDirectory, invoking close() on the now invalid file descriptor. Between the first and second call of close(), the file descriptor id can be recycled and used in a different context. This is described in open(2) which states:The erroneous call to close() in the destructor could therefore impact reused file descriptor ids thus leading to unexpected and difficult to debug error cases.