[Canary] lib: monkey: proceed oversized fired events on windows - #12359
Draft
cosmo0920 wants to merge 2 commits into
Draft
[Canary] lib: monkey: proceed oversized fired events on windows#12359cosmo0920 wants to merge 2 commits into
cosmo0920 wants to merge 2 commits into
Conversation
…ation Signed-off-by: Hiroshi Hatake <hiroshi@chronosphere.io>
Signed-off-by: Hiroshi Hatake <hiroshi@chronosphere.io>
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: trueThanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This is a Canary PR. DO NOT MERGE THIS.
Currently, monkey core does not have a bound of firing events.
This PR adds a capability for proceeding out-of-bounds sized events on monkey core.
What is wrong. The libevent backend allocates
ctx->firedonce, at loop creation, with 256 entries for the engine loop, and never grows it.cb_eventand_mk_event_injectappend to it with no bounds check, so the 257th event that becomes ready in a singleevent_base_looppass writes past the heap block. The reporter's stack trace, page-heap fault, and the fired_count of 546 in the 5.0.7 dump all match this. Only Windows is affected in practice, since the epoll and kqueue backends passqueue_sizeto the kernel and cannot overrun.The fix, in mk_event_libevent.c:
mk_event_fired_push, doubles the array withmk_mem_reallocwhen it is full, and both append sites go through it. If the realloc fails, the notification is dropped instead of overflowing. That is safe because the events are level triggered and persistent, so a still-ready descriptor fires again on the next pass. Growing inside the callback is safe: I checked every consumer, and all of them re-readctx->firedthrough the context pointer rather than caching a pointer into it.ev_mapstructs. What was real is that the timer'sev_map, its write socket, and its libevent timer lived on untilcb_timeoutnoticed the peer was closed, and leaked entirely if the event was removed via plainmk_event_delor the loop was destroyed. Now oneev_mapowns the socket pair and the timer,_mk_event_delstops the timer, unregisters, and closes both ends in one place, andcb_timeoutonly signals._mk_event_delalso now unregisters from libevent before closing sockets, since on Windows a closed handle can be reused by another thread immediately.Regression test in flb_event_loop.c: it creates a loop of size 64, registers 256 pipes that are all readable at once, and drains them. It is backend-neutral, since epoll simply needs more passes.
Verification with the NMake Debug tree in
build/:Mitigation for users until a release ships is to keep the number of simultaneously ready events under 256: a finite
Retry_Limiton the forward output,storage.max_chunks_upbelow 256, andstorage.total_limit_sizeto bound the backlog. These reduce the odds but do not remove the bug.Related to #11905.
This patch is fully included in monkey/monkey#446.
Enter
[N/A]in the box, if an item is not applicable to your change.Testing
Before we can approve your change; please submit the following in a comment:
If this is a change to packaging of containers or native binaries then please confirm it works for all targets.
ok-package-testlabel to test for all targets (requires maintainer to do).Documentation
Backporting
Fluent Bit is licensed under Apache 2.0, by submitting this pull request I understand that this code will be released under the terms of that license.