Skip to content

Commit

Permalink
[fix] [exporterhelper] Fix nil ptr dereference
Browse files Browse the repository at this point in the history
When persistent queue fails to start, for example due to bad
permissions, then persistent storage does not get allocated.
Thus, ensure stop storage method is only called if actually
initialized.
  • Loading branch information
fredthomsen committed Oct 21, 2023
1 parent 844b628 commit 60d0ff9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
4 changes: 3 additions & 1 deletion exporter/exporterhelper/internal/persistent_queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ import (
var (
// Monkey patching for unit test
stopStorage = func(queue *persistentQueue) {
queue.storage.stop()
if queue.storage != nil {
queue.storage.stop()
}
}
errNoStorageClient = errors.New("no storage client extension found")
errWrongExtensionType = errors.New("requested extension is not a storage extension")
Expand Down
9 changes: 9 additions & 0 deletions exporter/exporterhelper/internal/persistent_queue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,3 +292,12 @@ func TestInvalidStorageExtensionType(t *testing.T) {
assert.ErrorIs(t, err, errWrongExtensionType)
assert.Nil(t, client)
}

func TestPersistentQueue_StopAfterBadStart(t *testing.T) {
pq := NewPersistentQueue(1, 1, component.ID{}, newFakeTracesRequestMarshalerFunc(),
newFakeTracesRequestUnmarshalerFunc())
// verify that stopping a un-start/started w/error queue does not panic
assert.NotPanics(t, func() {
pq.Stop()
})
}

0 comments on commit 60d0ff9

Please sign in to comment.