-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
udp-receiver async - fix data corruption (with buffer pools) (#28898)
**Description:** Fixing a bug in udp async mode only (but didn't affect the default non-async mode). Udp-receiver reuses the same buffer when each packet is processed. While that's working fine when running it without async config, it cause a significant amount of duplicate packets and corrupted packets being sent downstream. The reader-async thread is reading a packet from the udp port into the buffer, places that buffer in the channel, and reads another packet into the same buffer and pushes it to the channel. Let's say that the processor-async thread was a bit slow, so it only tries to read from the channel after the 2 items were placed in the channel. In that case, the processor thread will read 2 items from the channel, but it will be the same 2nd packet (since the 1st one was overwritten). In some cases, it seems the processor is reading a corrupted buffer (since the reader is currently writing into it). We can't fix it by having the reader allocate a new buffer before each time it reads a packet from the udp port, since that hurts performance significantly (reducing it up to ~50%). Instead, use a pool so the buffers are reused. Before reading a packet, the reader get a buffer from the pool. The processor returns it back to the pool after it has been successfully processed **Link to tracking Issue:** 27613 **Testing:** Ran existing unitests. Ran ran stress tests (sending 250k udp packets per second) duplicate/corruption issue didn't happen; performance wasn't hurt. **Documentation:** None
- Loading branch information
Showing
2 changed files
with
67 additions
and
19 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
.chloggen/pkg-stanza-input-udp-async-fix-data-corruption.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# 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. filelogreceiver) | ||
component: pkg/stanza | ||
|
||
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). | ||
note: Fix data-corruption/race-condition issue in udp async (reuse of buffer); use buffer pool isntead. | ||
|
||
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. | ||
issues: [27613] | ||
|
||
# (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: | ||
|
||
# If your change doesn't affect end users or the exported elements of any package, | ||
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label. | ||
# 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: [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters