mozilla / sccache

Sccache is a ccache-like tool. It is used as a compiler wrapper and avoids compilation when possible. Sccache has the capability to utilize caching in remote storage environments, including various cloud storage options, or alternatively, in local storage.
Apache License 2.0
5.74k stars 542 forks source link

Server fails starting if `TMPDIR` path is too long #1309

Open cipriancraciun opened 2 years ago

cipriancraciun commented 2 years ago

If for whatever reason the TMPDIR environment variable is longer than usual (as per https://man7.org/linux/man-pages/man7/unix.7.html closer to ~100 characters), sscache fails to start with the following error:

export TMPDIR="/tmp/sccache--1234567890-1234567890-1234567890-1234567890-1234567890-1234567890-1234567890--tmpdir"
mkdir "${TMPDIR}"

sccache --start-server

sccache: Starting the server...
sccache: error: failed to start server process
sccache: caused by: path must be shorter than libc::sockaddr_un.sun_path

The issue seems related to the following code: https://github.com/mozilla/sccache/blob/c60b81cda5e37cc4330e894fd192240e7ae40032/src/commands.rs#L84-L102


An easy fix (that won't bother the current users, but that allows those that trigger this issue) is to use the environment variable SCCACHE_STARTUP_NOTIFY and use that as the socket path.

The code already uses SCCACHE_STARTUP_NOTIFY internally, and in fact it is even documented: https://github.com/mozilla/sccache/blob/c60b81cda5e37cc4330e894fd192240e7ae40032/docs/Configuration.md?plain=1#L62

(Perhaps this is a regression from a previous code version that actually used it?)

drahnr commented 2 years ago

Hey, thanks for reporting.

The issue is twofold; on unix there is a limitation of the length, which you exceed by the construction based on the tmp dir being too long. That part works as expected. Ref https://github.com/torvalds/linux/blob/master/include/uapi/linux/un.h

SCCACHE_STARTUP_NOTIFY on the other hand side should be accounted for and only fall back to the above construction if not present.

cipriancraciun commented 2 years ago

Still on the topic of SCCACHE_STARTUP_NOTIFY; my assumption is that it's used between the sccache cc process and the server that was just started as a way to notify that it's up-and-running; or perhaps to get some information regarding if the server is actually running.

In that case, and seeing your commit that fixes the issue, what if you also take into account the following scenario: making sure that sccache doesn't fork in the background by exporting the SCCACHE_STARTUP_NOTIFY as something like an empty string (or something like (none)). This way, the user has to make sure sccache is properly running, and any sccache cc won't try to fork and start it.

drahnr commented 2 years ago

That'd be a new feature and should be dealt with separately. I am not clear about the exact use case though.