Skip to content

Do not crash if filesystem can't fsync #1262

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions util/env_posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ class PosixWritableFile final : public WritableFile {
return status;
}

return SyncFd(fd_, filename_);
return SyncFd(fd_, filename_, false);
}

private:
Expand Down Expand Up @@ -382,7 +382,7 @@ class PosixWritableFile final : public WritableFile {
if (fd < 0) {
status = PosixError(dirname_, errno);
} else {
status = SyncFd(fd, dirname_);
status = SyncFd(fd, dirname_, true);
::close(fd);
}
return status;
Expand All @@ -394,7 +394,7 @@ class PosixWritableFile final : public WritableFile {
//
// The path argument is only used to populate the description string in the
// returned Status if an error occurs.
static Status SyncFd(int fd, const std::string& fd_path) {
static Status SyncFd(int fd, const std::string& fd_path, bool syncing_dir) {
#if HAVE_FULLFSYNC
// On macOS and iOS, fsync() doesn't guarantee durability past power
// failures. fcntl(F_FULLFSYNC) is required for that purpose. Some
Expand All @@ -414,6 +414,11 @@ class PosixWritableFile final : public WritableFile {
if (sync_success) {
return Status::OK();
}
// Do not crash if filesystem can't fsync directories
// (see https://github.com/bitcoin/bitcoin/pull/10000)
if (syncing_dir && errno == EINVAL) {
return Status::OK();
}
return PosixError(fd_path, errno);
}

Expand Down