Skip to content

Commit 2588e15

Browse files
[exporterhelper][batcher] - Fix the bug related to worker pool (#13689)
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description While working on an unrelated tasks, I observed unrestricted number of `partitionBatcher.flush(..)` being spinned. This resulted in `ConsumeLogs` being called excessively. If I understand correctly, we're supposed to return the worker to `qb.workerPool` only when the `consumeFunc` has returned. Right now, we're calling the `consumeFunc` in a background goroutine and returning the worker immediately in the main goroutine. Here's the previous behaviour for comparision: https://github.com/open-telemetry/opentelemetry-collector/pull/13164/files#diff-e3328327e734297f98f035f3eb463dc25c06843b82e6d48053020a94df0b9e94L189-L198 <!--Describe what testing was performed and which tests were added.--> #### Testing Did manual testing and verified the number of goroutines via profiling. --------- Co-authored-by: Bogdan Drutu <[email protected]>
1 parent 1d58da3 commit 2588e15

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

.chloggen/batcher-bug-workers.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: Prevent uncontrolled goroutines in batcher due to a incorrect worker pool behaviour.
11+
12+
# One or more tracking issues or pull requests related to the change
13+
issues: [13689]
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/partition_batcher.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,12 @@ func newWorkerPool(maxWorkers int) *workerPool {
261261

262262
func (wp *workerPool) execute(f func()) {
263263
<-wp.workers
264-
go f()
265-
wp.workers <- struct{}{}
264+
go func() {
265+
defer func() {
266+
wp.workers <- struct{}{}
267+
}()
268+
f()
269+
}()
266270
}
267271

268272
type multiDone []queue.Done

0 commit comments

Comments
 (0)