Skip to content

Commit c1c7745

Browse files
eventbus: change slow consumer event from error to warn (libp2p#3286)
Closes ipfs/kubo#10778
1 parent 813d78c commit c1c7745

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

p2p/host/eventbus/basic.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414

1515
type logInterface interface {
1616
Errorf(string, ...interface{})
17+
Warnf(string, ...interface{})
1718
}
1819

1920
var log logInterface = logging.Logger("eventbus")
@@ -464,7 +465,7 @@ func emitAndLogError(timer *time.Timer, typ reflect.Type, evt interface{}, sink
464465
<-timer.C
465466
}
466467
case <-timer.C:
467-
log.Errorf("subscriber named \"%s\" is a slow consumer of %s. This can lead to libp2p stalling and hard to debug issues.", sink.name, typ)
468+
log.Warnf("subscriber named \"%s\" is a slow consumer of %s. This can lead to libp2p stalling and hard to debug issues.", sink.name, typ)
468469
// Continue to stall since there's nothing else we can do.
469470
sink.ch <- evt
470471
}

p2p/host/eventbus/basic_test.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ import (
1818
"github.com/stretchr/testify/require"
1919
)
2020

21-
type EventA struct{}
22-
type EventB int
21+
type (
22+
EventA struct{}
23+
EventB int
24+
)
2325

2426
func getN() int {
2527
n := 50000
@@ -144,6 +146,10 @@ func (m *mockLogger) Errorf(format string, args ...interface{}) {
144146
m.logs = append(m.logs, fmt.Sprintf(format, args...))
145147
}
146148

149+
func (m *mockLogger) Warnf(format string, args ...interface{}) {
150+
m.Errorf(format, args...)
151+
}
152+
147153
func (m *mockLogger) Logs() []string {
148154
m.mu.Lock()
149155
defer m.mu.Unlock()

0 commit comments

Comments
 (0)