fix reconnect close

This commit is contained in:
c9s 2020-07-13 01:06:04 +08:00
parent 906350a5bc
commit a9e25c08d7

View File

@ -147,13 +147,21 @@ func (s *PrivateStream) read(ctx context.Context, eventC chan interface{}) {
mt, message, err := s.Conn.ReadMessage() mt, message, err := s.Conn.ReadMessage()
if err != nil { if err != nil {
if websocket.IsUnexpectedCloseError(err, websocket.CloseGoingAway) {
log.WithError(err).Errorf("read error: %s", err.Error()) log.WithError(err).Errorf("read error: %s", err.Error())
}
// reconnect // reconnect
for err != nil { for err != nil {
select {
case <-ctx.Done():
return
default:
err = s.connect(ctx) err = s.connect(ctx)
time.Sleep(5 * time.Second) time.Sleep(5 * time.Second)
} }
}
continue continue
} }