Fix hanging err channel send
This commit is contained in:
parent
406fb75d56
commit
46a6316523
@ -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
|
||||
}
|
||||
|
@ -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)
|
||||
}()
|
||||
|
Reference in New Issue
Block a user