Skip to content

Commit 8fa78b1

Browse files
committed
Reject too large elements to the queue
Without this change, the requests without deadline will block forever until the space is available which will never be. Signed-off-by: Bogdan Drutu <[email protected]>
1 parent cf18559 commit 8fa78b1

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

.chloggen/fix-too-large-size.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: bug_fix
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
7+
component: exporterhelper
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Reject elements larger than the queue capacity
11+
12+
# One or more tracking issues or pull requests related to the change
13+
issues: [12847]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext:
19+
20+
# Optional: The change log or logs in which this entry should be included.
21+
# e.g. '[user]' or '[user, api]'
22+
# Include 'user' if the change is relevant to end users.
23+
# Include 'api' if there is a change to a library API.
24+
# Default: '[user]'
25+
change_logs: []

exporter/exporterhelper/internal/queuebatch/memory_queue.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ var blockingDonePool = sync.Pool{
2121
}
2222

2323
var errInvalidSize = errors.New("invalid element size")
24+
var errSizeTooLarge = errors.New("element size too large")
2425

2526
// memoryQueueSettings defines internal parameters for boundedMemoryQueue creation.
2627
type memoryQueueSettings[T any] struct {
@@ -74,6 +75,11 @@ func (mq *memoryQueue[T]) Offer(ctx context.Context, el T) error {
7475
return errInvalidSize
7576
}
7677

78+
// If element larger than the capacity, will never been able to add it.
79+
if elSize > mq.cap {
80+
return errSizeTooLarge
81+
}
82+
7783
done, err := mq.add(ctx, el, elSize)
7884
if err != nil {
7985
return err

exporter/exporterhelper/internal/queuebatch/memory_queue_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,11 @@ func TestMemoryQueueOfferInvalidSize(t *testing.T) {
9797
require.ErrorIs(t, q.Offer(context.Background(), -1), errInvalidSize)
9898
}
9999

100+
func TestMemoryQueueRejectOverCapacityElements(t *testing.T) {
101+
q := newMemoryQueue[int64](memoryQueueSettings[int64]{sizer: sizerInt64{}, capacity: 7, blockOnOverflow: true})
102+
require.ErrorIs(t, q.Offer(context.Background(), 8), errSizeTooLarge)
103+
}
104+
100105
func TestMemoryQueueOfferZeroSize(t *testing.T) {
101106
q := newMemoryQueue[int64](memoryQueueSettings[int64]{sizer: sizerInt64{}, capacity: 1})
102107
require.NoError(t, q.Offer(context.Background(), 0))

0 commit comments

Comments
 (0)