From ec69624f8afc768d3f35815d4d91d7f5696a4f84 Mon Sep 17 00:00:00 2001 From: pwli <763045276@qq.com> Date: Thu, 19 May 2022 22:43:53 +0800 Subject: [PATCH] fix:(transport/http): fix unexpected overriding behavior when return an error (#1984) * fix:(transport/http): fix unexpected overriding behavior when return an error * fix:(transport/http): fix broken tests Co-authored-by: pwli0755 --- transport/http/resolver.go | 12 ++++++------ transport/http/resolver_test.go | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/transport/http/resolver.go b/transport/http/resolver.go index 6a264cb33..6bb1c3fff 100644 --- a/transport/http/resolver.go +++ b/transport/http/resolver.go @@ -79,17 +79,17 @@ func newResolver(ctx context.Context, discovery registry.Discovery, target *Targ select { case err := <-done: if err != nil { - err := watcher.Stop() - if err != nil { - r.logger.Errorf("failed to http client watch stop: %v", target) + stopErr := watcher.Stop() + if stopErr != nil { + r.logger.Errorf("failed to http client watch stop: %v, error: %+v", target, stopErr) } return nil, err } case <-ctx.Done(): r.logger.Errorf("http client watch service %v reaching context deadline!", target) - err := watcher.Stop() - if err != nil { - r.logger.Errorf("failed to http client watch stop: %v", target) + stopErr := watcher.Stop() + if stopErr != nil { + r.logger.Errorf("failed to http client watch stop: %v, error: %+v", target, stopErr) } return nil, ctx.Err() } diff --git a/transport/http/resolver_test.go b/transport/http/resolver_test.go index 5a214ad95..419bae44a 100644 --- a/transport/http/resolver_test.go +++ b/transport/http/resolver_test.go @@ -77,10 +77,10 @@ type mockWatch struct { } func (m *mockWatch) Next() ([]*registry.ServiceInstance, error) { - m.count++ if m.count == 1 { return nil, errors.New("mock test error") } + m.count++ instance := ®istry.ServiceInstance{ ID: "1", Name: "kratos",