Skip to content

Fix close(-1) on failed open in btrfs rename fsync path#14443

Open
omkarhgawde wants to merge 1 commit intofacebook:mainfrom
omkarhgawde:export-D95303407
Open

Fix close(-1) on failed open in btrfs rename fsync path#14443
omkarhgawde wants to merge 1 commit intofacebook:mainfrom
omkarhgawde:export-D95303407

Conversation

@omkarhgawde
Copy link
Contributor

Summary:
In PosixDirectory::FsyncWithDirOptions(), when handling btrfs file rename
syncing, if open() fails and fd is -1, the code unconditionally calls
close(fd). Calling close(-1) is undefined behavior per POSIX (returns
EBADF on Linux), and overwrites the original meaningful open error with a
misleading "While closing file after fsync" error message.

Fix: Guard the close() call with fd >= 0.

Differential Revision: D95303407

@meta-cla meta-cla bot added the CLA Signed label Mar 10, 2026
@meta-codesync
Copy link

meta-codesync bot commented Mar 10, 2026

@omkarhgawde has exported this pull request. If you are a Meta employee, you can view the originating Diff in D95303407.

@github-actions
Copy link

github-actions bot commented Mar 10, 2026

✅ clang-tidy: No findings on changed lines

Completed in 70.6s.

omkarhgawde added a commit to omkarhgawde/rocksdb that referenced this pull request Mar 10, 2026
Summary:

In `PosixDirectory::FsyncWithDirOptions()`, when handling btrfs file rename
syncing, if `open()` fails and `fd` is -1, the code unconditionally calls
`close(fd)`. Calling `close(-1)` is undefined behavior per POSIX (returns
EBADF on Linux), and overwrites the original meaningful open error with a
misleading "While closing file after fsync" error message.

Fix: Guard the `close()` call with `fd >= 0`.

Reviewed By: xingbowang

Differential Revision: D95303407
Summary:
Pull Request resolved: facebook#14443

In `PosixDirectory::FsyncWithDirOptions()`, when handling btrfs file rename
syncing, if `open()` fails and `fd` is -1, the code unconditionally calls
`close(fd)`. Calling `close(-1)` is undefined behavior per POSIX (returns
EBADF on Linux), and overwrites the original meaningful open error with a
misleading "While closing file after fsync" error message.

Fix: Guard the `close()` call with `fd >= 0`.

Reviewed By: xingbowang

Differential Revision: D95303407
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants