Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save felixbuenemann/ea29903e18e328cd9e8b to your computer and use it in GitHub Desktop.
Save felixbuenemann/ea29903e18e328cd9e8b to your computer and use it in GitHub Desktop.
Testcase to reproduce kqueue crash with thin on eventmachine 1.0.8
#!/usr/bin/env ruby
begin
require 'bundler/inline'
rescue LoadError => e
$stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler'
raise e
end
gemfile(true) do
source 'https://rubygems.org'
gem "eventmachine", "1.0.8"
gem "thin", "1.6.3"
end
EM.kqueue
class DeferrableBody
include EventMachine::Deferrable
def call(body)
body.each do |chunk|
@body_callback.call(chunk)
end
end
def each &blk
@body_callback = blk
end
end
class AsyncApp
AsyncResponse = [-1, {}, []].freeze
def call(env)
body = DeferrableBody.new
EventMachine::next_tick { env['async.callback'].call [200, {'Content-Type' => 'text/plain'}, body] }
EventMachine::add_timer(1) {
body.call ["Woah, async!\n"]
EventMachine::next_tick {
body.call ["Cheers then!"]
body.succeed
}
}
AsyncResponse
end
end
Thin::Server.start('127.0.0.1', 3000, AsyncApp.new)
@felixbuenemann
Copy link
Author

Usage

On a recent Mac OS X system (tested on 10.11 (15A263e) / ruby 2.2.3p173 x86_64) run:

# start a thin server on port 3000
ruby em-108-arm-kqueue-writer-failed-testcase.rb
# hit it hard with apache bench from another terminal
ab -r -c 150 -n 15000 http://127.0.0.1:3000/

It should crash with an error (might require a couple of tries, just rerun ab):

libc++abi.dylib: terminating with uncaught exception of type std::runtime_error: arm kqueue writer failed on 32681: Bad file descriptor

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