puma 5.0.0-java → 5.1.0-java

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of puma might be problematic. Click here for more details.

Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/History.md +1190 -574
  3. data/README.md +28 -20
  4. data/bin/puma-wild +3 -9
  5. data/docs/compile_options.md +19 -0
  6. data/docs/deployment.md +5 -6
  7. data/docs/fork_worker.md +2 -0
  8. data/docs/jungle/README.md +0 -4
  9. data/docs/jungle/rc.d/puma +2 -2
  10. data/docs/nginx.md +1 -1
  11. data/docs/restart.md +46 -23
  12. data/docs/systemd.md +25 -3
  13. data/ext/puma_http11/ext_help.h +1 -1
  14. data/ext/puma_http11/extconf.rb +4 -5
  15. data/ext/puma_http11/http11_parser.c +64 -64
  16. data/ext/puma_http11/mini_ssl.c +39 -37
  17. data/ext/puma_http11/puma_http11.c +25 -12
  18. data/lib/puma.rb +7 -4
  19. data/lib/puma/app/status.rb +44 -46
  20. data/lib/puma/binder.rb +48 -1
  21. data/lib/puma/cli.rb +4 -0
  22. data/lib/puma/client.rb +31 -80
  23. data/lib/puma/cluster.rb +39 -202
  24. data/lib/puma/cluster/worker.rb +176 -0
  25. data/lib/puma/cluster/worker_handle.rb +86 -0
  26. data/lib/puma/configuration.rb +20 -8
  27. data/lib/puma/const.rb +11 -3
  28. data/lib/puma/control_cli.rb +71 -70
  29. data/lib/puma/dsl.rb +67 -19
  30. data/lib/puma/error_logger.rb +2 -2
  31. data/lib/puma/events.rb +21 -3
  32. data/lib/puma/json.rb +96 -0
  33. data/lib/puma/launcher.rb +61 -12
  34. data/lib/puma/minissl.rb +8 -0
  35. data/lib/puma/puma_http11.jar +0 -0
  36. data/lib/puma/queue_close.rb +26 -0
  37. data/lib/puma/reactor.rb +79 -373
  38. data/lib/puma/request.rb +451 -0
  39. data/lib/puma/runner.rb +15 -21
  40. data/lib/puma/server.rb +193 -508
  41. data/lib/puma/single.rb +3 -2
  42. data/lib/puma/state_file.rb +5 -3
  43. data/lib/puma/systemd.rb +46 -0
  44. data/lib/puma/thread_pool.rb +22 -2
  45. data/lib/puma/util.rb +12 -0
  46. metadata +9 -6
  47. data/docs/jungle/upstart/README.md +0 -61
  48. data/docs/jungle/upstart/puma-manager.conf +0 -31
  49. data/docs/jungle/upstart/puma.conf +0 -69
  50. data/lib/puma/accept_nonblock.rb +0 -29
@@ -13,6 +13,7 @@ module Puma
13
13
  # gets created via the `start_server` method from the `Puma::Runner` class
14
14
  # that this inherits from.
15
15
  class Single < Runner
16
+ # @!attribute [r] stats
16
17
  def stats
17
18
  {
18
19
  started_at: @started_at.utc.iso8601
@@ -49,7 +50,7 @@ module Puma
49
50
  start_control
50
51
 
51
52
  @server = server = start_server
52
-
53
+ server_thread = server.run
53
54
 
54
55
  log "Use Ctrl-C to stop"
55
56
  redirect_io
@@ -57,7 +58,7 @@ module Puma
57
58
  @launcher.events.fire_on_booted!
58
59
 
59
60
  begin
60
- server.run.join
61
+ server_thread.join
61
62
  rescue Interrupt
62
63
  # Swallow it
63
64
  end
@@ -9,9 +9,11 @@ module Puma
9
9
  end
10
10
 
11
11
  def save(path, permission = nil)
12
- File.open(path, "w") do |file|
13
- file.chmod(permission) if permission
14
- file.write(YAML.dump(@options))
12
+ contents =YAML.dump @options
13
+ if permission
14
+ File.write path, contents, mode: 'wb:UTF-8'
15
+ else
16
+ File.write path, contents, mode: 'wb:UTF-8', perm: permission
15
17
  end
16
18
  end
17
19
 
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'sd_notify'
4
+
5
+ module Puma
6
+ class Systemd
7
+ def initialize(events)
8
+ @events = events
9
+ end
10
+
11
+ def hook_events
12
+ @events.on_booted { SdNotify.ready }
13
+ @events.on_stopped { SdNotify.stopping }
14
+ @events.on_restart { SdNotify.reloading }
15
+ end
16
+
17
+ def start_watchdog
18
+ return unless SdNotify.watchdog?
19
+
20
+ ping_f = watchdog_sleep_time
21
+
22
+ log "Pinging systemd watchdog every #{ping_f.round(1)} sec"
23
+ Thread.new do
24
+ loop do
25
+ sleep ping_f
26
+ SdNotify.watchdog
27
+ end
28
+ end
29
+ end
30
+
31
+ private
32
+
33
+ def watchdog_sleep_time
34
+ usec = Integer(ENV["WATCHDOG_USEC"])
35
+
36
+ sec_f = usec / 1_000_000.0
37
+ # "It is recommended that a daemon sends a keep-alive notification message
38
+ # to the service manager every half of the time returned here."
39
+ sec_f / 2
40
+ end
41
+
42
+ def log(str)
43
+ @events.log str
44
+ end
45
+ end
46
+ end
@@ -62,6 +62,8 @@ module Puma
62
62
  end
63
63
 
64
64
  @clean_thread_locals = false
65
+ @force_shutdown = false
66
+ @shutdown_mutex = Mutex.new
65
67
  end
66
68
 
67
69
  attr_reader :spawned, :trim_requested, :waiting
@@ -80,10 +82,12 @@ module Puma
80
82
  with_mutex { @todo.size }
81
83
  end
82
84
 
85
+ # @!attribute [r] pool_capacity
83
86
  def pool_capacity
84
87
  waiting + (@max - spawned)
85
88
  end
86
89
 
90
+ # @!attribute [r] busy_threads
87
91
  # @version 5.0.0
88
92
  def busy_threads
89
93
  with_mutex { @spawned - @waiting + @todo.size }
@@ -322,6 +326,19 @@ module Puma
322
326
  @reaper.start!
323
327
  end
324
328
 
329
+ # Allows ThreadPool::ForceShutdown to be raised within the
330
+ # provided block if the thread is forced to shutdown during execution.
331
+ def with_force_shutdown
332
+ t = Thread.current
333
+ @shutdown_mutex.synchronize do
334
+ raise ForceShutdown if @force_shutdown
335
+ t[:with_force_shutdown] = true
336
+ end
337
+ yield
338
+ ensure
339
+ t[:with_force_shutdown] = false
340
+ end
341
+
325
342
  # Tell all threads in the pool to exit and wait for them to finish.
326
343
  # Wait +timeout+ seconds then raise +ForceShutdown+ in remaining threads.
327
344
  # Next, wait an extra +grace+ seconds then force-kill remaining threads.
@@ -356,8 +373,11 @@ module Puma
356
373
  join.call(timeout)
357
374
 
358
375
  # If threads are still running, raise ForceShutdown and wait to finish.
359
- threads.each do |t|
360
- t.raise ForceShutdown
376
+ @shutdown_mutex.synchronize do
377
+ @force_shutdown = true
378
+ threads.each do |t|
379
+ t.raise ForceShutdown if t[:with_force_shutdown]
380
+ end
361
381
  end
362
382
  join.call(SHUTDOWN_GRACE_TIME)
363
383
 
@@ -23,6 +23,17 @@ module Puma
23
23
  end
24
24
  module_function :unescape
25
25
 
26
+ # @version 5.0.0
27
+ def nakayoshi_gc(events)
28
+ events.log "! Promoting existing objects to old generation..."
29
+ 4.times { GC.start(full_mark: false) }
30
+ if GC.respond_to?(:compact)
31
+ events.log "! Compacting..."
32
+ GC.compact
33
+ end
34
+ events.log "! Friendly fork preparation complete."
35
+ end
36
+
26
37
  DEFAULT_SEP = /[&;] */n
27
38
 
28
39
  # Stolen from Mongrel, with some small modifications:
@@ -72,6 +83,7 @@ module Puma
72
83
  end
73
84
  end
74
85
 
86
+ # @!attribute [r] to_hash
75
87
  def to_hash
76
88
  hash = {}
77
89
  each { |k,v| hash[k] = v }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puma
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.0.0
4
+ version: 5.1.0
5
5
  platform: java
6
6
  authors:
7
7
  - Evan Phoenix
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-09-17 00:00:00.000000000 Z
11
+ date: 2020-11-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -43,6 +43,7 @@ files:
43
43
  - bin/puma-wild
44
44
  - bin/pumactl
45
45
  - docs/architecture.md
46
+ - docs/compile_options.md
46
47
  - docs/deployment.md
47
48
  - docs/fork_worker.md
48
49
  - docs/images/puma-connection-flow-no-reactor.png
@@ -52,9 +53,6 @@ files:
52
53
  - docs/jungle/rc.d/README.md
53
54
  - docs/jungle/rc.d/puma
54
55
  - docs/jungle/rc.d/puma.conf
55
- - docs/jungle/upstart/README.md
56
- - docs/jungle/upstart/puma-manager.conf
57
- - docs/jungle/upstart/puma.conf
58
56
  - docs/nginx.md
59
57
  - docs/plugins.md
60
58
  - docs/restart.md
@@ -75,12 +73,13 @@ files:
75
73
  - ext/puma_http11/org/jruby/puma/MiniSSL.java
76
74
  - ext/puma_http11/puma_http11.c
77
75
  - lib/puma.rb
78
- - lib/puma/accept_nonblock.rb
79
76
  - lib/puma/app/status.rb
80
77
  - lib/puma/binder.rb
81
78
  - lib/puma/cli.rb
82
79
  - lib/puma/client.rb
83
80
  - lib/puma/cluster.rb
81
+ - lib/puma/cluster/worker.rb
82
+ - lib/puma/cluster/worker_handle.rb
84
83
  - lib/puma/commonlogger.rb
85
84
  - lib/puma/configuration.rb
86
85
  - lib/puma/const.rb
@@ -91,6 +90,7 @@ files:
91
90
  - lib/puma/events.rb
92
91
  - lib/puma/io_buffer.rb
93
92
  - lib/puma/jruby_restart.rb
93
+ - lib/puma/json.rb
94
94
  - lib/puma/launcher.rb
95
95
  - lib/puma/minissl.rb
96
96
  - lib/puma/minissl/context_builder.rb
@@ -98,14 +98,17 @@ files:
98
98
  - lib/puma/plugin.rb
99
99
  - lib/puma/plugin/tmp_restart.rb
100
100
  - lib/puma/puma_http11.jar
101
+ - lib/puma/queue_close.rb
101
102
  - lib/puma/rack/builder.rb
102
103
  - lib/puma/rack/urlmap.rb
103
104
  - lib/puma/rack_default.rb
104
105
  - lib/puma/reactor.rb
106
+ - lib/puma/request.rb
105
107
  - lib/puma/runner.rb
106
108
  - lib/puma/server.rb
107
109
  - lib/puma/single.rb
108
110
  - lib/puma/state_file.rb
111
+ - lib/puma/systemd.rb
109
112
  - lib/puma/thread_pool.rb
110
113
  - lib/puma/util.rb
111
114
  - lib/rack/handler/puma.rb
@@ -1,61 +0,0 @@
1
- # Puma as a service using Upstart
2
-
3
- Manage multiple Puma servers as services on the same box using Ubuntu upstart.
4
-
5
- ## Installation
6
-
7
- # Copy the scripts to services directory
8
- sudo cp puma.conf puma-manager.conf /etc/init
9
-
10
- # Create an empty configuration file
11
- sudo touch /etc/puma.conf
12
-
13
- ## Managing the jungle
14
-
15
- Puma apps are referenced in /etc/puma.conf by default. Add each app's path as a new line, e.g.:
16
-
17
- ```
18
- /home/apps/my-cool-ruby-app
19
- /home/apps/another-app/current
20
- ```
21
-
22
- Start the jungle running:
23
-
24
- `sudo start puma-manager`
25
-
26
- This script will run at boot time.
27
-
28
- Start a single puma like this:
29
-
30
- `sudo start puma app=/path/to/app`
31
-
32
- ## Logs
33
-
34
- Everything is logged by upstart, defaulting to `/var/log/upstart`.
35
-
36
- Each puma instance is named after its directory, so for an app called `/home/apps/my-app` the log file would be `/var/log/upstart/puma-_home_apps_my-app.log`.
37
-
38
- ## Conventions
39
-
40
- * The script expects:
41
- * a config file to exist under `config/puma.rb` in your app. E.g.: `/home/apps/my-app/config/puma.rb`.
42
- * a temporary folder to put the PID, socket and state files to exist called `tmp/puma`. E.g.: `/home/apps/my-app/tmp/puma`. Puma will take care of the files for you.
43
-
44
- You can always change those defaults by editing the scripts.
45
-
46
- ## Here's what a minimal app's config file should have
47
-
48
- ```
49
- pidfile "/path/to/app/tmp/puma/pid"
50
- state_path "/path/to/app/tmp/puma/state"
51
- activate_control_app
52
- ```
53
-
54
- ## Before starting...
55
-
56
- You need to customise `puma.conf` to:
57
-
58
- * Set the right user your app should be running on unless you want root to execute it!
59
- * Look for `setuid apps` and `setgid apps`, uncomment those lines and replace `apps` to whatever your deployment user is.
60
- * Replace `apps` on the paths (or set the right paths to your user's home) everywhere else.
61
- * Uncomment the source lines for `rbenv` or `rvm` support unless you use a system wide installation of Ruby.
@@ -1,31 +0,0 @@
1
- # /etc/init/puma-manager.conf - manage a set of Pumas
2
-
3
- # This example config should work with Ubuntu 12.04+. It
4
- # allows you to manage multiple Puma instances with
5
- # Upstart, Ubuntu's native service management tool.
6
- #
7
- # See puma.conf for how to manage a single Puma instance.
8
- #
9
- # Use "stop puma-manager" to stop all Puma instances.
10
- # Use "start puma-manager" to start all instances.
11
- # Use "restart puma-manager" to restart all instances.
12
- # Crazy, right?
13
- #
14
-
15
- description "Manages the set of puma processes"
16
-
17
- # This starts upon bootup and stops on shutdown
18
- start on runlevel [2345]
19
- stop on runlevel [06]
20
-
21
- # Set this to the number of Puma processes you want
22
- # to run on this machine
23
- env PUMA_CONF="/etc/puma.conf"
24
-
25
- pre-start script
26
- for i in `cat $PUMA_CONF`; do
27
- app=`echo $i | cut -d , -f 1`
28
- logger -t "puma-manager" "Starting $app"
29
- start puma app=$app
30
- done
31
- end script
@@ -1,69 +0,0 @@
1
- # /etc/init/puma.conf - Puma config
2
-
3
- # This example config should work with Ubuntu 12.04+. It
4
- # allows you to manage multiple Puma instances with
5
- # Upstart, Ubuntu's native service management tool.
6
- #
7
- # See puma-manager.conf for how to manage all Puma instances at once.
8
- #
9
- # Save this config as /etc/init/puma.conf then manage puma with:
10
- # sudo start puma app=PATH_TO_APP
11
- # sudo stop puma app=PATH_TO_APP
12
- # sudo status puma app=PATH_TO_APP
13
- #
14
- # or use the service command:
15
- # sudo service puma {start,stop,restart,status}
16
- #
17
-
18
- description "Puma Background Worker"
19
-
20
- # no "start on", we don't want to automatically start
21
- stop on (stopping puma-manager or runlevel [06])
22
-
23
- # change apps to match your deployment user if you want to use this as a less privileged user (recommended!)
24
- setuid apps
25
- setgid apps
26
-
27
- respawn
28
- respawn limit 3 30
29
-
30
- instance ${app}
31
-
32
- script
33
- # this script runs in /bin/sh by default
34
- # respawn as bash so we can source in rbenv/rvm
35
- # quoted heredoc to tell /bin/sh not to interpret
36
- # variables
37
-
38
- # source ENV variables manually as Upstart doesn't, eg:
39
- #. /etc/environment
40
-
41
- exec /bin/bash <<'EOT'
42
- # set HOME to the setuid user's home, there doesn't seem to be a better, portable way
43
- export HOME="$(eval echo ~$(id -un))"
44
-
45
- if [ -d "/usr/local/rbenv/bin" ]; then
46
- export PATH="/usr/local/rbenv/bin:/usr/local/rbenv/shims:$PATH"
47
- elif [ -d "$HOME/.rbenv/bin" ]; then
48
- export PATH="$HOME/.rbenv/bin:$HOME/.rbenv/shims:$PATH"
49
- elif [ -f /etc/profile.d/rvm.sh ]; then
50
- source /etc/profile.d/rvm.sh
51
- elif [ -f /usr/local/rvm/scripts/rvm ]; then
52
- source /etc/profile.d/rvm.sh
53
- elif [ -f "$HOME/.rvm/scripts/rvm" ]; then
54
- source "$HOME/.rvm/scripts/rvm"
55
- elif [ -f /usr/local/share/chruby/chruby.sh ]; then
56
- source /usr/local/share/chruby/chruby.sh
57
- if [ -f /usr/local/share/chruby/auto.sh ]; then
58
- source /usr/local/share/chruby/auto.sh
59
- fi
60
- # if you aren't using auto, set your version here
61
- # chruby 2.0.0
62
- fi
63
-
64
- cd $app
65
- logger -t puma "Starting server: $app"
66
-
67
- exec bundle exec puma -C config/puma.rb
68
- EOT
69
- end script
@@ -1,29 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'openssl'
4
-
5
- module OpenSSL
6
- module SSL
7
- class SSLServer
8
- unless public_method_defined? :accept_nonblock
9
- def accept_nonblock
10
- sock = @svr.accept_nonblock
11
-
12
- begin
13
- ssl = OpenSSL::SSL::SSLSocket.new(sock, @ctx)
14
- ssl.sync_close = true
15
- ssl.accept if @start_immediately
16
- ssl
17
- rescue SSLError => ex
18
- if ssl
19
- ssl.close
20
- else
21
- sock.close
22
- end
23
- raise ex
24
- end
25
- end
26
- end
27
- end
28
- end
29
- end