Skip to content

Commit

Permalink
[fix] [exporterhelper] Fix nil ptr dereference on storage stop (#8718)
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.

**Description:** 
Fixing a bug that resulted in panic when de-referencing nil pointer. The
issue is that in the persistent queue fail to start due to say bad
folder permissions, then the `Start` method does not actually set the
associated persistent storage, and thus when shutting down it tries to
stop the storage and panics.
  • Loading branch information
fredthomsen authored Oct 23, 2023
1 parent 9f454ff commit 37116a2
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 37116a2

Please sign in to comment.