Skip to content

Commit

Permalink
Swap LibevQuicEventBase callback list before processing the callbacks.
Browse files Browse the repository at this point in the history
Summary:
Previously, the last callback in the list could destroy the LibevQuicEventBase and invalidate the referenced loopCallbackWrappers intrusive list used in the while loop check.

This swaps the list to avoid this corner case.

Reviewed By: mjoras, sharmafb

Differential Revision: D52529616

fbshipit-source-id: 57cbed96c48799bf93d3e12934d82496c5b84ab4
  • Loading branch information
jbeshay authored and facebook-github-bot committed Jan 4, 2024
1 parent 6d722b1 commit bcb22b0
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions quic/common/events/LibevQuicEventBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,16 @@ void LibevQuicEventBase::scheduleTimeout(
}

void LibevQuicEventBase::checkCallbacks() {
while (!loopCallbackWrappers_.empty()) {
loopCallbackWrappers_.front().runLoopCallback();
// Running the callbacks in the loop callback list may change the contents of
// the list or completely delete the list (with the event base). We swap the
// list here to ensure the list survives until the end of the function.
folly::IntrusiveList<LoopCallbackWrapper, &LoopCallbackWrapper::listHook_>
currentLoopWrappers;
loopCallbackWrappers_.swap(currentLoopWrappers);
while (!currentLoopWrappers.empty()) {
// runLoopCallback first unlinks the callback wrapper from the list.
// This allows the callback to schedule itself again on the swapped list.
currentLoopWrappers.front().runLoopCallback();
}
}

Expand Down

0 comments on commit bcb22b0

Please sign in to comment.