()
| 712 | } |
| 713 | |
| 714 | func (c *channel) initHealthCheck() { |
| 715 | c.ping = make(chan struct{}, 1) |
| 716 | |
| 717 | go func() { |
| 718 | timer := time.NewTimer(time.Minute) |
| 719 | timer.Stop() |
| 720 | |
| 721 | for { |
| 722 | timer.Reset(c.checkInterval) |
| 723 | select { |
| 724 | case <-c.ping: |
| 725 | select { |
| 726 | case <-timer.C: |
| 727 | default: |
| 728 | } |
| 729 | case <-timer.C: |
| 730 | ctx, cancel := context.WithTimeout(context.Background(), c.pingTimeout) |
| 731 | pingErr := c.pubSub.Ping(ctx) |
| 732 | cancel() |
| 733 | |
| 734 | if pingErr != nil { |
| 735 | c.pubSub.mu.Lock() |
| 736 | reconnectCtx, reconnectCancel := context.WithTimeout(context.Background(), c.reconnectTimeout) |
| 737 | c.pubSub.reconnect(reconnectCtx, pingErr) |
| 738 | reconnectCancel() |
| 739 | c.pubSub.mu.Unlock() |
| 740 | } |
| 741 | case <-c.pubSub.exit: |
| 742 | return |
| 743 | } |
| 744 | } |
| 745 | }() |
| 746 | } |
| 747 | |
| 748 | // initMsgChan must be in sync with initAllChan. |
| 749 | func (c *channel) initMsgChan() { |
no test coverage detected