puma 3.8.2 → 4.3.12

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 (91) hide show
  1. checksums.yaml +5 -5
  2. data/History.md +305 -0
  3. data/LICENSE +0 -0
  4. data/README.md +162 -224
  5. data/bin/puma-wild +0 -0
  6. data/docs/architecture.md +37 -0
  7. data/{DEPLOYMENT.md → docs/deployment.md} +24 -4
  8. data/docs/images/puma-connection-flow-no-reactor.png +0 -0
  9. data/docs/images/puma-connection-flow.png +0 -0
  10. data/docs/images/puma-general-arch.png +0 -0
  11. data/docs/nginx.md +0 -0
  12. data/docs/plugins.md +38 -0
  13. data/docs/restart.md +41 -0
  14. data/docs/signals.md +56 -3
  15. data/docs/systemd.md +130 -37
  16. data/docs/tcp_mode.md +96 -0
  17. data/ext/puma_http11/PumaHttp11Service.java +2 -0
  18. data/ext/puma_http11/ext_help.h +0 -0
  19. data/ext/puma_http11/extconf.rb +21 -0
  20. data/ext/puma_http11/http11_parser.c +134 -144
  21. data/ext/puma_http11/http11_parser.h +0 -0
  22. data/ext/puma_http11/http11_parser.java.rl +21 -37
  23. data/ext/puma_http11/http11_parser.rl +12 -10
  24. data/ext/puma_http11/http11_parser_common.rl +4 -4
  25. data/ext/puma_http11/io_buffer.c +0 -0
  26. data/ext/puma_http11/mini_ssl.c +165 -34
  27. data/ext/puma_http11/org/jruby/puma/Http11.java +106 -114
  28. data/ext/puma_http11/org/jruby/puma/Http11Parser.java +85 -101
  29. data/ext/puma_http11/org/jruby/puma/IOBuffer.java +72 -0
  30. data/ext/puma_http11/org/jruby/puma/MiniSSL.java +30 -6
  31. data/ext/puma_http11/puma_http11.c +3 -0
  32. data/lib/puma/accept_nonblock.rb +7 -1
  33. data/lib/puma/app/status.rb +42 -26
  34. data/lib/puma/binder.rb +57 -74
  35. data/lib/puma/cli.rb +26 -7
  36. data/lib/puma/client.rb +307 -191
  37. data/lib/puma/cluster.rb +78 -34
  38. data/lib/puma/commonlogger.rb +2 -0
  39. data/lib/puma/configuration.rb +24 -16
  40. data/lib/puma/const.rb +41 -20
  41. data/lib/puma/control_cli.rb +46 -19
  42. data/lib/puma/detect.rb +2 -0
  43. data/lib/puma/dsl.rb +329 -68
  44. data/lib/puma/events.rb +6 -2
  45. data/lib/puma/io_buffer.rb +3 -6
  46. data/lib/puma/jruby_restart.rb +2 -1
  47. data/lib/puma/launcher.rb +125 -61
  48. data/lib/puma/minissl/context_builder.rb +76 -0
  49. data/lib/puma/minissl.rb +85 -28
  50. data/lib/puma/null_io.rb +2 -0
  51. data/lib/puma/plugin/tmp_restart.rb +2 -1
  52. data/lib/puma/plugin.rb +7 -2
  53. data/lib/puma/rack/builder.rb +4 -1
  54. data/lib/puma/rack/urlmap.rb +2 -0
  55. data/lib/puma/rack_default.rb +2 -0
  56. data/lib/puma/reactor.rb +224 -34
  57. data/lib/puma/runner.rb +27 -6
  58. data/lib/puma/server.rb +212 -68
  59. data/lib/puma/single.rb +16 -5
  60. data/lib/puma/state_file.rb +2 -0
  61. data/lib/puma/tcp_logger.rb +2 -0
  62. data/lib/puma/thread_pool.rb +67 -36
  63. data/lib/puma/util.rb +2 -6
  64. data/lib/puma.rb +16 -0
  65. data/lib/rack/handler/puma.rb +16 -5
  66. data/tools/docker/Dockerfile +16 -0
  67. data/tools/jungle/README.md +12 -2
  68. data/tools/jungle/init.d/README.md +2 -0
  69. data/tools/jungle/init.d/puma +8 -8
  70. data/tools/jungle/init.d/run-puma +1 -1
  71. data/tools/jungle/rc.d/README.md +74 -0
  72. data/tools/jungle/rc.d/puma +61 -0
  73. data/tools/jungle/rc.d/puma.conf +10 -0
  74. data/tools/jungle/upstart/README.md +0 -0
  75. data/tools/jungle/upstart/puma-manager.conf +0 -0
  76. data/tools/jungle/upstart/puma.conf +0 -0
  77. data/tools/trickletest.rb +1 -2
  78. metadata +32 -93
  79. data/.github/issue_template.md +0 -20
  80. data/Gemfile +0 -12
  81. data/Manifest.txt +0 -78
  82. data/Rakefile +0 -158
  83. data/Release.md +0 -9
  84. data/gemfiles/2.1-Gemfile +0 -12
  85. data/lib/puma/compat.rb +0 -14
  86. data/lib/puma/convenient.rb +0 -23
  87. data/lib/puma/daemon_ext.rb +0 -31
  88. data/lib/puma/delegation.rb +0 -11
  89. data/lib/puma/java_io_buffer.rb +0 -45
  90. data/lib/puma/rack/backports/uri/common_193.rb +0 -33
  91. data/puma.gemspec +0 -52
data/docs/plugins.md ADDED
@@ -0,0 +1,38 @@
1
+ ## Plugins
2
+
3
+ Puma 3.0 added support for plugins that can augment configuration and service
4
+ operations.
5
+
6
+ 2 canonical plugins to look to aid in development of further plugins:
7
+
8
+ * [tmp\_restart](https://github.com/puma/puma/blob/master/lib/puma/plugin/tmp_restart.rb):
9
+ Restarts the server if the file `tmp/restart.txt` is touched
10
+ * [heroku](https://github.com/puma/puma-heroku/blob/master/lib/puma/plugin/heroku.rb):
11
+ Packages up the default configuration used by puma on Heroku
12
+
13
+ Plugins are activated in a puma configuration file (such as `config/puma.rb'`)
14
+ by adding `plugin "name"`, such as `plugin "heroku"`.
15
+
16
+ Plugins are activated based simply on path requirements so, activating the
17
+ `heroku` plugin will simply be doing `require "puma/plugin/heroku"`. This
18
+ allows gems to provide multiple plugins (as well as unrelated gems to provide
19
+ puma plugins).
20
+
21
+ The `tmp_restart` plugin is bundled with puma, so it can always be used.
22
+
23
+ To use the `heroku` plugin, add `puma-heroku` to your Gemfile or install it.
24
+
25
+ ### API
26
+
27
+ ## Server-wide hooks
28
+
29
+ Plugins can use a couple of hooks at server level: `start` and `config`.
30
+
31
+ `start` runs when the server has started and allows the plugin to start other
32
+ functionality to augment puma.
33
+
34
+ `config` runs when the server is being configured and is passed a `Puma::DSL`
35
+ object that can be used to add additional configuration.
36
+
37
+ Any public methods in `Puma::Plugin` are the public API that any plugin may
38
+ use.
data/docs/restart.md ADDED
@@ -0,0 +1,41 @@
1
+ # Restarts
2
+
3
+ To perform a restart, there are 3 builtin mechanisms:
4
+
5
+ * Send the `puma` process the `SIGUSR2` signal (normal restart)
6
+ * Send the `puma` process the `SIGUSR1` signal (restart in phases (a "rolling restart"), cluster mode only)
7
+ * Use the status server and issue `/restart`
8
+
9
+ No code is shared between the current and restarted process, so it should be safe to issue a restart any place where you would manually stop Puma and start it again.
10
+
11
+ If the new process is unable to load, it will simply exit. You should therefore run Puma under a process monitor (see below) when using it in production.
12
+
13
+ ### Normal vs Hot vs Phased Restart
14
+
15
+ A hot restart means that no requests will be lost while deploying your new code, since the server socket is kept open between restarts.
16
+
17
+ But beware, hot restart does not mean that the incoming requests won’t hang for multiple seconds while your new code has not fully deployed. If you need a zero downtime and zero hanging requests deploy, you must use phased restart.
18
+
19
+ When you run pumactl phased-restart, Puma kills workers one-by-one, meaning that at least another worker is still available to serve requests, which lead to zero hanging requests (yay!).
20
+
21
+ But again beware, upgrading an application sometimes involves upgrading the database schema. With phased restart, there may be a moment during the deployment where processes belonging to the previous version and processes belonging to the new version both exist at the same time. Any database schema upgrades you perform must therefore be backwards-compatible with the old application version.
22
+
23
+ If you perform a lot of database migrations, you probably should not use phased restart and use a normal/hot restart instead (`pumactl restart`). That way, no code is shared while deploying (in that case, `preload_app!` might help for quicker deployment, see ["Clustered Mode" in the README](../README.md#clustered-mode)).
24
+
25
+ **Note**: Hot and phased restarts are only available on MRI, not on JRuby. They are also unavailable on Windows servers.
26
+
27
+ ### Release Directory
28
+
29
+ If your symlink releases into a common working directory (i.e., `/current` from Capistrano), Puma won't pick up your new changes when running phased restarts without additional configuration. You should set your working directory within Puma's config to specify the directory it should use. This is a change from earlier versions of Puma (< 2.15) that would infer the directory for you.
30
+
31
+ ```ruby
32
+ # config/puma.rb
33
+
34
+ directory '/var/www/current'
35
+ ```
36
+
37
+ ### Cleanup Code
38
+
39
+ Puma isn't able to understand all the resources that your app may use, so it provides a hook in the configuration file you pass to `-C` called `on_restart`. The block passed to `on_restart` will be called, unsurprisingly, just before Puma restarts itself.
40
+
41
+ You should place code to close global log files, redis connections, etc. in this block so that their file descriptors don't leak into the restarted process. Failure to do so will result in slowly running out of descriptors and eventually obscure crashes as the server is restarted many times.
data/docs/signals.md CHANGED
@@ -36,8 +36,61 @@ Puma cluster responds to these signals:
36
36
  - `TTIN` increment the worker count by 1
37
37
  - `TTOU` decrement the worker count by 1
38
38
  - `TERM` send `TERM` to worker. Worker will attempt to finish then exit.
39
- - `USR2` restart workers
40
- - `USR1` restart workers in phases, a rolling restart.
41
- - `HUP` reopen log files defined in stdout_redirect configuration parameter
39
+ - `USR2` restart workers. This also reloads puma configuration file, if there is one.
40
+ - `USR1` restart workers in phases, a rolling restart. This will not reload configuration file.
41
+ - `HUP` reopen log files defined in stdout_redirect configuration parameter. If there is no stdout_redirect option provided it will behave like `INT`
42
42
  - `INT` equivalent of sending Ctrl-C to cluster. Will attempt to finish then exit.
43
43
  - `CHLD`
44
+
45
+ ## Callbacks order in case of different signals
46
+
47
+ ### Start application
48
+
49
+ ```
50
+ puma configuration file reloaded, if there is one
51
+ * Pruning Bundler environment
52
+ puma configuration file reloaded, if there is one
53
+
54
+ before_fork
55
+ on_worker_fork
56
+ after_worker_fork
57
+
58
+ Gemfile in context
59
+
60
+ on_worker_boot
61
+
62
+ Code of the app is loaded and running
63
+ ```
64
+
65
+ ### Send USR2
66
+
67
+ ```
68
+ on_worker_shutdown
69
+ on_restart
70
+
71
+ puma configuration file reloaded, if there is one
72
+
73
+ before_fork
74
+ on_worker_fork
75
+ after_worker_fork
76
+
77
+ Gemfile in context
78
+
79
+ on_worker_boot
80
+
81
+ Code of the app is loaded and running
82
+ ```
83
+
84
+ ### Send USR1
85
+
86
+ ```
87
+ on_worker_shutdown
88
+ on_worker_fork
89
+ after_worker_fork
90
+
91
+ Gemfile in context
92
+
93
+ on_worker_boot
94
+
95
+ Code of the app is loaded and running
96
+ ```
data/docs/systemd.md CHANGED
@@ -3,10 +3,21 @@
3
3
  [systemd](https://www.freedesktop.org/wiki/Software/systemd/) is a
4
4
  commonly available init system (PID 1) on many Linux distributions. It
5
5
  offers process monitoring (including automatic restarts) and other
6
- useful features for running Puma in production. Below is a sample
7
- puma.service configuration file for systemd:
6
+ useful features for running Puma in production.
8
7
 
9
- ~~~~
8
+ ## Service Configuration
9
+
10
+ Below is a sample puma.service configuration file for systemd, which
11
+ can be copied or symlinked to /etc/systemd/system/puma.service, or if
12
+ desired, using an application or instance specific name.
13
+
14
+ Note that this uses the systemd preferred "simple" type where the
15
+ start command remains running in the foreground (does not fork and
16
+ exit). See also, the
17
+ [Alternative Forking Configuration](#alternative-forking-configuration)
18
+ below.
19
+
20
+ ~~~~ ini
10
21
  [Unit]
11
22
  Description=Puma HTTP Server
12
23
  After=network.target
@@ -21,22 +32,26 @@ Type=simple
21
32
  # Preferably configure a non-privileged user
22
33
  # User=
23
34
 
24
- # Specify the path to your puma application root
25
- # WorkingDirectory=
35
+ # The path to the your application code root directory.
36
+ # Also replace the "<YOUR_APP_PATH>" place holders below with this path.
37
+ # Example /home/username/myapp
38
+ WorkingDirectory=<YOUR_APP_PATH>
26
39
 
27
40
  # Helpful for debugging socket activation, etc.
28
41
  # Environment=PUMA_DEBUG=1
29
42
 
30
- # The command to start Puma
31
- # Here we are using a binstub generated via:
32
- # `bundle binstubs puma --path ./sbin`
33
- # in the WorkingDirectory (replace <WD> below)
34
- # You can alternatively use `bundle exec --keep-file-descriptors puma`
35
- # ExecStart=<WD>/sbin/puma -b tcp://0.0.0.0:9292 -b ssl://0.0.0.0:9293?key=key.pem&cert=cert.pem
43
+ # SystemD will not run puma even if it is in your path. You must specify
44
+ # an absolute URL to puma. For example /usr/local/bin/puma
45
+ # Alternatively, create a binstub with `bundle binstubs puma --path ./sbin` in the WorkingDirectory
46
+ ExecStart=/<FULLPATH>/bin/puma -C <YOUR_APP_PATH>/puma.rb
47
+
48
+ # Variant: Rails start.
49
+ # ExecStart=/<FULLPATH>/bin/puma -C <YOUR_APP_PATH>/config/puma.rb ../config.ru
50
+
51
+ # Variant: Use `bundle exec --keep-file-descriptors puma` instead of binstub
52
+ # Variant: Specify directives inline.
53
+ # ExecStart=/<FULLPATH>/puma -b tcp://0.0.0.0:9292 -b ssl://0.0.0.0:9293?key=key.pem&cert=cert.pem
36
54
 
37
- # Alternatively with a config file (in WorkingDirectory) and
38
- # comparable `bind` directives
39
- # ExecStart=<WD>/sbin/puma -C config.rb
40
55
 
41
56
  Restart=always
42
57
 
@@ -50,14 +65,29 @@ for additional details.
50
65
  ## Socket Activation
51
66
 
52
67
  systemd and puma also support socket activation, where systemd opens
53
- the listening socket(s) in advance and provides them to the puma master
54
- process on startup. Among other advantages, this keeps listening
55
- sockets open across puma restarts and achieves graceful restarts. To
56
- use socket activation, configure one or more `ListenStream`
57
- sockets in a companion `*.socket` systemd config file. Here is a sample
58
- puma.socket, matching the ports used in the above puma.service:
59
-
60
- ~~~~
68
+ the listening socket(s) in advance and provides them to the puma
69
+ master process on startup. Among other advantages, this keeps
70
+ listening sockets open across puma restarts and achieves graceful
71
+ restarts, including when upgraded puma, and is compatible with both
72
+ clustered mode and application preload.
73
+
74
+ **Note:** Any wrapper scripts which `exec`, or other indirections in
75
+ `ExecStart`, may result in activated socket file descriptors being closed
76
+ before they reach the puma master process. For example, if using `bundle exec`,
77
+ pass the `--keep-file-descriptors` flag. `bundle exec` can be avoided by using a
78
+ `puma` executable generated by `bundle binstubs puma`. This is tracked in
79
+ [#1499].
80
+
81
+ **Note:** Socket activation doesn't currently work on jruby. This is
82
+ tracked in [#1367].
83
+
84
+ To use socket activation, configure one or more `ListenStream` sockets
85
+ in a companion `*.socket` unit file. Also uncomment the associated
86
+ `Requires` directive for the socket unit in the service file (see
87
+ above.) Here is a sample puma.socket, matching the ports used in the
88
+ above puma.service:
89
+
90
+ ~~~~ ini
61
91
  [Unit]
62
92
  Description=Puma HTTP Server Accept Sockets
63
93
 
@@ -84,6 +114,16 @@ for additional configuration details.
84
114
  Note that the above configurations will work with Puma in either
85
115
  single process or cluster mode.
86
116
 
117
+ ### Sockets and symlinks
118
+
119
+ When using releases folders, you should set the socket path using the
120
+ shared folder path (ex. `/srv/projet/shared/tmp/puma.sock`), not the
121
+ release folder path (`/srv/projet/releases/1234/tmp/puma.sock`).
122
+
123
+ Puma will detect the release path socket as different than the one provided by
124
+ systemd and attempt to bind it again, resulting in the exception
125
+ `There is already a server bound to:`.
126
+
87
127
  ## Usage
88
128
 
89
129
  Without socket activation, use `systemctl` as root (e.g. via `sudo`) as
@@ -169,29 +209,82 @@ Apr 07 08:40:19 hx puma[28320]: * Activated ssl://0.0.0.0:9234?key=key.pem&cert=
169
209
  Apr 07 08:40:19 hx puma[28320]: Use Ctrl-C to stop
170
210
  ~~~~
171
211
 
172
- ## Alternative background process configuration
173
-
174
- If Capistrano and [capistrano3-puma](https://github.com/seuros/capistrano-puma) tasks are used you can use the following configuration. In this case, you would skip systemd Socket Activation, since Puma handles the socket by itself:
212
+ ## Alternative Forking Configuration
213
+
214
+ Other systems/tools might expect or need puma to be run as a
215
+ "traditional" forking server, for example so that the `pumactl`
216
+ command can be used directly and outside of systemd for
217
+ stop/start/restart. This use case is incompatible with systemd socket
218
+ activation, so it should not be configured. Below is an alternative
219
+ puma.service config sample, using `Type=forking` and the `--daemon`
220
+ flag in `ExecStart`. Here systemd is playing a role more equivalent to
221
+ SysV init.d, where it is responsible for starting Puma on boot
222
+ (multi-user.target) and stopping it on shutdown, but is not performing
223
+ continuous restarts. Therefore running Puma in cluster mode, where the
224
+ master can restart workers, is highly recommended. See the systemd
225
+ [Restart] directive for details.
226
+
227
+ ~~~~ ini
228
+ [Unit]
229
+ Description=Puma HTTP Forking Server
230
+ After=network.target
175
231
 
176
- ~~~~
177
232
  [Service]
178
233
  # Background process configuration (use with --daemon in ExecStart)
179
234
  Type=forking
180
235
 
181
- # To learn which exact command is to be used to execute at "ExecStart" of this
182
- # Service, ask Capistrano: `cap <stage> puma:start --dry-run`. Your result
183
- # may differ from this example, for example if you use a Ruby version
184
- # manager. `<WD>` is short for "your working directory". Replace it with your
185
- # path.
236
+ # Preferably configure a non-privileged user
237
+ # User=
238
+
239
+ # The path to the puma application root
240
+ # Also replace the "<WD>" place holders below with this path.
241
+ WorkingDirectory=
242
+
243
+ # The command to start Puma
244
+ # (replace "<WD>" below)
186
245
  ExecStart=bundle exec puma -C <WD>/shared/puma.rb --daemon
187
246
 
188
- # To learn which exact command is to be used to execute at "ExecStop" of this
189
- # Service, ask Capistrano: `cap <stage> puma:stop --dry-run`. Your result
190
- # may differ from this example, for example if you use a Ruby version
191
- # manager. `<WD>` is short for "your working directory". Replace it with your
192
- # path.
247
+ # The command to stop Puma
248
+ # (replace "<WD>" below)
193
249
  ExecStop=bundle exec pumactl -S <WD>/shared/tmp/pids/puma.state stop
194
250
 
195
- # PIDFile setting is required in order to work properly
251
+ # Path to PID file so that systemd knows which is the master process
196
252
  PIDFile=<WD>/shared/tmp/pids/puma.pid
253
+
254
+ # Should systemd restart puma?
255
+ # Use "no" (the default) to ensure no interference when using
256
+ # stop/start/restart via `pumactl`. The "on-failure" setting might
257
+ # work better for this purpose, but you must test it.
258
+ # Use "always" if only `systemctl` is used for start/stop/restart, and
259
+ # reconsider if you actually need the forking config.
260
+ Restart=no
261
+
262
+ # `puma_ctl restart` wouldn't work without this. It's because `pumactl`
263
+ # changes PID on restart and systemd stops the service afterwards
264
+ # because of the PID change. This option prevents stopping after PID
265
+ # change.
266
+ RemainAfterExit=yes
267
+
268
+ [Install]
269
+ WantedBy=multi-user.target
270
+ ~~~~
271
+
272
+ ### capistrano3-puma
273
+
274
+ By default,
275
+ [capistrano3-puma](https://github.com/seuros/capistrano-puma) uses
276
+ `pumactl` for deployment restarts, outside of systemd. To learn the
277
+ exact commands that this tool would use for `ExecStart` and
278
+ `ExecStop`, use the following `cap` commands in dry-run mode, and
279
+ update from the above forking service configuration accordingly. Note
280
+ also that the configured `User` should likely be the same as the
281
+ capistrano3-puma `:puma_user` option.
282
+
283
+ ~~~~ sh
284
+ stage=production # or different stage, as needed
285
+ cap $stage puma:start --dry-run
286
+ cap $stage puma:stop --dry-run
197
287
  ~~~~
288
+
289
+ [Restart]: https://www.freedesktop.org/software/systemd/man/systemd.service.html#Restart=
290
+ [#1367]: https://github.com/puma/puma/issues/1367
data/docs/tcp_mode.md ADDED
@@ -0,0 +1,96 @@
1
+ # TCP mode
2
+
3
+ Puma also could be used as a TCP server to process incoming TCP
4
+ connections.
5
+
6
+
7
+ ## Configuration
8
+
9
+ TCP mode can be enabled with CLI option `--tcp-mode`:
10
+
11
+ ```
12
+ $ puma --tcp-mode
13
+ ```
14
+
15
+ Default ip and port to listen to are `0.0.0.0` and `9292`. You can configure
16
+ them with `--port` and `--bind` options:
17
+
18
+ ```
19
+ $ puma --tcp-mode --bind tcp://127.0.0.1:9293
20
+ $ puma --tcp-mode --port 9293
21
+ ```
22
+
23
+ TCP mode could be set with a configuration file as well with `tcp_mode`
24
+ and `tcp_mode!` methods:
25
+
26
+ ```
27
+ # config/puma.rb
28
+ tcp_mode
29
+ ```
30
+
31
+ When Puma starts in the TCP mode it prints the corresponding message:
32
+
33
+ ```
34
+ puma --tcp-mode
35
+ Puma starting in single mode...
36
+ ...
37
+ * Mode: Lopez Express (tcp)
38
+ ```
39
+
40
+
41
+ ## How to declare an application
42
+
43
+ An application to process TCP connections should be declared as a
44
+ callable object which accepts `env` and `socket` arguments.
45
+
46
+ `env` argument is a Hash with following structure:
47
+
48
+ ```ruby
49
+ { "thread" => {}, "REMOTE_ADDR" => "127.0.0.1:51133", "log" => "#<Proc:0x000..." }
50
+ ```
51
+
52
+ It consists of:
53
+ * `thread` - a Hash for each thread in the thread pool that could be
54
+ used to store information between requests
55
+ * `REMOTE_ADDR` - a client ip address
56
+ * `log` - a proc object to write something down
57
+
58
+ `log` object could be used this way:
59
+
60
+ ```ruby
61
+ env['log'].call('message to log')
62
+ #> 19/Oct/2019 20:28:53 - 127.0.0.1:51266 - message to log
63
+ ```
64
+
65
+
66
+ ## Example of an application
67
+
68
+ Let's look at an example of a simple application which just echoes
69
+ incoming string:
70
+
71
+ ```ruby
72
+ # config/puma.rb
73
+ app do |env, socket|
74
+ s = socket.gets
75
+ socket.puts "Echo #{s}"
76
+ end
77
+ ```
78
+
79
+ We can easily access the TCP server with `telnet` command and receive an
80
+ echo:
81
+
82
+ ```shell
83
+ telnet 0.0.0.0 9293
84
+ Trying 0.0.0.0...
85
+ Connected to 0.0.0.0.
86
+ Escape character is '^]'.
87
+ sssss
88
+ Echo sssss
89
+ ^CConnection closed by foreign host.
90
+ ```
91
+
92
+
93
+ ## Socket management
94
+
95
+ After the application finishes, Puma closes the socket. In order to
96
+ prevent this, the application should set `env['detach'] = true`.
@@ -6,11 +6,13 @@ import org.jruby.Ruby;
6
6
  import org.jruby.runtime.load.BasicLibraryService;
7
7
 
8
8
  import org.jruby.puma.Http11;
9
+ import org.jruby.puma.IOBuffer;
9
10
  import org.jruby.puma.MiniSSL;
10
11
 
11
12
  public class PumaHttp11Service implements BasicLibraryService {
12
13
  public boolean basicLoad(final Ruby runtime) throws IOException {
13
14
  Http11.createHttp11(runtime);
15
+ IOBuffer.createIOBuffer(runtime);
14
16
  MiniSSL.createMiniSSL(runtime);
15
17
  return true;
16
18
  }
File without changes
@@ -1,6 +1,11 @@
1
1
  require 'mkmf'
2
2
 
3
3
  dir_config("puma_http11")
4
+ if $mingw && RUBY_VERSION >= '2.4'
5
+ append_cflags '-D_FORTIFY_SOURCE=2'
6
+ append_ldflags '-fstack-protector'
7
+ have_library 'ssp'
8
+ end
4
9
 
5
10
  unless ENV["DISABLE_SSL"]
6
11
  dir_config("openssl")
@@ -9,6 +14,22 @@ unless ENV["DISABLE_SSL"]
9
14
  %w'ssl ssleay32'.find {|ssl| have_library(ssl, 'SSL_CTX_new')}
10
15
 
11
16
  have_header "openssl/bio.h"
17
+
18
+ # below is yes for 1.0.2 & later
19
+ have_func "DTLS_method" , "openssl/ssl.h"
20
+
21
+ # below are yes for 1.1.0 & later, may need to check func rather than macro
22
+ # with versions after 1.1.1
23
+ have_func "TLS_server_method" , "openssl/ssl.h"
24
+ have_macro "SSL_CTX_set_min_proto_version", "openssl/ssl.h"
25
+
26
+ # Random.bytes available in Ruby 2.5 and later, Random::DEFAULT deprecated in 3.0
27
+ if Random.respond_to?(:bytes)
28
+ $defs.push("-DHAVE_RANDOM_BYTES")
29
+ puts "checking for Random.bytes... yes"
30
+ else
31
+ puts "checking for Random.bytes... no"
32
+ end
12
33
  end
13
34
  end
14
35