Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 480
#2995 followups#3193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Uh oh!
There was an error while loading. Please reload this page.
Merged
#2995 followups #3193
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1047,21 +1047,25 @@ where | ||
| } | ||
| } | ||
| macro_rules! drop_handled_events_and_abort { ($self: expr, $res: expr, $offset: expr, $event_queue: expr) => { | ||
| macro_rules! drop_handled_events_and_abort { ($self: expr, $res_iter: expr, $event_queue: expr) => { | ||
| // We want to make sure to cleanly abort upon event handling failure. To this end, we drop all | ||
| // successfully handled events from the given queue, reset the events processing flag, and | ||
| // return, to have the events eventually replayed upon next invocation. | ||
| { | ||
| let mut queue_lock = $event_queue.lock().unwrap(); | ||
| // We skip `$offset` result entries to reach the ones relevant for the given `$event_queue`. | ||
| let mut res_iter = $res.iter().skip($offset); | ||
| // Keep all events which previously error'd *or* any that have been added since we dropped | ||
| // the Mutex before. | ||
| queue_lock.retain(|_| res_iter.next().map_or(true, |r| r.is_err())); | ||
| let mut any_error = false; | ||
| queue_lock.retain(|_| { | ||
| $res_iter.next().map_or(true, |r| { | ||
| let is_err = r.is_err(); | ||
| any_error |= is_err; | ||
| is_err | ||
| }) | ||
| }); | ||
| if $res.iter().any(|r| r.is_err()) { | ||
| if any_error { | ||
| // We failed handling some events. Return to have them eventually replayed. | ||
| $self.pending_events_processor.store(false, Ordering::Release); | ||
| $self.event_notifier.notify(); | ||
| @@ -1426,7 +1430,8 @@ where | ||
| } | ||
| // Let the `OnionMessageIntercepted` events finish before moving on to peer_connecteds | ||
| let res = MultiResultFuturePoller::new(futures).await; | ||
| drop_handled_events_and_abort!(self, res, intercepted_msgs_offset, self.pending_intercepted_msgs_events); | ||
| let mut res_iter = res.iter().skip(intercepted_msgs_offset); | ||
| drop_handled_events_and_abort!(self, res_iter, self.pending_intercepted_msgs_events); | ||
| } | ||
| { | ||
| @@ -1449,7 +1454,8 @@ where | ||
| futures.push(future); | ||
| } | ||
| let res = MultiResultFuturePoller::new(futures).await; | ||
| drop_handled_events_and_abort!(self, res, 0, self.pending_peer_connected_events); | ||
| let mut res_iter = res.iter(); | ||
| drop_handled_events_and_abort!(self, res_iter, self.pending_peer_connected_events); | ||
| } | ||
| } | ||
| self.pending_events_processor.store(false, Ordering::Release); | ||
| @@ -1508,7 +1514,7 @@ where | ||
| { | ||
| let pending_intercepted_msgs_events = self.pending_intercepted_msgs_events.lock().unwrap(); | ||
| intercepted_msgs = pending_intercepted_msgs_events.clone(); | ||
| let mut pending_peer_connected_events = self.pending_peer_connected_events.lock().unwrap(); | ||
| let pending_peer_connected_events = self.pending_peer_connected_events.lock().unwrap(); | ||
| peer_connecteds = pending_peer_connected_events.clone(); | ||
| #[cfg(debug_assertions)] { | ||
| for ev in pending_intercepted_msgs_events.iter() { | ||
| @@ -1518,14 +1524,47 @@ where | ||
| if let Event::OnionMessagePeerConnected { .. } = ev {} else { panic!(); } | ||
| } | ||
| } | ||
| pending_peer_connected_events.shrink_to(10); // Limit total heap usage | ||
| } | ||
| let res = intercepted_msgs.into_iter().map(|ev| handler.handle_event(ev)).collect::<Vec<_>>(); | ||
| drop_handled_events_and_abort!(self, res, 0, self.pending_intercepted_msgs_events); | ||
| let mut handling_intercepted_msgs_failed = false; | ||
| let mut num_handled_intercepted_events = 0; | ||
| for ev in intercepted_msgs { | ||
| match handler.handle_event(ev) { | ||
| Ok(()) => num_handled_intercepted_events += 1, | ||
| Err(ReplayEvent ()) => { | ||
| handling_intercepted_msgs_failed = true; | ||
| break; | ||
| } | ||
| } | ||
| } | ||
| { | ||
| let mut pending_intercepted_msgs_events = self.pending_intercepted_msgs_events.lock().unwrap(); | ||
| pending_intercepted_msgs_events.drain(..num_handled_intercepted_events); | ||
| } | ||
| let res = peer_connecteds.into_iter().map(|ev| handler.handle_event(ev)).collect::<Vec<_>>(); | ||
| drop_handled_events_and_abort!(self, res, 0, self.pending_peer_connected_events); | ||
| if handling_intercepted_msgs_failed { | ||
| self.pending_events_processor.store(false, Ordering::Release); | ||
| self.event_notifier.notify(); | ||
| return; | ||
tnull marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| } | ||
| let mut num_handled_peer_connecteds = 0; | ||
| for ev in peer_connecteds { | ||
| match handler.handle_event(ev) { | ||
| Ok(()) => num_handled_peer_connecteds += 1, | ||
| Err(ReplayEvent ()) => { | ||
| self.event_notifier.notify(); | ||
| break; | ||
tnull marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| } | ||
| } | ||
| } | ||
| { | ||
| let mut pending_peer_connected_events = self.pending_peer_connected_events.lock().unwrap(); | ||
| pending_peer_connected_events.drain(..num_handled_peer_connecteds); | ||
| pending_peer_connected_events.shrink_to(10); // Limit total heap usage | ||
| } | ||
| self.pending_events_processor.store(false, Ordering::Release); | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.