Skip to content

Commit

Permalink
fix: return nil instead of argument error if there is no listener on …
Browse files Browse the repository at this point in the history
…a topic. Logging this event is just enough.
  • Loading branch information
buraksezer committed Nov 27, 2022
1 parent d944fe9 commit 056e1bb
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
16 changes: 11 additions & 5 deletions internal/dtopic/dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ package dtopic
import (
"context"
"fmt"
"github.com/buraksezer/olric/pkg/neterrors"
"math/rand"
"runtime"
"sync"

"github.com/buraksezer/olric/pkg/flog"
"github.com/buraksezer/olric/pkg/neterrors"
"golang.org/x/sync/semaphore"
)

Expand All @@ -40,11 +41,13 @@ type Dispatcher struct {

m map[string]*listeners
ctx context.Context
log *flog.Logger
}

func NewDispatcher(ctx context.Context) *Dispatcher {
func NewDispatcher(ctx context.Context, log *flog.Logger) *Dispatcher {
return &Dispatcher{
m: make(map[string]*listeners),
log: log,
ctx: ctx,
}
}
Expand Down Expand Up @@ -89,7 +92,9 @@ func (d *Dispatcher) removeListener(topic string, listenerID uint64) error {

l, ok := d.m[topic]
if !ok {
return neterrors.Wrap(neterrors.ErrInvalidArgument, fmt.Sprintf("topic not found: %s", topic))
// There is no active listener for this topic
d.log.V(3).Printf("[DEBUG] Topic not found: %s, possibly there is no listener", topic)
return nil
}

_, ok = l.m[listenerID]
Expand All @@ -112,8 +117,9 @@ func (d *Dispatcher) dispatch(topic string, msg *Message) error {

l, ok := d.m[topic]
if !ok {
// there is no listener for this topic on this node.
return fmt.Errorf("%w: topic not found: %s", neterrors.ErrInvalidArgument, topic)
// There is no active listener for this topic
d.log.V(3).Printf("[DEBUG] Topic not found: %s, possibly there is no listener", topic)
return nil
}

var wg sync.WaitGroup
Expand Down
2 changes: 1 addition & 1 deletion internal/dtopic/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func NewService(e *environment.Environment) (service.Service, error) {
client: e.Get("client").(*transport.Client),
log: e.Get("logger").(*flog.Logger),
rt: e.Get("routingtable").(*routingtable.RoutingTable),
dispatcher: NewDispatcher(context.Background()),
dispatcher: NewDispatcher(ctx, e.Get("logger").(*flog.Logger)),
m: make(map[string]*DTopic),
ctx: ctx,
cancel: cancel,
Expand Down
2 changes: 1 addition & 1 deletion olric.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ import (
)

// ReleaseVersion is the current stable version of Olric
const ReleaseVersion string = "0.4.7"
const ReleaseVersion string = "0.4.10"

var (
// ErrOperationTimeout is returned when an operation times out.
Expand Down

0 comments on commit 056e1bb

Please sign in to comment.