socketry / io-event

MIT License
75 stars 16 forks source link

Bugfix: Fix kqueue event clobbering #20

Closed machty closed 2 years ago

machty commented 2 years ago

Description

Fixes root issue described here:

https://github.com/socketry/async/issues/137

The solution is to set the EV_UDATA_SPECIFIC flag on all kqueue events, which tells kqueue to consider the udata value (the pointer to the fiber) as part of the unique tuple.

Types of Changes

Testing

Test case output

Reprinting the simplified test case from https://github.com/socketry/async/issues/137:

Async do |t|
  puts "Root start"
  t.async do
    puts "Sleep 1 Start"
    sleep 1
    puts "Sleep 1 End"
  end
  t.async do
    puts "Sleep 2 Start"
    sleep 1
    puts "Sleep 2 End"
  end
  puts "Root end"
end

Without this PR, Ruby 3.1.0 prints the following output and hangs:

Root start
Sleep 1 StartSleep 2 Start
Root end
Sleep 2 End

With this PR on Ruby 3.1.0, the following is output (and doesn't hang):

Root start
Sleep 1 StartSleep 2 Start

Root end
Sleep 1 EndSleep 2 End

=> true

I tried this PR against your Ruby PR but the output is the same (it succeeds, doesn't hang).

ioquatix commented 2 years ago

Wow this is amazing, I didn't know this was possible!