Skip to content

Commit

Permalink
ignore jsonld.ContextURLNotAllowedErr errors at startup (#2570)
Browse files Browse the repository at this point in the history
  • Loading branch information
gerardsn authored Oct 27, 2023
1 parent 6d4bef3 commit 93c09fa
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
7 changes: 7 additions & 0 deletions network/dag/notifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/nuts-foundation/nuts-node/jsonld"
"strings"
"time"

"github.com/avast/retry-go/v4"
Expand Down Expand Up @@ -246,6 +248,11 @@ func (p *notifier) Run() error {
event := Event{}
_ = json.Unmarshal(v, &event)

// Do not retry events that previously failed on an unknown context. See https://github.com/nuts-foundation/nuts-node/issues/2569
if strings.HasSuffix(event.Error, jsonld.ContextURLNotAllowedErr.Error()) {
return nil
}

if err := p.notifyNow(event); err != nil {
if event.Retries < maxRetries {
failedAtStartup = append(failedAtStartup, event)
Expand Down
20 changes: 20 additions & 0 deletions network/dag/notifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"errors"
"github.com/nuts-foundation/go-stoabs"
"github.com/nuts-foundation/nuts-node/crypto/hash"
"github.com/nuts-foundation/nuts-node/jsonld"
"github.com/nuts-foundation/nuts-node/storage"
"github.com/nuts-foundation/nuts-node/test"
"github.com/nuts-foundation/nuts-node/test/io"
Expand Down Expand Up @@ -415,6 +416,25 @@ func TestNotifier_Run(t *testing.T) {
return index != -1, nil
}, time.Second, "timeout while waiting for go routine to start")
})

t.Run("OK - does not retry unknown context errors", func(t *testing.T) {
ctx := context.Background()
filePath := io.TestDirectory(t)
kvStore := storage.CreateTestBBoltStore(t, path.Join(filePath, "test.db"))
counter := callbackCounter{}
s := NewNotifier(t.Name(), counter.callbackFinished, WithPersistency(kvStore), WithRetryDelay(time.Millisecond)).(*notifier)
defer s.Close()

event := Event{Error: "some error: " + jsonld.ContextURLNotAllowedErr.Error()}
_ = kvStore.WriteShelf(ctx, s.shelfName(), func(writer stoabs.Writer) error {
bytes, _ := json.Marshal(event)
return writer.Put(stoabs.BytesKey(event.Hash.Slice()), bytes)
})

err := s.Run()
require.NoError(t, err)
assert.Equal(t, int64(0), counter.N.Load())
})
}

func TestNotifier_VariousFlows(t *testing.T) {
Expand Down

0 comments on commit 93c09fa

Please sign in to comment.