Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delay reconnect log #2636

Merged
merged 3 commits into from
Mar 15, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions changelog/unreleased/delay-reconnect-log.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Bugfix: delay reconnect log for events

Print reconnect information log only when reconnect time is bigger than a second

https://github.com/cs3org/reva/pull/2636
6 changes: 4 additions & 2 deletions pkg/events/server/nats.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package server

import (
"fmt"
"time"

"github.com/asim/go-micro/plugins/events/nats/v4"
"github.com/cenkalti/backoff"
Expand All @@ -46,10 +47,11 @@ func NewNatsStream(opts ...nats.Option) (events.Stream, error) {
b := backoff.NewExponentialBackOff()
var stream events.Stream
o := func() error {
n := b.NextBackOff()
s, err := nats.NewStream(opts...)
if err != nil {
if err != nil && n > time.Second {
// TODO: should we get the standard logger here? if yes: How?
fmt.Printf("can't connect to nats (stan) server, retrying in %s\n", b.NextBackOff())
fmt.Printf("can't connect to nats (stan) server, retrying in %s\n", n)
kobergj marked this conversation as resolved.
Show resolved Hide resolved
}
stream = s
return err
Expand Down