Skip to content
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

RCORE-2242: Include pathname in exception thrown in File::rw_lock #8000

Merged
merged 3 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@

### Fixed
* <How do the end-user experience this issue? what was the impact?> ([#????](https://github.com/realm/realm-core/issues/????), since v?.?.?)
* Using an empty KeyPath in C API would result in no filtering being done ([#7805](https://github.com/realm/realm-core/issues/7805), since 13.24.0)
* Filtering notifications with backlink columns as last element could sometimes give wrong results ([#7530](https://github.com/realm/realm-core/issues/7530), since 11.1.0)
* Using an empty KeyPath in C API would result in no filtering being done ([#7805](https://github.com/realm/realm-core/issues/7805), since v13.24.0)
* Filtering notifications with backlink columns as last element could sometimes give wrong results ([#7530](https://github.com/realm/realm-core/issues/7530), since v11.1.0)
* Fix crash during client app shutdown when Logger log level is set higher than Info. ([#7969](https://github.com/realm/realm-core/issues/7969), since v13.23.3)
* If File::rw_lock() fails to open a file the exception message does not contain the filename ([#7999](https://github.com/realm/realm-core/issues/7999), since v6.0.21)

### Breaking changes
* None.
Expand Down
11 changes: 8 additions & 3 deletions src/realm/util/file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1152,6 +1152,11 @@ bool File::rw_lock(bool exclusive, bool non_blocking)
// or the OS will deadlock when un-suspending the app.
int mode = exclusive ? O_WRONLY | O_NONBLOCK : O_RDWR | O_NONBLOCK;

auto report_err = [path = m_fifo_path](int err, const char* msg) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we worry about the cost of copying this string here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any reason for this to not just capture [this].

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

auto message = util::format("%1: %2, path = '%3'", msg, std::system_category().message(err), path);
throw RuntimeError(ErrorCodes::FileOperationFailed, message); // LCOV_EXCL_LINE
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think we probably shouldn't worry about the cost of copying the string here, but should message be moved?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think not. RuntimeError takes a std::string_view as parameter.

};

// Optimistically try to open the fifo. This may fail due to the fifo not
// existing, but since it usually exists this is faster than trying to create
// it first.
Expand All @@ -1168,7 +1173,7 @@ bool File::rw_lock(bool exclusive, bool non_blocking)
}

// Otherwise we got an unexpected error
throw std::system_error(err, std::system_category(), "opening lock fifo for writing failed");
report_err(err, "opening lock fifo for writing failed");
}

if (err == ENOENT) {
Expand All @@ -1178,15 +1183,15 @@ bool File::rw_lock(bool exclusive, bool non_blocking)
try_make_dir(m_fifo_dir_path);
status = mkfifo(m_fifo_path.c_str(), 0666);
if (status != 0)
throw std::system_error(errno, std::system_category(), "creating lock fifo for reading failed");
report_err(errno, "creating lock fifo for reading failed");

// Try again to open the fifo now that it exists
fd = ::open(m_fifo_path.c_str(), mode);
err = errno;
}

if (fd == -1)
throw std::system_error(err, std::system_category(), "opening lock fifo for reading failed");
report_err(err, "opening lock fifo for reading failed");
}

// We successfully opened the pipe. If we're trying to acquire an exclusive
Expand Down
Loading