-
Notifications
You must be signed in to change notification settings - Fork 653
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
NIOAsyncWriter: Fix suspending yield when writer is finished #3044
NIOAsyncWriter: Fix suspending yield when writer is finished #3044
Conversation
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.
This is a great catch, thanks so much!
Regarding your test, it might be useful for the test to use a new delegate that makes it easier to arrange the ordering to work out. NIO's ConditionLock can be used to set up a nice ordering chain, so that instead of using the usleeps we can just block on that lock being unlocked with the right value.
bf18517
to
f15a87b
Compare
@Lukasa : I updated it with ConditionLock. Is this what you had in mind? This is still blocking a thread from the concurrency pool and then depending on another thread to unblock it. Will that not be a problem? The only way I see around that is to add an async hook to NIOAsyncWriter. |
For testing purposes, that blocking will be safe. We will eventually resolve it, and we don't rely on Dispatch to make that happen (it requires the NIO thread to do it), so it'll be ok. |
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.
This is a really lovely patch, thanks so much @orobio!
I'm not sure I fully understand what you're saying here, but I assume it's fine then. I do still have that 'FIXME' line in there, which would probably be good to remove. Well..., this got merged while I was typing, so I'll open a new pull request for that. Edit: Opened #3059 |
This was left in when pull request apple#3044 was merged, but as discussed on that pull request, this doesn't need to be fixed.
This was left in when pull request #3044 was merged, but as discussed on that pull request, this doesn't need to be fixed.
This fixes hitting the following preconditionFailure in NIOAsyncWriter: "This should have already been handled by
yield()
".It doesn't expect a yield to be suspended when the state is
.writerFinished
, but this can definitely happen. This seemed to be the correct solution to me, but please check it carefully, because I'm unfamiliar with this code.I'm not happy about the test for this. It's blocking the
didYield
call for a while, to make sure the correct state is reached. See also the 'FIXME' line. What would be a better way to do this?