Repository: syncthing/syncthing (language: go)

Issue:
GUI address unix socket broken
### What happened?

syncthing used to work with a unix socket as a GUI address, e.g. when using a command line option like this:

`-gui-address=unix:///run/syncthing/syncthing.sock`

It worked until 1.28.0 (including), and then in 1.28.1. it broke and complains.

I think PR #9675 is the culprit, more specifically commit 65d0ca8aa96efa785fe9527de992e7efaabc22bd

### Syncthing version

v1.28.1

### Platform & operating system

Linux amd64

### Browser version

_No response_

### Relevant log output

```shell
[start] WARNING: Failed to initialize config: failed to generate default config: get default port (GUI): address /run/syncthing/syncthing.sock: missing port in address
```



Discussion / hints:
Yep, seems like that
Will look into it, but I might need a couple of days... 
A workaround for this case is to pass the `--skip-port-probing` option, which is of course useless in case of a UNIX socket.

Still looking into the root cause of this failure.  It happens only when generating a new config, not when simply overriding an existing one's GUI address.
> A workaround for this case is to pass the `--skip-port-probing` option, which is of course useless in case of a UNIX socket.
> 
> Still looking into the root cause of this failure. It happens only when generating a new config, not when simply overriding an existing one's GUI address.

I confirm this workaround works, I tested it with an existing config file, and also without a preexisting config file. That's good enough for me.

Fix patch:
diff --git a/lib/config/config.go b/lib/config/config.go
index a16c8923d91..772694859b2 100644
--- a/lib/config/config.go
+++ b/lib/config/config.go
@@ -139,21 +139,23 @@ func New(myID protocol.DeviceID) Configuration {
 }
 
 func (cfg *Configuration) ProbeFreePorts() error {
-	guiHost, guiPort, err := net.SplitHostPort(cfg.GUI.Address())
-	if err != nil {
-		return fmt.Errorf("get default port (GUI): %w", err)
-	}
-	port, err := strconv.Atoi(guiPort)
-	if err != nil {
-		return fmt.Errorf("convert default port (GUI): %w", err)
-	}
-	port, err = getFreePort(guiHost, port)
-	if err != nil {
-		return fmt.Errorf("get free port (GUI): %w", err)
+	if cfg.GUI.Network() == "tcp" {
+		guiHost, guiPort, err := net.SplitHostPort(cfg.GUI.Address())
+		if err != nil {
+			return fmt.Errorf("get default port (GUI): %w", err)
+		}
+		port, err := strconv.Atoi(guiPort)
+		if err != nil {
+			return fmt.Errorf("convert default port (GUI): %w", err)
+		}
+		port, err = getFreePort(guiHost, port)
+		if err != nil {
+			return fmt.Errorf("get free port (GUI): %w", err)
+		}
+		cfg.GUI.RawAddress = net.JoinHostPort(guiHost, strconv.Itoa(port))
 	}
-	cfg.GUI.RawAddress = net.JoinHostPort(guiHost, strconv.Itoa(port))
 
-	port, err = getFreePort("0.0.0.0", DefaultTCPPort)
+	port, err := getFreePort("0.0.0.0", DefaultTCPPort)
 	if err != nil {
 		return fmt.Errorf("get free port (BEP): %w", err)
 	}


Test patch: