ed-precompiled_puma 7.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. checksums.yaml +7 -0
  2. data/History.md +3172 -0
  3. data/LICENSE +29 -0
  4. data/README.md +477 -0
  5. data/bin/puma +10 -0
  6. data/bin/puma-wild +25 -0
  7. data/bin/pumactl +12 -0
  8. data/docs/architecture.md +74 -0
  9. data/docs/compile_options.md +55 -0
  10. data/docs/deployment.md +102 -0
  11. data/docs/fork_worker.md +41 -0
  12. data/docs/images/puma-connection-flow-no-reactor.png +0 -0
  13. data/docs/images/puma-connection-flow.png +0 -0
  14. data/docs/images/puma-general-arch.png +0 -0
  15. data/docs/java_options.md +54 -0
  16. data/docs/jungle/README.md +9 -0
  17. data/docs/jungle/rc.d/README.md +74 -0
  18. data/docs/jungle/rc.d/puma +61 -0
  19. data/docs/jungle/rc.d/puma.conf +10 -0
  20. data/docs/kubernetes.md +80 -0
  21. data/docs/nginx.md +80 -0
  22. data/docs/plugins.md +42 -0
  23. data/docs/rails_dev_mode.md +28 -0
  24. data/docs/restart.md +65 -0
  25. data/docs/signals.md +98 -0
  26. data/docs/stats.md +148 -0
  27. data/docs/systemd.md +253 -0
  28. data/docs/testing_benchmarks_local_files.md +150 -0
  29. data/docs/testing_test_rackup_ci_files.md +36 -0
  30. data/ext/puma_http11/PumaHttp11Service.java +17 -0
  31. data/ext/puma_http11/ext_help.h +15 -0
  32. data/ext/puma_http11/extconf.rb +65 -0
  33. data/ext/puma_http11/http11_parser.c +1057 -0
  34. data/ext/puma_http11/http11_parser.h +65 -0
  35. data/ext/puma_http11/http11_parser.java.rl +145 -0
  36. data/ext/puma_http11/http11_parser.rl +149 -0
  37. data/ext/puma_http11/http11_parser_common.rl +54 -0
  38. data/ext/puma_http11/mini_ssl.c +852 -0
  39. data/ext/puma_http11/no_ssl/PumaHttp11Service.java +15 -0
  40. data/ext/puma_http11/org/jruby/puma/Http11.java +257 -0
  41. data/ext/puma_http11/org/jruby/puma/Http11Parser.java +455 -0
  42. data/ext/puma_http11/org/jruby/puma/MiniSSL.java +509 -0
  43. data/ext/puma_http11/puma_http11.c +507 -0
  44. data/lib/puma/app/status.rb +96 -0
  45. data/lib/puma/binder.rb +511 -0
  46. data/lib/puma/cli.rb +245 -0
  47. data/lib/puma/client.rb +720 -0
  48. data/lib/puma/cluster/worker.rb +182 -0
  49. data/lib/puma/cluster/worker_handle.rb +127 -0
  50. data/lib/puma/cluster.rb +635 -0
  51. data/lib/puma/cluster_accept_loop_delay.rb +91 -0
  52. data/lib/puma/commonlogger.rb +115 -0
  53. data/lib/puma/configuration.rb +452 -0
  54. data/lib/puma/const.rb +307 -0
  55. data/lib/puma/control_cli.rb +320 -0
  56. data/lib/puma/detect.rb +47 -0
  57. data/lib/puma/dsl.rb +1480 -0
  58. data/lib/puma/error_logger.rb +115 -0
  59. data/lib/puma/events.rb +72 -0
  60. data/lib/puma/io_buffer.rb +50 -0
  61. data/lib/puma/jruby_restart.rb +11 -0
  62. data/lib/puma/json_serialization.rb +96 -0
  63. data/lib/puma/launcher/bundle_pruner.rb +104 -0
  64. data/lib/puma/launcher.rb +496 -0
  65. data/lib/puma/log_writer.rb +147 -0
  66. data/lib/puma/minissl/context_builder.rb +96 -0
  67. data/lib/puma/minissl.rb +463 -0
  68. data/lib/puma/null_io.rb +101 -0
  69. data/lib/puma/plugin/systemd.rb +90 -0
  70. data/lib/puma/plugin/tmp_restart.rb +36 -0
  71. data/lib/puma/plugin.rb +111 -0
  72. data/lib/puma/rack/builder.rb +297 -0
  73. data/lib/puma/rack/urlmap.rb +93 -0
  74. data/lib/puma/rack_default.rb +24 -0
  75. data/lib/puma/reactor.rb +140 -0
  76. data/lib/puma/request.rb +701 -0
  77. data/lib/puma/runner.rb +211 -0
  78. data/lib/puma/sd_notify.rb +146 -0
  79. data/lib/puma/server.rb +734 -0
  80. data/lib/puma/single.rb +72 -0
  81. data/lib/puma/state_file.rb +69 -0
  82. data/lib/puma/thread_pool.rb +402 -0
  83. data/lib/puma/util.rb +134 -0
  84. data/lib/puma.rb +93 -0
  85. data/lib/rack/handler/puma.rb +144 -0
  86. data/tools/Dockerfile +18 -0
  87. data/tools/trickletest.rb +44 -0
  88. metadata +152 -0
@@ -0,0 +1,140 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Puma
4
+ class UnsupportedBackend < StandardError; end
5
+
6
+ # Monitors a collection of IO objects, calling a block whenever
7
+ # any monitored object either receives data or times out, or when the Reactor shuts down.
8
+ #
9
+ # The waiting/wake up is performed with nio4r, which will use the appropriate backend (libev,
10
+ # Java NIO or just plain IO#select). The call to `NIO::Selector#select` will
11
+ # 'wakeup' any IO object that receives data.
12
+ #
13
+ # This class additionally tracks a timeout for every added object,
14
+ # and wakes up any object when its timeout elapses.
15
+ #
16
+ # The implementation uses a Queue to synchronize adding new objects from the internal select loop.
17
+ class Reactor
18
+
19
+ # @!attribute [rw] reactor_max
20
+ # Maximum number of clients in the selector. Reset with calls to `Server.stats`.
21
+ attr_accessor :reactor_max
22
+ attr_reader :reactor_size
23
+
24
+ # Create a new Reactor to monitor IO objects added by #add.
25
+ # The provided block will be invoked when an IO has data available to read,
26
+ # its timeout elapses, or when the Reactor shuts down.
27
+ def initialize(backend, &block)
28
+ require 'nio'
29
+ valid_backends = [:auto, *::NIO::Selector.backends]
30
+ unless valid_backends.include?(backend)
31
+ raise ArgumentError.new("unsupported IO selector backend: #{backend} (available backends: #{valid_backends.join(', ')})")
32
+ end
33
+
34
+ @selector = ::NIO::Selector.new(NIO::Selector.backends.delete(backend))
35
+ @input = Queue.new
36
+ @timeouts = []
37
+ @block = block
38
+ @reactor_size = 0
39
+ @reactor_max = 0
40
+ end
41
+
42
+ # Run the internal select loop, using a background thread by default.
43
+ def run(background=true)
44
+ if background
45
+ @thread = Thread.new do
46
+ Puma.set_thread_name "reactor"
47
+ select_loop
48
+ end
49
+ else
50
+ select_loop
51
+ end
52
+ end
53
+
54
+ # Add a new client to monitor.
55
+ # The object must respond to #timeout and #timeout_at.
56
+ # Returns false if the reactor is already shut down.
57
+ def add(client)
58
+ @input << client
59
+ @selector.wakeup
60
+ true
61
+ rescue ClosedQueueError, IOError # Ignore if selector is already closed
62
+ false
63
+ end
64
+
65
+ # Shutdown the reactor, blocking until the background thread is finished.
66
+ def shutdown
67
+ @input.close
68
+ begin
69
+ @selector.wakeup
70
+ rescue IOError # Ignore if selector is already closed
71
+ end
72
+ @thread&.join
73
+ end
74
+
75
+ private
76
+
77
+ def select_loop
78
+ close_selector = true
79
+ begin
80
+ until @input.closed? && @input.empty?
81
+ # Wakeup any registered object that receives incoming data.
82
+ # Block until the earliest timeout or Selector#wakeup is called.
83
+ timeout = (earliest = @timeouts.first) && earliest.timeout
84
+ monitor_wake_up = false
85
+ @selector.select(timeout) do |monitor|
86
+ monitor_wake_up = true
87
+ wakeup!(monitor.value)
88
+ end
89
+
90
+ # Wakeup all objects that timed out.
91
+ timed_out = @timeouts.take_while { |client| client.timeout == 0 }
92
+ timed_out.each { |client| wakeup!(client) }
93
+
94
+ unless @input.empty?
95
+ until @input.empty?
96
+ client = @input.pop
97
+ register(client) if client.io_ok?
98
+ end
99
+ @timeouts.sort_by!(&:timeout_at)
100
+ end
101
+ end
102
+ rescue StandardError => e
103
+ STDERR.puts "Error in reactor loop escaped: #{e.message} (#{e.class})"
104
+ STDERR.puts e.backtrace
105
+
106
+ # NoMethodError may be rarely raised when calling @selector.select, which
107
+ # is odd. Regardless, it may continue for thousands of calls if retried.
108
+ # Also, when it raises, @selector.close also raises an error.
109
+ if !monitor_wake_up && NoMethodError === e
110
+ close_selector = false
111
+ else
112
+ retry
113
+ end
114
+ end
115
+ # Wakeup all remaining objects on shutdown.
116
+ @timeouts.each(&@block)
117
+ @selector.close if close_selector
118
+ end
119
+
120
+ # Start monitoring the object.
121
+ def register(client)
122
+ @selector.register(client.to_io, :r).value = client
123
+ @reactor_size += 1
124
+ @reactor_max = @reactor_size if @reactor_max < @reactor_size
125
+ @timeouts << client
126
+ rescue ArgumentError
127
+ # unreadable clients raise error when processed by NIO
128
+ end
129
+
130
+ # 'Wake up' a monitored object by calling the provided block.
131
+ # Stop monitoring the object if the block returns `true`.
132
+ def wakeup!(client)
133
+ if @block.call client
134
+ @selector.deregister client.to_io
135
+ @reactor_size -= 1
136
+ @timeouts.delete client
137
+ end
138
+ end
139
+ end
140
+ end