-
Notifications
You must be signed in to change notification settings - Fork 931
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
Small changes to scheduler comments and state changes #1746
Conversation
Tries to make some of the comments in scheduler.c easier to follow, and simplifies a couple of the scheduler channel state changes.
Pull Request Test Coverage Report for Build 8145
💛 - Coveralls |
* This side-effect will only occur if the channel is currently in the | ||
* 'SCHED_CHAN_WAITING_TO_WRITE' or 'SCHED_CHAN_IDLE' states, which KIST | ||
* rarely uses, so it should be fine unless KIST begins using these states | ||
* in the future. */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Useful comment! That made me curious to figure out the side-effect here of having a scheduler change after this call. Correct me if I'm wrong (this is quite spaghetti code to follow):
When KIST is within a scheduler loop, the channel can only be in PENDING
or WAITING_FOR_CELLS
. Actually, I know for a fact that scheduler_channel_wants_writes()
is 99% called because the outbuf length is always below the low watermark (those marks are a remain of the vanilla scheduler past).
datalen = connection_get_outbuf_len(TO_CONN(conn));
if (datalen < OR_CONN_LOWWATER) {
/* Let the scheduler know */
scheduler_channel_wants_writes(TLS_CHAN_TO_BASE(conn->chan));
}
However, because the channel is in PENDING
or WAITING_FOR_CELLS
state, scheduler_channel_wants_writes()
just results in doing nothing.
And thus no side effect since the channel will not change state within a scheduler loop.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep that sounds right to me. Even when it's under the low water mark, the function will have no effect if the state is PENDING
or WAITING_FOR_CELLS
, which are the only states KIST uses unless a connection is closing or errors (since with KIST channels always want to write). I just wanted to document this in case someone modifies KIST in the future (for example following the comments here) and doesn't realize that the state may change from somewhere way outside of the scheduling loop. Or for someone like me who's just looking at the code, isn't sure if KIST handles that situation correctly, and then spends an hour working through that side-case to make sure nothing is going wrong :) It might be useful to add something like
old_state = chan->scheduler_state;
connection_handle_write(...);
tor_assert_nonfatal_once(chan->scheduler_state == old_state);
but for now I just wanted to document it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed... I agree that a nonfatal assert() would help us in the future and be a clear way to have "code documentation" about the expected re-entry behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just let me know if you'd like for me to include that in this PR and remove the comment, but I currently have no way of testing it to make sure that it never asserts (such as if a channel is closing or something).
See ticket #33349.
Merged in: f056186