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 ea2b2a0
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
25 changes: 25 additions & 0 deletions .chloggen/fix-nil-storage-panic-on-bad-start.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: bug_fix

# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
component: exporterhelper

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Fix nil pointer dereference when stopping persistent queue after a start encountered an error

# One or more tracking issues or pull requests related to the change
issues: [8718]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:

# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: []
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 ea2b2a0

Please sign in to comment.