From 6d55e95389688e6eed143602bb7b59c90c14795f Mon Sep 17 00:00:00 2001 From: Robert Laszczak Date: Mon, 12 Nov 2018 13:40:07 +0100 Subject: [PATCH] fixed close support for http.Subscriber --- message/infrastructure/http/subscriber.go | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/message/infrastructure/http/subscriber.go b/message/infrastructure/http/subscriber.go index 58379f763..1943cd035 100644 --- a/message/infrastructure/http/subscriber.go +++ b/message/infrastructure/http/subscriber.go @@ -33,7 +33,7 @@ func NewSubscriber(addr string, unmarshalMessageFunc UnmarshalMessageFunc, logge s, logger, unmarshalMessageFunc, - make([]chan *message.Message, 1), + make([]chan *message.Message, 0), &sync.Mutex{}, false, }, nil @@ -84,17 +84,19 @@ func (s *Subscriber) RunHTTPServer() error { return s.server.ListenAndServe() } -func (s Subscriber) Close() error { +func (s *Subscriber) Close() error { if s.closed { return nil } s.closed = true - defer func() { - for _, ch := range s.outputChannels { - close(ch) - } - }() + if err := s.server.Close(); err != nil { + return err + } + + for _, ch := range s.outputChannels { + close(ch) + } - return s.server.Close() + return nil }