From fcca9afe0cdb3d23e6fc653dd334161cbc6d832a Mon Sep 17 00:00:00 2001 From: Stanislav Chzhen Date: Wed, 24 Apr 2024 18:56:34 +0300 Subject: [PATCH] all: fix client duplicate uids --- CHANGELOG.md | 2 ++ internal/client/index.go | 10 ++++++++-- internal/home/clients.go | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a180412d26..3e707048f2d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,6 +34,8 @@ NOTE: Add new changes BELOW THIS COMMENT. ### Fixed +- Acceptance of duplicate UIDs for persistent clients at startup. See also a + section on client settings on the [Wiki page][wiki-config]. - Issues with QUIC and HTTP/3 upstreams on older Linux kernel versions ([#6422]). - YouTube restricted mode is not enforced by HTTPS queries on Firefox. diff --git a/internal/client/index.go b/internal/client/index.go index c6a17cb3703..7ab33f67d9c 100644 --- a/internal/client/index.go +++ b/internal/client/index.go @@ -85,10 +85,16 @@ func (ci *Index) Add(c *Persistent) { // Clashes returns an error if the index contains a different persistent client // with at least a single identifier contained by c. c must be non-nil. func (ci *Index) Clashes(c *Persistent) (err error) { + p, ok := ci.uidToClient[c.UID] + if ok { + return fmt.Errorf("another client %q uses the same UID", p.Name) + } + for _, id := range c.ClientIDs { - existing, ok := ci.clientIDToUID[id] + var existing UID + existing, ok = ci.clientIDToUID[id] if ok && existing != c.UID { - p := ci.uidToClient[existing] + p = ci.uidToClient[existing] return fmt.Errorf("another client %q uses the same ID %q", p.Name, id) } diff --git a/internal/home/clients.go b/internal/home/clients.go index 1474002bc5f..b2fc16fd0b0 100644 --- a/internal/home/clients.go +++ b/internal/home/clients.go @@ -286,7 +286,7 @@ func (clients *clientsContainer) addFromConfig( _, err = clients.add(cli) if err != nil { - log.Error("clients: adding client at index %d %s: %s", i, cli.Name, err) + return fmt.Errorf("clients: adding client at index %d %s: %w", i, cli.Name, err) } }