fork of https://github.com/sourcegraph/zoekt
0

Configure Feed

Select the types of activity you want to include in your feed.

indexserver: don't exit if socket connection fails (#495)

Instead of failing hard, we simply log an move on. So far this
connection is only used for a nonessential feature ("reindex button").

+30 -23
+30 -23
cmd/zoekt-sourcegraph-indexserver/main.go
··· 1140 1140 1141 1141 }() 1142 1142 1143 - // Serve mux on a unix domain socket so that webserver can call the 1144 - // endpoints via the shared filesystem. 1143 + // Serve mux on a unix domain socket on a best-effort-basis so that 1144 + // webserver can call the endpoints via the shared filesystem. 1145 + // 1146 + // 2022-12-08: Docker for Mac with VirtioFS enabled will fail to listen 1147 + // on the socket due to permission errors. See 1148 + // https://github.com/docker/for-mac/issues/6239 1145 1149 go func() { 1146 - socket := filepath.Join(s.IndexDir, "indexserver.sock") 1147 - // We cannot bind a socket to an existing pathname. 1148 - if err := os.Remove(socket); err != nil && !errors.Is(err, fs.ErrNotExist) { 1149 - log.Fatalf("error removing socket file: %s", socket) 1150 - } 1151 - // The "unix" network corresponds to stream sockets. (cf. unixgram, 1152 - // unixpacket). 1153 - l, err := net.Listen("unix", socket) 1154 - if err != nil { 1155 - log.Fatalf("failed to listen on socket: %s", err) 1156 - } 1157 - // Indexserver (root) and webserver (Sourcegraph) run with 1158 - // different users. Per default, the socket is created with 1159 - // permission 755 (root root), which doesn't let webserver write to 1160 - // it. 1161 - // 1162 - // See https://github.com/golang/go/issues/11822 for more context. 1163 - if err := os.Chmod(socket, 0777); err != nil { 1164 - log.Fatalf("failed to change permission of socket %s: %s", socket, err) 1150 + serveHTTPOverSocket := func() error { 1151 + socket := filepath.Join(s.IndexDir, "indexserver.sock") 1152 + // We cannot bind a socket to an existing pathname. 1153 + if err := os.Remove(socket); err != nil && !errors.Is(err, fs.ErrNotExist) { 1154 + return fmt.Errorf("error removing socket file: %s", socket) 1155 + } 1156 + // The "unix" network corresponds to stream sockets. (cf. unixgram, 1157 + // unixpacket). 1158 + l, err := net.Listen("unix", socket) 1159 + if err != nil { 1160 + return fmt.Errorf("failed to listen on socket %s: %w", socket, err) 1161 + } 1162 + // Indexserver (root) and webserver (Sourcegraph) run with 1163 + // different users. Per default, the socket is created with 1164 + // permission 755 (root root), which doesn't let webserver write to 1165 + // it. 1166 + // 1167 + // See https://github.com/golang/go/issues/11822 for more context. 1168 + if err := os.Chmod(socket, 0777); err != nil { 1169 + return fmt.Errorf("failed to change permission of socket %s: %w", socket, err) 1170 + } 1171 + debug.Printf("serving HTTP on %s", socket) 1172 + return http.Serve(l, mux) 1165 1173 } 1166 - debug.Printf("serving HTTP on %s", socket) 1167 - log.Fatal(http.Serve(l, mux)) 1174 + debug.Print(serveHTTPOverSocket()) 1168 1175 }() 1169 1176 } 1170 1177