From 8e30ede8c76d3ba147ee85942a7b313e5fa476f6 Mon Sep 17 00:00:00 2001 From: Huan Huang Date: Sun, 12 Jul 2020 14:17:56 +0800 Subject: [PATCH] track error (#1815) * track error * remove useless code Co-authored-by: huanghuan.27@bytedance.com Co-authored-by: Asim Aslam --- registry/mdns_registry.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/registry/mdns_registry.go b/registry/mdns_registry.go index 8b3a33d5..fabc4978 100644 --- a/registry/mdns_registry.go +++ b/registry/mdns_registry.go @@ -84,14 +84,22 @@ func encode(txt *mdnsTxt) ([]string, error) { defer buf.Reset() w := zlib.NewWriter(&buf) + defer func() { + if closeErr := w.Close(); closeErr != nil { + if logger.V(logger.ErrorLevel, logger.DefaultLogger) { + logger.Errorf("[mdns] registry close encoding writer err: %v", closeErr) + } + } + }() if _, err := w.Write(b); err != nil { - w.Close() return nil, err } - w.Close() + + if err = w.Close(); err != nil { + return nil, err + } encoded := hex.EncodeToString(buf.Bytes()) - // individual txt limit if len(encoded) <= 255 { return []string{encoded}, nil