fix(GODT-2272): use shorter filename for gRPC file socket.

This commit is contained in:
Xavier Michelon 2023-01-31 15:35:03 +01:00
parent e382687168
commit 342a2a5568
No known key found for this signature in database
GPG Key ID: DAE1FC3F3255843C
2 changed files with 10 additions and 2 deletions

View File

@ -89,6 +89,6 @@ There are now three types of system folders which Bridge recognises:
| gluon messages | sata | gluon/backend/store |
| Update files | data | updates |
| sentry cache | data | sentry_cache |
| Mac/Linux File Socket | temp | bridge_{RANDOM_UUID}.sock |
| Mac/Linux File Socket | temp | bridge{4_DIGITS} |

View File

@ -25,6 +25,7 @@ import (
"errors"
"fmt"
"io/fs"
"math/rand"
"net"
"os"
"path/filepath"
@ -580,10 +581,17 @@ func (s *Service) monitorParentPID() {
func computeFileSocketPath() (string, error) {
tempPath := os.TempDir()
for i := 0; i < 1000; i++ {
path := filepath.Join(tempPath, fmt.Sprintf("bridge_%v.sock", uuid.NewString()))
path := filepath.Join(tempPath, fmt.Sprintf("bridge%04d", rand.Intn(10000))) // nolint:gosec
if _, err := os.Stat(path); errors.Is(err, fs.ErrNotExist) {
return path, nil
}
if err := os.Remove(path); err != nil {
logrus.WithField("path", path).WithError(err).Warning("Could not remove existing socket file")
continue
}
return path, nil
}
return "", errors.New("unable to find a suitable file socket in user config folder")