Allocate much larger buffer for event data, remove incorrect logic #17
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
We have recently been alerted about an issue where go-udev returns the following error:
udev event error: Unable to parse uevent, err: no buffer space available
(see https://bugs.launchpad.net/snapd/+bug/1833707).The reference implementation of udev monitor coming from systemd uses a large buffer for events - see https://github.com/systemd/systemd/blob/master/src/udev/udevadm-monitor.c#L73 ; while go-udev implements logic for resizing the buffer, it is based on a wrong assumption regarding MSG_PEEK flag; the meaning of the flag is simply the following:
"This flag causes the receive operation to return data from the beginning of the receive queue without removing that data from the queue. Thus, a subsequent receive call will return the same data."
This PR pre-allocates the buffer based on reference implementation from systemd, and removes the resizing logic. Also, the allocation is moved to the Connect method so it's done only once.
I think that maybe MSG_PEEK should be OR'ed with MSG_TRUNC flag and then the resizing logic would work, but I'm not able to reproduce this error case, so I chose a conservative fix.