Use select to query the uv kqueue #5378
Merged
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.
This resolves #38. Read the issue for context, but after debugging the problem looks like this:
When a pty is in the uv kqueue, the poll kqueue does not properly clear the event after receiving it. The obvious fix would be to add
EV_CLEAR
to the event flags so that it is definitely cleared after receiving any event, however this causes a race condition in Darwin. The poll kqueue is signaled before the uv kqueue, resulting in the uv thread running once, seeing no events, and going back to sleep, while simultaneously the poll thread clears its kqueue out. This results in events being delayed until the next event comes in. You can verify that this is a race condition by addingEV_CLEAR
to the original kevent call and then adding a sleep at the end ofPollEvents
The code is simply waiting for data to be available for reading on the uv kqueue file descriptor, which
select
also does. I have migrated the Darwin-specific uv polling code to useselect
instead of kqueue.I've verified that events still get processed like they should on El Capitan 10.11.3 (15D21).
Note:
poll
doesn't work on kqueues, otherwise I would have used that instead.