From 3cabecda04d43352200a41e54d08fa1d54a7abc9 Mon Sep 17 00:00:00 2001 From: Jakob Borg Date: Sat, 24 Sep 2016 07:33:56 +0000 Subject: [PATCH] lib/upnp: Correct the result deduplication mechanism (fixes #3578) GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/3618 --- lib/upnp/upnp.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/upnp/upnp.go b/lib/upnp/upnp.go index 38504fd36..4f4b50f98 100644 --- a/lib/upnp/upnp.go +++ b/lib/upnp/upnp.go @@ -108,19 +108,21 @@ func Discover(renewal, timeout time.Duration) []nat.Device { close(resultChan) }() + seenResults := make(map[string]bool) nextResult: for result := range resultChan { - for _, existingResult := range results { - if existingResult.ID() == result.ID() { - l.Debugf("Skipping duplicate result %s with services:", result.uuid) - for _, service := range result.services { - l.Debugf("* [%s] %s", service.ID, service.URL) - } - continue nextResult + if seenResults[result.ID()] { + l.Debugf("Skipping duplicate result %s with services:", result.uuid) + for _, service := range result.services { + l.Debugf("* [%s] %s", service.ID, service.URL) } + continue nextResult } + result := result // Reallocate as we need to keep a pointer results = append(results, &result) + seenResults[result.ID()] = true + l.Debugf("UPnP discovery result %s with services:", result.uuid) for _, service := range result.services { l.Debugf("* [%s] %s", service.ID, service.URL)