Skip to content

Conversation

@rrbutani
Copy link
Contributor

@rrbutani rrbutani commented Dec 5, 2023

Note

Follow-up to #20373 (see here)


Currently if the --install_base path passed is not writable by the user invoking Bazel, the Bazel client crashes:

bazel --install_base=/some/read/only/path version
FATAL: failed to set timestamp on '/some/read/only/path': (error: 30): Read-only file system

This happens because the Bazel client (unconditionally) attempts to update the mtime of this path:

bazel/src/main/cpp/blaze.cc

Lines 1010 to 1021 in a3c677d

// Update the mtime of the install base so that cleanup tools can
// find install bases that haven't been used for a long time
std::unique_ptr<blaze_util::IFileMtime> mtime(
blaze_util::CreateFileMtime());
if (!mtime->SetToNow(blaze_util::Path(startup_options.install_base))) {
string err = GetLastErrorString();
BAZEL_DIE(blaze_exit_code::LOCAL_ENVIRONMENTAL_ERROR)
<< "failed to set timestamp on '" << startup_options.install_base
<< "': " << err;
}
}
}

This commit updates the client to ignore such errors. See #20373 for context.


cc: @tjgq

if (errno == EROFS || errno == EPERM) { raise_error = false; }
#elif defined(_WIN32)
// On Windows, `SetToNow` is backed by `CreateFileW` + `SetFileTime`:
if (::GetLastError() == ERROR_ACCESS_DENIED) { raise_error = false; }
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 am not sure whether this is correct; unfortunately I don't have access to a Windows machine at the moment.

Copy link
Contributor Author

@rrbutani rrbutani Dec 5, 2023

Choose a reason for hiding this comment

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

CI seems to confirm that this does at least build on Windows.

@rrbutani rrbutani marked this pull request as ready for review December 5, 2023 21:05
@github-actions github-actions bot added team-Rules-CPP Issues for C++ rules awaiting-review PR is awaiting review from an assigned reviewer labels Dec 5, 2023
Copy link
Contributor

@tjgq tjgq left a comment

Choose a reason for hiding this comment

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

We try to keep the platform-dependent filesystem code in file_platform.h and its two implementations, file_posix.cc and file_windows.cc.

How about adding a new SetToNowIfPossible method there with the desired "permissions error counts as success" semantics?

Currently if the `--install_base` path passed is not writable by the
user invoking Bazel, the Bazel client crashes[^1]:
```console
❯ bazel --install_base=/some/read/only/path version
FATAL: failed to set timestamp on '/some/read/only/path': (error: 30): Read-only file system
```

This happens because the Bazel client (unconditionally) attempts to
update the `mtime` of this path:
https://github.com/bazelbuild/bazel/blob/a3c677dfea2de636a719d50345a5a97af96fae60/src/main/cpp/blaze.cc#L1010-L1021

[^1]: Note that if you invoke Bazel again after this happens, it will successfully start up because the `install` symlink in the output base [that inhibits the `mtime` update/install base check] has already been [created].

[that inhibits the `mtime` update/install base check]: https://github.com/bazelbuild/bazel/blob/a3c677dfea2de636a719d50345a5a97af96fae60/src/main/cpp/blaze.cc#L983-L993
[created]: https://github.com/bazelbuild/bazel/blob/a3c677dfea2de636a719d50345a5a97af96fae60/src/main/cpp/blaze.cc#L1003

This commit updates the client to ignore such errors. See bazelbuild#20373 for
context.
@rrbutani rrbutani force-pushed the fix/install-base-mtime-update-ignore-readonly-error branch from ed3d573 to da0afbb Compare December 12, 2023 19:14
@rrbutani rrbutani marked this pull request as draft December 12, 2023 19:15
@rrbutani rrbutani marked this pull request as ready for review December 12, 2023 20:17
@rrbutani
Copy link
Contributor Author

How about adding a new SetToNowIfPossible method there with the desired "permissions error counts as success" semantics?

@tjgq done; PTAL.

@rrbutani rrbutani requested a review from tjgq December 12, 2023 22:57
@tjgq tjgq added awaiting-PR-merge PR has been approved by a reviewer and is ready to be merge internally and removed awaiting-review PR is awaiting review from an assigned reviewer labels Dec 14, 2023
@github-actions github-actions bot removed the awaiting-PR-merge PR has been approved by a reviewer and is ready to be merge internally label Dec 15, 2023
@brentleyjones
Copy link
Contributor

@bazel-io flag

@bazel-io bazel-io added the potential release blocker Flagged by community members using "@bazel-io flag". Should be added to a release blocker milestone label Dec 15, 2023
@iancha1992
Copy link
Member

@bazel-io fork 7.1.0

@bazel-io bazel-io removed the potential release blocker Flagged by community members using "@bazel-io flag". Should be added to a release blocker milestone label Dec 15, 2023
@iancha1992
Copy link
Member

@brentleyjones please let me know if you want this included with 6.5.0 as well.

@brentleyjones
Copy link
Contributor

@iancha1992 If it applies nicely, it would be good to get in, yes.

@iancha1992
Copy link
Member

@bazel-io fork 6.5.0

bazel-io pushed a commit to bazel-io/bazel that referenced this pull request Dec 15, 2023
Currently if the `--install_base` path passed is not writable by the user invoking Bazel, the Bazel client crashes:
```console
❯ bazel --install_base=/some/read/only/path version
FATAL: failed to set timestamp on '/some/read/only/path': (error: 30): Read-only file system
```

This happens because the Bazel client (unconditionally) attempts to update the `mtime` of this path:
https://github.com/bazelbuild/bazel/blob/a3c677dfea2de636a719d50345a5a97af96fae60/src/main/cpp/blaze.cc#L1010-L1021

This commit updates the client to ignore such errors. See bazelbuild#20373 for context.

Closes bazelbuild#20442.

PiperOrigin-RevId: 591266054
Change-Id: If53e7cad48cb62406f7883f72b413e4b5a0bb8e2
@rrbutani rrbutani deleted the fix/install-base-mtime-update-ignore-readonly-error branch December 15, 2023 20:53
bazel-io pushed a commit to bazel-io/bazel that referenced this pull request Dec 21, 2023
Currently if the `--install_base` path passed is not writable by the user invoking Bazel, the Bazel client crashes:
```console
❯ bazel --install_base=/some/read/only/path version
FATAL: failed to set timestamp on '/some/read/only/path': (error: 30): Read-only file system
```

This happens because the Bazel client (unconditionally) attempts to update the `mtime` of this path:
https://github.com/bazelbuild/bazel/blob/a3c677dfea2de636a719d50345a5a97af96fae60/src/main/cpp/blaze.cc#L1010-L1021

This commit updates the client to ignore such errors. See bazelbuild#20373 for context.

Closes bazelbuild#20442.

PiperOrigin-RevId: 591266054
Change-Id: If53e7cad48cb62406f7883f72b413e4b5a0bb8e2
github-merge-queue bot pushed a commit that referenced this pull request Jan 9, 2024
…tall_base` (#20568)

Currently if the `--install_base` path passed is not writable by the
user invoking Bazel, the Bazel client crashes:
```console
❯ bazel --install_base=/some/read/only/path version
FATAL: failed to set timestamp on '/some/read/only/path': (error: 30): Read-only file system
```

This happens because the Bazel client (unconditionally) attempts to
update the `mtime` of this path:

https://github.com/bazelbuild/bazel/blob/a3c677dfea2de636a719d50345a5a97af96fae60/src/main/cpp/blaze.cc#L1010-L1021

This commit updates the client to ignore such errors. See #20373 for
context.

Closes #20442.

Commit
7f782e3

PiperOrigin-RevId: 591266054
Change-Id: If53e7cad48cb62406f7883f72b413e4b5a0bb8e2

Co-authored-by: Rahul Butani <[email protected]>
Co-authored-by: Ian (Hee) Cha <[email protected]>
github-merge-queue bot pushed a commit that referenced this pull request Jan 11, 2024
…tall_base` (#20648)

Currently if the `--install_base` path passed is not writable by the
user invoking Bazel, the Bazel client crashes:
```console
❯ bazel --install_base=/some/read/only/path version
FATAL: failed to set timestamp on '/some/read/only/path': (error: 30): Read-only file system
```

This happens because the Bazel client (unconditionally) attempts to
update the `mtime` of this path:

https://github.com/bazelbuild/bazel/blob/a3c677dfea2de636a719d50345a5a97af96fae60/src/main/cpp/blaze.cc#L1010-L1021

This commit updates the client to ignore such errors. See #20373 for
context.

Closes #20442.

Commit
7f782e3

PiperOrigin-RevId: 591266054
Change-Id: If53e7cad48cb62406f7883f72b413e4b5a0bb8e2

Co-authored-by: Rahul Butani <[email protected]>
Co-authored-by: Ian (Hee) Cha <[email protected]>
@iancha1992
Copy link
Member

The changes in this PR have been included in Bazel 6.5.0 RC1. Please test out the release candidate and report any issues as soon as possible. If you're using Bazelisk, you can point to the latest RC by setting USE_BAZEL_VERSION=last_rc.
Thanks!

@iancha1992
Copy link
Member

The changes in this PR have been included in Bazel 7.1.0 RC1. Please test out the release candidate and report any issues as soon as possible. If you're using Bazelisk, you can point to the latest RC by setting USE_BAZEL_VERSION=last_rc.
Thanks!

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

Labels

team-Rules-CPP Issues for C++ rules

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants