Skip to content
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

Postloop callbacks 2 #41

Merged
merged 7 commits into from Apr 13, 2018
Merged

Conversation

Labels
None yet
Projects
None yet
3 participants
@nmathewson
Copy link
Contributor

@nmathewson nmathewson commented Apr 5, 2018

No description provided.

nmathewson added 6 commits Apr 13, 2018
See bug #25787 for discussion; we should have a better fix here.
We've been labeling some events as happening "outside the event
loop", to avoid Libevent starvation.  This patch provides a cleaner
mechanism to avoid that starvation.

For background, the problem here is that Libevent only scans for new
events once it has run all its active callbacks.  So if the
callbacks keep activating new callbacks, they could potentially
starve Libevent indefinitely and keep it from ever checking for
timed, socket, or signal events.

To solve this, we add the ability to label some events as
"post-loop".  The rule for a "post-loop" event is that any events
_it_ activates can only be run after libevent has re-scanned for new
events at least once.
A linked connection_t is one that gets its I/O, not from the
network, but from another connection_t.  When such a connection has
something to write, we want the corresponding connection to run its
read callback ... but not immediately, to avoid infinite recursion
and/or event loop starvation.

Previously we handled this case by activating the read events
outside the event loop.  Now we use the "postloop event" logic.
This lets us simplify do_main_loop_once() a little.
This is a second motivating case for our postloop event logic.
This test works by having two post-loop events activate one another
in a tight loop.  If the "post-loop" mechanism didn't work, this
would be enough to starve all other events.
@nmathewson nmathewson force-pushed the postloop_callbacks_2 branch from 117de42 to 2fe499e Apr 13, 2018
@dgoulet-tor
Copy link
Contributor

@dgoulet-tor dgoulet-tor commented Apr 13, 2018

So this all lgtm! The only thing I think can be done as an extra commit is to remove the tell_event_loop_to_run_external_code() code since it is not used anymore.

@tor-bot tor-bot merged commit 4c03af4 into torproject:master Apr 13, 2018
1 check was pending
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment