Skip to content

Commit

Permalink
Merge pull request #27 from mysteriumnetwork/nats-reconnect
Browse files Browse the repository at this point in the history
Panic if nats connection closed
  • Loading branch information
vkuznecovas authored Jul 27, 2021
2 parents 9a25d2a + 0ec650c commit 4b00308
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 11 additions & 1 deletion listener/proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package listener
import (
"encoding/json"
"errors"
"time"

v2 "github.com/mysteriumnetwork/discovery/proposal/v2"

Expand All @@ -30,7 +31,16 @@ func New(brokerURL string, repository *proposal.Repository) *Listener {
}

func (l *Listener) Listen() error {
conn, err := nats.Connect(l.brokerURL)
var opts = func(opts *nats.Options) error {
opts.PingInterval = time.Second * 5
opts.MaxReconnect = 5
opts.ClosedCB = func(c *nats.Conn) {
panic("nats connection closed")
}
return nil
}

conn, err := nats.Connect(l.brokerURL, opts)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion proposal/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (s *Service) List(opts ListOpts) ([]v2.Proposal, error) {
// exclude monitoringFailed nodes
sessionsResponse, err := s.qualityService.Sessions(opts.from)
if err != nil {
log.Warn().Err(err).Msgf("Could not fetch session stats for consumer", opts.from)
log.Warn().Err(err).Msgf("Could not fetch session stats for consumer %v", opts.from)
} else {
for k, proposal := range resultMap {
if sessionsResponse.MonitoringFailed(proposal.ProviderID, proposal.ServiceType) {
Expand Down

0 comments on commit 4b00308

Please sign in to comment.