unicorn 4.7.0 → 6.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (119) hide show
  1. checksums.yaml +7 -0
  2. data/.document +0 -1
  3. data/.gitattributes +5 -0
  4. data/.gitignore +2 -2
  5. data/.manifest +14 -21
  6. data/.olddoc.yml +22 -0
  7. data/Application_Timeouts +7 -7
  8. data/DESIGN +2 -4
  9. data/Documentation/.gitignore +1 -3
  10. data/Documentation/unicorn.1 +222 -0
  11. data/Documentation/unicorn_rails.1 +207 -0
  12. data/FAQ +23 -6
  13. data/GIT-VERSION-FILE +1 -1
  14. data/GIT-VERSION-GEN +1 -1
  15. data/GNUmakefile +139 -92
  16. data/HACKING +13 -28
  17. data/ISSUES +82 -19
  18. data/KNOWN_ISSUES +18 -18
  19. data/LATEST +22 -44
  20. data/LICENSE +2 -2
  21. data/Links +24 -22
  22. data/NEWS +729 -0
  23. data/PHILOSOPHY +0 -6
  24. data/README +50 -48
  25. data/Rakefile +0 -44
  26. data/SIGNALS +12 -3
  27. data/Sandbox +11 -10
  28. data/TODO +0 -2
  29. data/TUNING +30 -9
  30. data/archive/.gitignore +3 -0
  31. data/archive/slrnpull.conf +4 -0
  32. data/bin/unicorn +4 -2
  33. data/bin/unicorn_rails +3 -3
  34. data/examples/big_app_gc.rb +1 -1
  35. data/examples/init.sh +36 -8
  36. data/examples/logrotate.conf +17 -2
  37. data/examples/nginx.conf +14 -14
  38. data/examples/unicorn.conf.minimal.rb +2 -2
  39. data/examples/unicorn.conf.rb +14 -6
  40. data/examples/unicorn.socket +11 -0
  41. data/examples/unicorn@.service +40 -0
  42. data/ext/unicorn_http/common_field_optimization.h +23 -5
  43. data/ext/unicorn_http/ext_help.h +0 -20
  44. data/ext/unicorn_http/extconf.rb +37 -1
  45. data/ext/unicorn_http/global_variables.h +1 -1
  46. data/ext/unicorn_http/httpdate.c +2 -2
  47. data/ext/unicorn_http/unicorn_http.c +940 -644
  48. data/ext/unicorn_http/unicorn_http.rl +167 -170
  49. data/ext/unicorn_http/unicorn_http_common.rl +1 -1
  50. data/lib/unicorn/configurator.rb +110 -46
  51. data/lib/unicorn/const.rb +2 -25
  52. data/lib/unicorn/http_request.rb +110 -31
  53. data/lib/unicorn/http_response.rb +17 -31
  54. data/lib/unicorn/http_server.rb +292 -199
  55. data/lib/unicorn/launcher.rb +1 -1
  56. data/lib/unicorn/oob_gc.rb +16 -6
  57. data/lib/unicorn/socket_helper.rb +58 -78
  58. data/lib/unicorn/stream_input.rb +9 -11
  59. data/lib/unicorn/tee_input.rb +16 -11
  60. data/lib/unicorn/tmpio.rb +10 -6
  61. data/lib/unicorn/util.rb +5 -4
  62. data/lib/unicorn/version.rb +1 -1
  63. data/lib/unicorn/worker.rb +99 -22
  64. data/lib/unicorn.rb +69 -42
  65. data/man/man1/unicorn.1 +124 -122
  66. data/man/man1/unicorn_rails.1 +113 -127
  67. data/t/.gitignore +0 -1
  68. data/t/GNUmakefile +3 -80
  69. data/t/README +4 -4
  70. data/t/t0002-parser-error.sh +3 -3
  71. data/t/t0011-active-unix-socket.sh +1 -1
  72. data/t/t0012-reload-empty-config.sh +2 -1
  73. data/t/t0300-no-default-middleware.sh +6 -1
  74. data/t/t0301-no-default-middleware-ignored-in-config.sh +25 -0
  75. data/t/t0301.ru +13 -0
  76. data/t/test-lib.sh +2 -2
  77. data/test/benchmark/README +14 -4
  78. data/test/benchmark/ddstream.ru +50 -0
  79. data/test/benchmark/readinput.ru +40 -0
  80. data/test/benchmark/uconnect.perl +66 -0
  81. data/test/exec/test_exec.rb +74 -20
  82. data/test/test_helper.rb +42 -33
  83. data/test/unit/test_ccc.rb +91 -0
  84. data/test/unit/test_droplet.rb +1 -1
  85. data/test/unit/test_http_parser.rb +49 -19
  86. data/test/unit/test_http_parser_ng.rb +98 -115
  87. data/test/unit/test_request.rb +11 -11
  88. data/test/unit/test_response.rb +31 -19
  89. data/test/unit/test_server.rb +89 -15
  90. data/test/unit/test_signals.rb +9 -9
  91. data/test/unit/test_socket_helper.rb +20 -14
  92. data/test/unit/test_tee_input.rb +10 -0
  93. data/test/unit/test_upload.rb +10 -15
  94. data/test/unit/test_util.rb +28 -3
  95. data/unicorn.gemspec +28 -23
  96. data/unicorn_1 +1 -0
  97. data/unicorn_rails_1 +1 -0
  98. metadata +64 -134
  99. data/.wrongdoc.yml +0 -10
  100. data/ChangeLog +0 -4694
  101. data/Documentation/GNUmakefile +0 -30
  102. data/Documentation/unicorn.1.txt +0 -178
  103. data/Documentation/unicorn_rails.1.txt +0 -175
  104. data/examples/git.ru +0 -13
  105. data/lib/unicorn/app/exec_cgi.rb +0 -154
  106. data/lib/unicorn/app/inetd.rb +0 -109
  107. data/lib/unicorn/ssl_client.rb +0 -11
  108. data/lib/unicorn/ssl_configurator.rb +0 -104
  109. data/lib/unicorn/ssl_server.rb +0 -42
  110. data/local.mk.sample +0 -59
  111. data/script/isolate_for_tests +0 -32
  112. data/t/hijack.ru +0 -42
  113. data/t/sslgen.sh +0 -71
  114. data/t/t0016-trust-x-forwarded-false.sh +0 -30
  115. data/t/t0017-trust-x-forwarded-true.sh +0 -30
  116. data/t/t0200-rack-hijack.sh +0 -27
  117. data/t/t0600-https-server-basic.sh +0 -48
  118. data/test/unit/test_http_parser_xftrust.rb +0 -38
  119. data/test/unit/test_sni_hostnames.rb +0 -47
@@ -1,6 +1,6 @@
1
1
  # -*- encoding: binary -*-
2
2
 
3
- require 'test/test_helper'
3
+ require './test/test_helper'
4
4
  require 'tempfile'
5
5
 
6
6
  class TestSocketHelper < Test::Unit::TestCase
@@ -57,8 +57,8 @@ class TestSocketHelper < Test::Unit::TestCase
57
57
  assert File.readable?(@unix_listener_path), "not readable"
58
58
  assert File.writable?(@unix_listener_path), "not writable"
59
59
  assert_equal 0777, File.umask
60
- ensure
61
- File.umask(old_umask)
60
+ ensure
61
+ File.umask(old_umask)
62
62
  end
63
63
 
64
64
  def test_bind_listen_unix_umask
@@ -71,8 +71,8 @@ class TestSocketHelper < Test::Unit::TestCase
71
71
  assert_equal @unix_listener_path, sock_name(@unix_listener)
72
72
  assert_equal 0140700, File.stat(@unix_listener_path).mode
73
73
  assert_equal 0777, File.umask
74
- ensure
75
- File.umask(old_umask)
74
+ ensure
75
+ File.umask(old_umask)
76
76
  end
77
77
 
78
78
  def test_bind_listen_unix_idempotent
@@ -116,7 +116,7 @@ class TestSocketHelper < Test::Unit::TestCase
116
116
  client.syswrite('abcde')
117
117
  exit 0
118
118
  end
119
- s = UNIXSocket.new(@unix_listener_path)
119
+ s = unix_socket(@unix_listener_path)
120
120
  IO.select([s])
121
121
  assert_equal 'abcde', s.sysread(5)
122
122
  pid, status = Process.waitpid2(pid)
@@ -150,28 +150,31 @@ class TestSocketHelper < Test::Unit::TestCase
150
150
  end
151
151
 
152
152
  def test_tcp_defer_accept_default
153
+ return unless defined?(TCP_DEFER_ACCEPT)
153
154
  port = unused_port @test_addr
154
155
  name = "#@test_addr:#{port}"
155
156
  sock = bind_listen(name)
156
157
  cur = sock.getsockopt(Socket::SOL_TCP, TCP_DEFER_ACCEPT).unpack('i')[0]
157
158
  assert cur >= 1
158
- end if defined?(TCP_DEFER_ACCEPT)
159
+ end
159
160
 
160
161
  def test_tcp_defer_accept_disable
162
+ return unless defined?(TCP_DEFER_ACCEPT)
161
163
  port = unused_port @test_addr
162
164
  name = "#@test_addr:#{port}"
163
165
  sock = bind_listen(name, :tcp_defer_accept => false)
164
166
  cur = sock.getsockopt(Socket::SOL_TCP, TCP_DEFER_ACCEPT).unpack('i')[0]
165
167
  assert_equal 0, cur
166
- end if defined?(TCP_DEFER_ACCEPT)
168
+ end
167
169
 
168
170
  def test_tcp_defer_accept_nr
171
+ return unless defined?(TCP_DEFER_ACCEPT)
169
172
  port = unused_port @test_addr
170
173
  name = "#@test_addr:#{port}"
171
174
  sock = bind_listen(name, :tcp_defer_accept => 60)
172
175
  cur = sock.getsockopt(Socket::SOL_TCP, TCP_DEFER_ACCEPT).unpack('i')[0]
173
176
  assert cur > 1
174
- end if defined?(TCP_DEFER_ACCEPT)
177
+ end
175
178
 
176
179
  def test_ipv6only
177
180
  port = begin
@@ -182,14 +185,17 @@ class TestSocketHelper < Test::Unit::TestCase
182
185
  sock = bind_listen "[#@test6_addr]:#{port}", :ipv6only => true
183
186
  cur = sock.getsockopt(:IPPROTO_IPV6, :IPV6_V6ONLY).unpack('i')[0]
184
187
  assert_equal 1, cur
185
- rescue Errno::EAFNOSUPPORT
186
- end if RUBY_VERSION >= "1.9.2"
188
+ rescue Errno::EAFNOSUPPORT
189
+ end
187
190
 
188
191
  def test_reuseport
192
+ return unless defined?(Socket::SO_REUSEPORT)
189
193
  port = unused_port @test_addr
190
194
  name = "#@test_addr:#{port}"
191
195
  sock = bind_listen(name, :reuseport => true)
192
- cur = sock.getsockopt(Socket::SOL_SOCKET, SO_REUSEPORT).unpack('i')[0]
193
- assert_equal 1, cur
194
- end if defined?(SO_REUSEPORT)
196
+ cur = sock.getsockopt(:SOL_SOCKET, :SO_REUSEPORT).int
197
+ assert_operator cur, :>, 0
198
+ rescue Errno::ENOPROTOOPT
199
+ # kernel does not support SO_REUSEPORT (older Linux)
200
+ end
195
201
  end
@@ -29,6 +29,13 @@ class TestTeeInput < Test::Unit::TestCase
29
29
  end while true
30
30
  end
31
31
 
32
+ def check_tempfiles
33
+ tmp = @parser.env["rack.tempfiles"]
34
+ assert_instance_of Array, tmp
35
+ assert_operator tmp.size, :>=, 1
36
+ assert_instance_of Unicorn::TmpIO, tmp[0]
37
+ end
38
+
32
39
  def test_gets_long
33
40
  r = init_request("hello", 5 + (4096 * 4 * 3) + "#$/foo#$/".size)
34
41
  ti = TeeInput.new(@rd, r)
@@ -106,6 +113,7 @@ class TestTeeInput < Test::Unit::TestCase
106
113
  assert_kind_of File, ti.tmp
107
114
  assert_equal 0, ti.tmp.pos
108
115
  assert_equal Unicorn::Const::MAX_BODY + 1, ti.size
116
+ check_tempfiles
109
117
  end
110
118
 
111
119
  def test_read_in_full_if_content_length
@@ -148,6 +156,7 @@ class TestTeeInput < Test::Unit::TestCase
148
156
  assert_nil ti.read(1)
149
157
  pid, status = Process.waitpid2(pid)
150
158
  assert status.success?
159
+ check_tempfiles
151
160
  end
152
161
 
153
162
  def test_chunked
@@ -183,6 +192,7 @@ class TestTeeInput < Test::Unit::TestCase
183
192
  status = nil
184
193
  pid, status = Process.waitpid2(pid)
185
194
  assert status.success?
195
+ check_tempfiles
186
196
  end
187
197
 
188
198
  def test_chunked_ping_pong
@@ -1,7 +1,7 @@
1
1
  # -*- encoding: binary -*-
2
2
 
3
3
  # Copyright (c) 2009 Eric Wong
4
- require 'test/test_helper'
4
+ require './test/test_helper'
5
5
  require 'digest/md5'
6
6
 
7
7
  include Unicorn
@@ -60,7 +60,7 @@ class UploadTest < Test::Unit::TestCase
60
60
 
61
61
  def test_put
62
62
  start_server(@sha1_app)
63
- sock = TCPSocket.new(@addr, @port)
63
+ sock = tcp_socket(@addr, @port)
64
64
  sock.syswrite("PUT / HTTP/1.0\r\nContent-Length: #{length}\r\n\r\n")
65
65
  @count.times do |i|
66
66
  buf = @random.sysread(@bs)
@@ -77,7 +77,7 @@ class UploadTest < Test::Unit::TestCase
77
77
  def test_put_content_md5
78
78
  md5 = Digest::MD5.new
79
79
  start_server(@sha1_app)
80
- sock = TCPSocket.new(@addr, @port)
80
+ sock = tcp_socket(@addr, @port)
81
81
  sock.syswrite("PUT / HTTP/1.0\r\nTransfer-Encoding: chunked\r\n" \
82
82
  "Trailer: Content-MD5\r\n\r\n")
83
83
  @count.times do |i|
@@ -103,7 +103,7 @@ class UploadTest < Test::Unit::TestCase
103
103
  @count, @bs = 2, 128
104
104
  start_server(@sha1_app)
105
105
  assert_equal 256, length
106
- sock = TCPSocket.new(@addr, @port)
106
+ sock = tcp_socket(@addr, @port)
107
107
  hdr = "PUT / HTTP/1.0\r\nContent-Length: #{length}\r\n\r\n"
108
108
  @count.times do
109
109
  buf = @random.sysread(@bs)
@@ -122,7 +122,7 @@ class UploadTest < Test::Unit::TestCase
122
122
 
123
123
  def test_put_keepalive_truncates_small_overwrite
124
124
  start_server(@sha1_app)
125
- sock = TCPSocket.new(@addr, @port)
125
+ sock = tcp_socket(@addr, @port)
126
126
  to_upload = length + 1
127
127
  sock.syswrite("PUT / HTTP/1.0\r\nContent-Length: #{to_upload}\r\n\r\n")
128
128
  @count.times do
@@ -155,7 +155,7 @@ class UploadTest < Test::Unit::TestCase
155
155
  tmp.write(nr.to_s)
156
156
  [ 200, @hdr, [] ]
157
157
  })
158
- sock = TCPSocket.new(@addr, @port)
158
+ sock = tcp_socket(@addr, @port)
159
159
  buf = ' ' * @bs
160
160
  sock.syswrite("PUT / HTTP/1.0\r\nContent-Length: #{length}\r\n\r\n")
161
161
 
@@ -236,15 +236,10 @@ class UploadTest < Test::Unit::TestCase
236
236
  resp = Tempfile.new('resp')
237
237
  resp.sync = true
238
238
 
239
- rd, wr = IO.pipe
240
- wr.sync = rd.sync = true
241
- pid = fork {
242
- STDIN.reopen(rd)
243
- rd.close
244
- wr.close
245
- STDOUT.reopen(resp)
246
- exec cmd
247
- }
239
+ rd, wr = IO.pipe.each do |io|
240
+ io.sync = io.close_on_exec = true
241
+ end
242
+ pid = spawn(*cmd, { 0 => rd, 1 => resp })
248
243
  rd.close
249
244
 
250
245
  tmp.rewind
@@ -1,6 +1,6 @@
1
1
  # -*- encoding: binary -*-
2
2
 
3
- require 'test/test_helper'
3
+ require './test/test_helper'
4
4
  require 'tempfile'
5
5
 
6
6
  class TestUtil < Test::Unit::TestCase
@@ -69,7 +69,7 @@ class TestUtil < Test::Unit::TestCase
69
69
  }
70
70
  }
71
71
  tmp.close!
72
- end if STDIN.respond_to?(:external_encoding)
72
+ end
73
73
 
74
74
  def test_reopen_logs_renamed_with_internal_encoding
75
75
  tmp = Tempfile.new('')
@@ -101,5 +101,30 @@ class TestUtil < Test::Unit::TestCase
101
101
  }
102
102
  }
103
103
  tmp.close!
104
- end if STDIN.respond_to?(:external_encoding)
104
+ end
105
+
106
+ def test_pipe
107
+ r, w = Unicorn.pipe
108
+ assert r
109
+ assert w
110
+
111
+ return if RUBY_PLATFORM !~ /linux/
112
+
113
+ begin
114
+ f_getpipe_sz = 1032
115
+ IO.pipe do |a, b|
116
+ a_sz = a.fcntl(f_getpipe_sz)
117
+ b.fcntl(f_getpipe_sz)
118
+ assert_kind_of Integer, a_sz
119
+ r_sz = r.fcntl(f_getpipe_sz)
120
+ assert_equal Raindrops::PAGE_SIZE, r_sz
121
+ assert_operator a_sz, :>=, r_sz
122
+ end
123
+ rescue Errno::EINVAL
124
+ # Linux <= 2.6.34
125
+ end
126
+ ensure
127
+ w.close
128
+ r.close
129
+ end
105
130
  end
data/unicorn.gemspec CHANGED
@@ -1,9 +1,6 @@
1
1
  # -*- encoding: binary -*-
2
- ENV["VERSION"] or abort "VERSION= must be specified"
3
- manifest = File.readlines('.manifest').map! { |x| x.chomp! }
4
- require 'wrongdoc'
5
- extend Wrongdoc::Gemspec
6
- name, summary, title = readme_metadata
2
+ manifest = File.exist?('.manifest') ?
3
+ IO.readlines('.manifest').map!(&:chomp!) : `git ls-files`.split("\n")
7
4
 
8
5
  # don't bother with tests that fork, not worth our time to get working
9
6
  # with `gem check -t` ... (of course we care for them when testing with
@@ -14,31 +11,39 @@ end.compact
14
11
 
15
12
  Gem::Specification.new do |s|
16
13
  s.name = %q{unicorn}
17
- s.version = ENV["VERSION"].dup
18
- s.authors = ["#{name} hackers"]
19
- s.summary = summary
20
- s.date = Time.now.utc.strftime('%Y-%m-%d')
21
- s.description = readme_description
22
- s.email = %q{mongrel-unicorn@rubyforge.org}
14
+ s.version = (ENV['VERSION'] || '6.0.0').dup
15
+ s.authors = ['unicorn hackers']
16
+ s.summary = 'Rack HTTP server for fast clients and Unix'
17
+ s.description = File.read('README').split("\n\n")[1]
18
+ s.email = %q{unicorn-public@yhbt.net}
23
19
  s.executables = %w(unicorn unicorn_rails)
24
20
  s.extensions = %w(ext/unicorn_http/extconf.rb)
25
- s.extra_rdoc_files = extra_rdoc_files(manifest)
21
+ s.extra_rdoc_files = IO.readlines('.document').map!(&:chomp!).keep_if do |f|
22
+ File.exist?(f)
23
+ end
26
24
  s.files = manifest
27
- s.homepage = Wrongdoc.config[:rdoc_url]
28
- s.rdoc_options = rdoc_options
29
- s.rubyforge_project = %q{mongrel}
25
+ s.homepage = 'https://yhbt.net/unicorn/'
30
26
  s.test_files = test_files
31
27
 
32
- # for people that are absolutely stuck on Rails 2.3.2 and can't
33
- # up/downgrade to any other version, the Rack dependency may be
34
- # commented out. Nevertheless, upgrading to Rails 2.3.4 or later is
35
- # *strongly* recommended for security reasons.
36
- s.add_dependency(%q<rack>)
28
+ # 1.9.3 is the minumum supported version. We don't specify
29
+ # a maximum version to make it easier to test pre-releases,
30
+ # but we do warn users if they install unicorn on an untested
31
+ # version in extconf.rb
32
+ s.required_ruby_version = ">= 1.9.3"
33
+
34
+ # We do not have a hard dependency on rack, it's possible to load
35
+ # things which respond to #call. HTTP status lines in responses
36
+ # won't have descriptive text, only the numeric status.
37
+ s.add_development_dependency(%q<rack>)
38
+
37
39
  s.add_dependency(%q<kgio>, '~> 2.6')
38
40
  s.add_dependency(%q<raindrops>, '~> 0.7')
39
41
 
40
- s.add_development_dependency('isolate', '~> 3.2')
41
- s.add_development_dependency('wrongdoc', '~> 1.6.1')
42
+ s.add_development_dependency('test-unit', '~> 3.0')
42
43
 
43
- s.licenses = ["GPLv2+", "Ruby 1.8"]
44
+ # Note: To avoid ambiguity, we intentionally avoid the SPDX-compatible
45
+ # 'Ruby' here since Ruby 1.9.3 switched to BSD-2-Clause, but we
46
+ # inherited our license from Mongrel when Ruby was at 1.8.
47
+ # We cannot automatically switch licenses when Ruby changes.
48
+ s.licenses = ['GPL-2.0+', 'Ruby-1.8']
44
49
  end
data/unicorn_1 ADDED
@@ -0,0 +1 @@
1
+ olddoc_placeholder
data/unicorn_rails_1 ADDED
@@ -0,0 +1 @@
1
+ olddoc_placeholder