diff --git a/go.mod b/go.mod index ddfd182..13eec73 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/chia-network/chia-exporter go 1.21 require ( - github.com/chia-network/go-chia-libs v0.16.1 + github.com/chia-network/go-chia-libs v0.17.0 github.com/chia-network/go-modules v0.0.8 github.com/go-sql-driver/mysql v1.8.1 github.com/oschwald/maxminddb-golang v1.13.1 diff --git a/go.sum b/go.sum index 1210e41..5b8069c 100644 --- a/go.sum +++ b/go.sum @@ -4,8 +4,8 @@ github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= -github.com/chia-network/go-chia-libs v0.16.1 h1:oMOfvGodh7aCXX0xGFGU6NtmC+u/bz5BUptUbirH1jI= -github.com/chia-network/go-chia-libs v0.16.1/go.mod h1:npTqaFSjTdMxE7hc0LOmWJmWGqcs+IERarK5fDxXk/I= +github.com/chia-network/go-chia-libs v0.17.0 h1:MwzUxprIDyKNWTbac32BGc8G2p6FH8erbaug64xXl8c= +github.com/chia-network/go-chia-libs v0.17.0/go.mod h1:npTqaFSjTdMxE7hc0LOmWJmWGqcs+IERarK5fDxXk/I= github.com/chia-network/go-modules v0.0.8 h1:VATMxehRISOhaRwPo/GL735IKWW0G7sUYH2OmBofsfE= github.com/chia-network/go-modules v0.0.8/go.mod h1:OdvlWftyJc3+i3QYv5cfQsiQASL7Em7fJnzdmPmj07M= github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= diff --git a/internal/metrics/metrics.go b/internal/metrics/metrics.go index cd796d8..ac8916b 100644 --- a/internal/metrics/metrics.go +++ b/internal/metrics/metrics.go @@ -138,6 +138,12 @@ func NewMetrics(port uint16, logLevel log.Level, version string) (*Metrics, erro } func (m *Metrics) setNewClient() error { + if m.client != nil { + err := m.client.Close() + if err != nil { + log.Error("Error closing old client", "error", err) + } + } client, err := rpc.NewClient(rpc.ConnectionModeWebsocket, rpc.WithAutoConfig(), rpc.WithBaseURL(&url.URL{ Scheme: "wss", Host: viper.GetString("hostname"), @@ -353,7 +359,6 @@ func (m *Metrics) OpenWebsocket() error { for { // If we don't get any events for 5 minutes, we'll reset the connection time.Sleep(10 * time.Second) - if m.lastReceive.Before(time.Now().Add(-5 * time.Minute)) { cancel() log.Info("Websocket connection seems down. Recreating...") @@ -372,7 +377,7 @@ func (m *Metrics) OpenWebsocket() error { // Got the new connection open, so stop the loop on the old connection // since we called this function again and a new loop was created - break + return } } }() @@ -382,9 +387,7 @@ func (m *Metrics) OpenWebsocket() error { // CloseWebsocket closes the websocket connection func (m *Metrics) CloseWebsocket() error { - // @TODO reenable once fixed in the upstream dep - //return m.client.DaemonService.CloseConnection() - return nil + return m.client.Close() } // StartServer starts the metrics server