Skip to content

fix kqueue EV_SET bug#7

Open
zt2 wants to merge 2 commits into
dsh0416:masterfrom
zt2:master
Open

fix kqueue EV_SET bug#7
zt2 wants to merge 2 commits into
dsh0416:masterfrom
zt2:master

Conversation

@zt2
Copy link
Copy Markdown

@zt2 zt2 commented Jul 31, 2021

Hi,

I find using Net::HTTP will hangs forever with kqueue on mac like issue #6 , for example:

require 'evt'
require 'net/http'

scheduler = Evt::Scheduler.new

Fiber.set_scheduler scheduler

100.times do
  Fiber.schedule do
    p Net::HTTP.get('httpbin.org', '/ip')
  end
end

After some researching, I found this problem is trigged in ext/evt/kqueue.h:

    if (ruby_interest & readable) {
        event_flags |= EVFILT_READ;
    }

    if (ruby_interest & writable) {
        event_flags |= EVFILT_WRITE;
    }

    EV_SET(&event, fd, event_flags, EV_ADD|EV_ENABLE|EV_ONESHOT, 0, 0, (void*) io);

EVFILT_READ == ffffffff
EVFILT_WRITE == fffffffe

That makes EVFILT_READ | EVFILT_WRITE == EVFILT_READ and the script will hang on one event.

The result is that "or"-ing them together makes kqueue wait for READ events only. Flags can be "or"-ed but filters should not.

So this patch tries to create two events and this problem is solved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant