Last active
August 28, 2015 23:50
-
-
Save felixbuenemann/ea29903e18e328cd9e8b to your computer and use it in GitHub Desktop.
Testcase to reproduce kqueue crash with thin on eventmachine 1.0.8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage
On a recent Mac OS X system (tested on 10.11 (15A263e) / ruby 2.2.3p173 x86_64) run:
It should crash with an error (might require a couple of tries, just rerun ab):