From 011c3d398d1d6a798659c1b3e517c1a7a619cae6 Mon Sep 17 00:00:00 2001 From: Jeff Haynie Date: Sat, 27 Jun 2020 12:55:27 -0500 Subject: [PATCH] remove ping code --- event/event.go | 53 +------------------------------------------------- 1 file changed, 1 insertion(+), 52 deletions(-) diff --git a/event/event.go b/event/event.go index a3434a3..a173e7c 100644 --- a/event/event.go +++ b/event/event.go @@ -413,7 +413,6 @@ func (c *SubscriptionChannel) Close() error { } close(c.done) close(c.ch) - c.checkLastPingsStop() } return nil } @@ -430,45 +429,6 @@ var defaultInsecureWSDialer = &websocket.Dialer{ EnableCompression: true, } -func (c *SubscriptionChannel) pingReceived() { - c.lastPingMu.Lock() - c.lastPing = time.Now() - c.lastPingMu.Unlock() -} - -const expectedDurationBetweenPings = 30 * time.Second - -func (c *SubscriptionChannel) checkLastPingsInit() { - c.pingReceived() // make initial checks right - c.lastPingTimer = time.NewTicker(expectedDurationBetweenPings) - c.lastPingsDone = make(chan bool) -} - -func (c *SubscriptionChannel) checkLastPingsLoop() { - for { - select { - case <-c.lastPingsDone: - return - case <-c.lastPingTimer.C: - c.lastPingMu.Lock() - lastPing := c.lastPing - c.lastPingMu.Unlock() - // crash if 5 last pings were missed - // would be better to retry subscription, but can't figure out how to do this cleanly here, since it would be blocked on wch.ReadJSON() - if time.Since(lastPing) > 5*expectedDurationBetweenPings { - panic(fmt.Errorf("no pings received for %v, expecting pings every %v", time.Since(lastPing), expectedDurationBetweenPings)) - } - } - } -} - -func (c *SubscriptionChannel) checkLastPingsStop() { - if c.lastPingTimer != nil { - c.lastPingTimer.Stop() - c.lastPingsDone <- true - } -} - // Publish will send a message to the event api func (c *SubscriptionChannel) Publish(event PublishEvent, options ...Option) error { ts := time.Now() @@ -659,12 +619,6 @@ func (c *SubscriptionChannel) run() { c.mu.Unlock() log.Debug(c.subscription.Logger, "connected") - pinghandler := wch.PingHandler() - wch.SetPingHandler(func(data string) error { - c.pingReceived() - return pinghandler(data) - }) - var subid string if len(c.subscription.Topics) > 0 { @@ -695,11 +649,6 @@ func (c *SubscriptionChannel) run() { c.mu.Unlock() } - if !c.subscription.DisablePing { - c.checkLastPingsInit() // have it separately to avoid races with Close - go c.checkLastPingsLoop() - } - errors = 0 var errored bool var closed bool @@ -862,7 +811,7 @@ type Subscription struct { HTTPHeaders map[string]string `json:"-"` CloseTimeout time.Duration `json:"-"` DispatchTimeout time.Duration `json:"-"` - DisablePing bool `json:"-"` + DisablePing bool `json:"-"` // Deprecated } // NewSubscription will create a subscription to the event server and will continously read events (as they arrive)