From 81b3a83401b7aa73134c75b19e0281520c8589ca Mon Sep 17 00:00:00 2001 From: Ramy Medhat Date: Fri, 28 Aug 2020 23:53:02 -0400 Subject: [PATCH] Fallback to /tmp when socket address is longer than max length. Test: Temporary change of base name to cover handled cases. Change-Id: I1f6953752e7861ccbe7180351386ed65ab5fc259 --- ui/build/rbe.go | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/ui/build/rbe.go b/ui/build/rbe.go index 67bcebb75..c4b829d2e 100644 --- a/ui/build/rbe.go +++ b/ui/build/rbe.go @@ -19,6 +19,7 @@ import ( "math/rand" "os" "path/filepath" + "syscall" "time" "android/soong/ui/metrics" @@ -50,8 +51,25 @@ func rbeCommand(ctx Context, config Config, rbeCmd string) string { return cmdPath } -func getRBEVars(ctx Context, config Config) map[string]string { +func sockAddr(dir string) (string, error) { + maxNameLen := len(syscall.RawSockaddrUnix{}.Path) rand.Seed(time.Now().UnixNano()) + base := fmt.Sprintf("reproxy_%v.sock", rand.Intn(1000)) + + name := filepath.Join(dir, base) + if len(name) < maxNameLen { + return name, nil + } + + name = filepath.Join("/tmp", base) + if len(name) < maxNameLen { + return name, nil + } + + return "", fmt.Errorf("cannot generate a proxy socket address shorter than the limit of %v", maxNameLen) +} + +func getRBEVars(ctx Context, config Config) map[string]string { vars := map[string]string{ "RBE_log_path": config.rbeLogPath(), "RBE_log_dir": config.logDir(), @@ -60,7 +78,12 @@ func getRBEVars(ctx Context, config Config) map[string]string { "RBE_output_dir": config.rbeStatsOutputDir(), } if config.StartRBE() { - vars["RBE_server_address"] = fmt.Sprintf("unix://%v/reproxy_%v.sock", absPath(ctx, config.TempDir()), rand.Intn(1000)) + name, err := sockAddr(absPath(ctx, config.TempDir())) + if err != nil { + ctx.Fatalf("Error retrieving socket address: %v", err) + return nil + } + vars["RBE_server_address"] = fmt.Sprintf("unix://%v", name) } k, v := config.rbeAuth() vars[k] = v