-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
default java.io.tmp location is too long #3215
Comments
Stack Overflow question got answered, closing the issue. I'd say asking only on Stack Overflow would be enough in this case. Glad you found the workaround :) |
@mhlopko what about the workaround hurting the hermetically of the test? |
Sorry was too fast scanning the issue, I assumed it's just a dup of the SO. |
@mhlopko Has there been any progress on this front? This is also affecting Debian based distros, which has a much larger install base than just macOS. Running this test rule results in a file path that is 224-character long, and causes gpg-agent to fail due to "filename too long". gpg-agent is known to have the same 108-character restriction. Note that it does not affect Ubuntu based distros, just plain debian based ones. |
Pinging @philwo as the assigned owner :) |
@laszlocsomor is our designated expert on all things related to temporary directories. Reassigning. |
Starting from Bazel 0.8.0, every action has:
They point to safe temp dirs that the action can use. Ironically, the reason I implemented that feature was exactly |
@laszlocsomor Can you elaborate a bit on how to actually solve the issue? EDITED: Sorry I misread a previous release doc. (Just did ctrl+F on the doc :-P) |
@jianglai , I'm sorry, I made the same mistake as @mhlopko earlier, thinking the issue was about something else... Anyway, are you also trying to create a short temp dir? The shortest I can get on Linux with Bazel 0.8.0 is:
|
@laszlocsomor yes we need the temp dir to be with in 108 chars. We are using:
It uses Do you suggest us to change |
Yes, please try that.
What scenario do you have mind? If I understand the docs correctly,
|
I was mostly concerned with if using I don't quite understand how sandboxing works, from the post here it seems to be mostly restricting bazel's access to other files, not other processes' access to bazel files in the sandbox? What would be the benefits of using In any case, chance of such a collision is slim. I'll give |
@laszlocsomor I tried I found this SO post, which shows that for macOS, In any case, do you recommend the |
I think, not sure, that since the jvm is notoriously bad at removing temp
files on exit then you might reuse that directory on subsequent runs. Right?
…On Wed, 6 Dec 2017 at 5:42 Lai Jiang ***@***.***> wrote:
@laszlocsomor <https://github.com/laszlocsomor> I tried $TMPDIR and it
gives the same path as null, which kinda make sense as null is supposed
to use the default temp directory. I tried adding bazel tmp directory too
long jvm_flags = ["-Djava.io.tmpdir=/tmp"] as suggested by the OP to the
test rule and it works on macOS. I'll try tomorrow on Debian.
I found this
<https://stackoverflow.com/questions/45200150/bazel-how-to-get-a-short-but-hermetic-temp-dir-for-tests>
SO post, which shows that for macOS
<https://github.com/bazelbuild/bazel/blob/b4bf984f36766ba85abb7ac7449657fe793d1818/src/main/java/com/google/devtools/build/lib/sandbox/DarwinSandboxedSpawnRunner.java#L140>,
\tmp is always added to the writable locations when sandboxing. There're
some similar logic for Linux
<https://github.com/bazelbuild/bazel/blob/a2d2615362c65be98629b39ce39754a325ed1c42/src/main/java/com/google/devtools/build/lib/sandbox/LinuxSandboxedSpawnRunner.java#L241>,
so maybe that'll work?
In any case, do you recommend the jvm_flags trick? Any drawbacks?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#3215 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABUIF-CmNiMDTLK-alQ5wJ0euf-mh1iRks5s9g1AgaJpZM4N-FGI>
.
|
@ittaiz I don't that is the concern here, @laszlocsomor Some findings: The command I run:
I tried to set Sandbox, Sandbox, Local, Local, Sandboxing always results in a path that is too long. Without sandboxing, if I set As I mentioned before, setting It is really unfortunate that I had to forgo sandboxing to get a short enough path... |
We should fix this and I very very much recommend against disabling sandboxing. Any weird hack is better than disabling sandboxing, which not only means that your action can no longer run on a remote execution platform, it can also accidentally wipe your home folder, use information from untracked sources, ... it also means using a vastly inferior process management that might leave processes running in the background after your action ends. When using the sandbox with the "required option" --sandbox_tmpfs_path=/tmp to ensure a hermetic /tmp, we could easily set TMPDIR to /tmp, as every sandboxed action will then get its own fresh and empty /tmp directory. When not using that option, we could create a temporary folder below /tmp and then use that as the value for TMPDIR. I don't follow why using /tmp would be less hermetic than the current path? I mean, yes, in theory processes could write to your securely generated temporary folder that has a randomized name in /tmp - but the sandbox is not meant to (and cannot) protect against malicious acts. It is meant as a safety net so that you don't accidentally wipe your files and depend on untracked state. @laszlocsomor What do you think? |
It'll be more desirable if sandbox_tmpfs_path can be specified in a test rule other than on the command line. So the currently suggested solution is to not disable sandboxing, but to create tmp folders under
You are right, I mis-interpreted the intention of sandboxing. |
@jianglai : Thanks for your patience and for the info about the status quo. I discussed this issue in person with @philwo, @dslomov, and some others, here are my conclusions. I can't think of a satisfactory mechanism in current Bazel to achieve what you need. Therefore I think we need a new feature: a means for the user to control the temp directory path. Specifying a temp path in the build rule would make the rule platform- and machine-dependent, ruling out remote execution and building on other platforms. I don't think that's a worthy tradeoff. Thinking about remote execution, it seems reasonable to assume that the machine wouldn't allow accessing I prefer adding a new flag to Bazel, e.g. Finally, I think it should be a flag rather than an environment variable, because flags are explicit and you can set them in the How does that sound? What do others think -- @philwo , @dslomov ? |
@laszlocsomor, @philwo, @dslomov : Looks good to me in general. Some comments/questions below:
Agreed, hardcooding is always less desirable.
I generally prefer this approach. I'd just set I probably don't understand all the intricacies of bazel, but why can't it by default, or through a flag, use the system temp directory as the tmp base?
Partially agree that whether to override the default tmp root should be configured by a flag, but like I said in the comment above, it seems to be a reasonable expectation that the system would provide some sort of tmp directory that bazel can query and use (instead of having the user provide one), if the user set the flag. |
Is there any better solution than adding the following option to our BUILD rule to fix the issue temporarily?
We know it's not the best long term solution, but until |
I'm not aware of any better workarounds. |
Detailed discussion can be found on github (bazelbuild/bazel#3215). On newer Debian systems as well as on macOS, the temporary folder created to store gpg configs are too long, which results in an error: gpg: can't connect to the agent: File name too long This CL makes affected tests use /tmp as temp folder base. Other options are discussed in the github issue, but this one seems to be the mostly non-harmful one. Note that this change only affect the FOSS build, as internal builds are not affected by the temp directory issue, probably due to the internal build tool using a different base temp directory. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=178803914
Just want to make sure that I understand the fix. It seems that |
Correct. Sorry for not communicating that more clearly.
Yes you are, and yes, it is how you said. |
Just to make sure- if I used to specify “-Djava.io.tmpdir=/tmp“ in many test rules then I don’t need to do it anymore? |
@ittaiz : On Linux/macOS: no, you no longer need to specify that flag: bazel/src/main/java/com/google/devtools/build/lib/exec/local/PosixLocalEnvProvider.java Lines 49 to 53 in a729b9b
bazel/src/main/java/com/google/devtools/build/lib/exec/apple/XCodeLocalEnvProvider.java Lines 73 to 77 in a729b9b
On Windows, Bazel falls back to the tmp-in-execroot, so you either have to export bazel/src/main/java/com/google/devtools/build/lib/exec/local/WindowsLocalEnvProvider.java Line 58 in a729b9b
|
Thanks!
…On Fri, 9 Feb 2018 at 14:21 László Csomor ***@***.***> wrote:
@ittaiz <https://github.com/ittaiz> : On Linux/macOS: no, you no longer
need this flag:
https://github.com/bazelbuild/bazel/blob/a729b9b4c3d7844a7d44934bf3365f92633c0a60/src/main/java/com/google/devtools/build/lib/exec/local/PosixLocalEnvProvider.java#L49-L53
https://github.com/bazelbuild/bazel/blob/a729b9b4c3d7844a7d44934bf3365f92633c0a60/src/main/java/com/google/devtools/build/lib/exec/apple/XCodeLocalEnvProvider.java#L73-L77
On Windows, Bazel falls back to the tmp-in-execroot:
https://github.com/bazelbuild/bazel/blob/a729b9b4c3d7844a7d44934bf3365f92633c0a60/src/main/java/com/google/devtools/build/lib/exec/local/WindowsLocalEnvProvider.java#L58
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#3215 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABUIFw13PcsOaX_Qk80OCFrR5wXXemZLks5tTDgwgaJpZM4N-FGI>
.
|
Btw, |
Yes, it's possible that TMPDIR is defined by default, not only on OSX but on Linux too. Do you see any practical difference between adding a flag to everyone's |
The difference is that we generate the bazelrc and check it in the projects
so people don’t need to do anything manually.
Having people need to change their bash profile will become tribal
knowledge.
…On Mon, 12 Feb 2018 at 10:31 László Csomor ***@***.***> wrote:
Yes, it's possible that TMPDIR is defined by default, not only on OSX but
on Linux.
Do you see any practical difference between adding a flag to everyone's
~/.bazelrc (assuming Bazel supported the flag), and adding export
TMPDIR=/tmp to everyone's ~/.bash_profile? I believe they'd have the same
desired effect, would amount to the same work on your side, but the latter
would require no work from the Bazel team. WDYT?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#3215 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABUIF-UQraXMtEm0JGzSv84xIppLLfcZks5tT_b8gaJpZM4N-FGI>
.
|
OK, I'll implement the flag then. |
Add new flag called `--local_tmp_root`, which (if specified) tells Bazel what temp directory should locally executed actions use. Fixes #4621 Related to #3215 RELNOTES[NEW]: The new "--local_tmp_root=<path>" flag allows specifying the temp directory for locally executed actions. Change-Id: Ice69a5e63d0bf4d3b5c9ef4dbdd1ed1c5025f85e PiperOrigin-RevId: 185509555
*** Reason for rollback *** There's already a --test_tmpdir flag, and Java tests don't pick up this new one. More info: #4621 (comment) *** Original change description *** tmpdir,local-exec: implement --local_tmp_root Add new flag called `--local_tmp_root`, which (if specified) tells Bazel what temp directory should locally executed actions use. Fixes #4621 Related to #3215 RELNOTES[NEW]: The new "--local_tmp_root=<path>" flag allows specifying the temp directory for locally executed actions. Change-Id: Ice69a5e63d0bf4d3b5c9ef4dbdd1ed1c5025f85e PiperOrigin-RevId: 185982705
FYI, I decided to roll back the For the record, there's already a I'll discuss with the team how to go forward. |
So we haven't visited this issue for a while. Any updates? |
I generally agree with the sentiment that Bazel should be using We have encountered this too in some tests and have fixed it by making any such affected test use Also, given that Unix domain socket names are restricted in length, any test that wants to create them must ensure that they fit within those limits. Relying on any environment variable or the cwd configured by Bazel to be "short enough" is bound to fail in some cases, so I'd say that we shouldn't get into that business and that any tests relying on this specific limit must explicitly account for it. |
I have an issue with files created at temp directory having too long pathname.
Please kindly see this SO question.
I managed to solve that by explicitly adding to my test target
But that hurts the hermetical principle of testing.
I suggest we offer much shorter yet unique tmp location for tests
(somehting like
/tmp/bazel-<unique-7-chars>
)WDYT?
The text was updated successfully, but these errors were encountered: