Fix hanging err channel send

This commit is contained in:
Kevin Cotugno 2017-09-25 16:40:36 -07:00
parent 406fb75d56
commit 46a6316523
2 changed files with 26 additions and 2 deletions

View File

@ -19,6 +19,9 @@ type ListenerService struct {
closed bool
shouldRestart bool
restMu sync.Mutex
errorsMu sync.Mutex
sendErrors bool
}
func (s *ListenerService) Open() error {
@ -95,13 +98,19 @@ func (s *ListenerService) listen() {
go func() {
for err := range s.Client.Error() {
s.Logger.Info("Error from GDAX client: %v", err)
s.err <- err
if s.SendErrors() {
s.err <- err
}
}
s.Logger.Info("Error closed")
if s.restart() {
err := s.Open()
if err != nil {
s.Logger.Info("GDAX Unable to reastablish connection")
s.Close()
return
}
s.Subscribe(s.subs...)
@ -123,3 +132,17 @@ func (s *ListenerService) setRestart(restart bool) {
s.shouldRestart = restart
}
func (s *ListenerService) SendErrors() bool {
s.errorsMu.Lock()
defer s.errorsMu.Unlock()
return s.sendErrors
}
func (s *ListenerService) SetSendErrors(send bool) {
s.errorsMu.Lock()
defer s.errorsMu.Unlock()
s.sendErrors = send
}

View File

@ -50,12 +50,13 @@ func (c *Client) Open() error {
websocket.CloseNormalClosure) {
c.sendClose(false)
c.err <- err
break
}
break
}
c.msgs <- msg
}
close(c.msgs)
close(c.err)
}()