puma 8.0.2-java → 8.1.0-java

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 (49) hide show
  1. checksums.yaml +4 -4
  2. data/History.md +136 -0
  3. data/README.md +20 -5
  4. data/docs/6.0-Upgrade.md +1 -1
  5. data/docs/8.0-Upgrade.md +2 -2
  6. data/docs/deployment.md +3 -3
  7. data/docs/fork_worker.md +34 -4
  8. data/docs/kubernetes.md +3 -3
  9. data/docs/plugins.md +2 -2
  10. data/docs/puma_support.md +78 -0
  11. data/docs/rails_dev_mode.md +2 -2
  12. data/docs/restart.md +4 -3
  13. data/docs/signals.md +2 -2
  14. data/docs/stats.md +5 -5
  15. data/docs/systemd.md +4 -2
  16. data/docs/testing_benchmarks_local_files.md +1 -1
  17. data/docs/testing_test_rackup_ci_files.md +2 -2
  18. data/ext/puma_http11/extconf.rb +2 -0
  19. data/ext/puma_http11/http11_parser.c +6 -2
  20. data/ext/puma_http11/http11_parser_common.rl +4 -1
  21. data/ext/puma_http11/mini_ssl.c +16 -5
  22. data/ext/puma_http11/org/jruby/puma/Http11Parser.java +36 -36
  23. data/ext/puma_http11/org/jruby/puma/MiniSSL.java +44 -34
  24. data/ext/puma_http11/puma_http11.c +28 -3
  25. data/lib/puma/binder.rb +29 -0
  26. data/lib/puma/cli.rb +6 -0
  27. data/lib/puma/client.rb +178 -44
  28. data/lib/puma/client_env.rb +32 -18
  29. data/lib/puma/cluster/worker.rb +109 -33
  30. data/lib/puma/cluster/worker_handle.rb +16 -0
  31. data/lib/puma/cluster.rb +173 -44
  32. data/lib/puma/commonlogger.rb +3 -3
  33. data/lib/puma/configuration.rb +23 -3
  34. data/lib/puma/const.rb +14 -9
  35. data/lib/puma/control_cli.rb +14 -3
  36. data/lib/puma/dsl.rb +279 -92
  37. data/lib/puma/launcher.rb +6 -4
  38. data/lib/puma/minissl.rb +101 -56
  39. data/lib/puma/plugin/systemd.rb +1 -1
  40. data/lib/puma/puma_http11.jar +0 -0
  41. data/lib/puma/reactor.rb +35 -3
  42. data/lib/puma/response.rb +28 -6
  43. data/lib/puma/runner.rb +5 -1
  44. data/lib/puma/sd_notify.rb +4 -1
  45. data/lib/puma/server.rb +131 -35
  46. data/lib/puma/thread_pool.rb +12 -1
  47. data/lib/puma/util.rb +8 -4
  48. data/lib/puma.rb +1 -1
  49. metadata +3 -2
@@ -78,7 +78,7 @@ ruby 3.2.0dev (2022-06-14T01:21:55Z master 048f14221c) +YJIT [x86_64-linux]
78
78
 
79
79
  ## bench_base.sh, bench_base.rb
80
80
 
81
- These two files setup parameters for the Puma server, which is normally started in a shell
81
+ These two files set up parameters for the Puma server, which is normally started in a shell
82
82
  script. It then starts a Ruby file (a subclass of BenchBase), passing arguments to it. The
83
83
  Ruby file is normally used to generate a client request stream(s).
84
84
 
@@ -7,7 +7,7 @@ and by the type of object used for the body.
7
7
 
8
8
  Five rackup files are located in 'test/rackup' that can be used. All have their
9
9
  request body size (in kB) set via `Body-Conf` header or with `ENV['CI_BODY_CONF']`.
10
- Additionally, the ci_select.ru file can have it's body type set via a starting
10
+ Additionally, the ci_select.ru file can have its body type set via a starting
11
11
  character.
12
12
 
13
13
  * **ci_array.ru** - body is an `Array` of 1kB strings. `Content-Length` is not set.
@@ -21,7 +21,7 @@ contain 1kB items.
21
21
 
22
22
  All can be delayed by a float value (seconds) specified by the `Dly` header
23
23
 
24
- Note that rhe `Body-Conf` header takes precedence, and `ENV['CI_BODY_CONF']` is
24
+ Note that the `Body-Conf` header takes precedence, and `ENV['CI_BODY_CONF']` is
25
25
  only read on load.
26
26
 
27
27
  ## ci_select.ru
@@ -8,6 +8,8 @@ if $mingw
8
8
  have_library 'ssp'
9
9
  end
10
10
 
11
+ have_func "prctl(PR_SET_CHILD_SUBREAPER, 1)", "sys/prctl.h"
12
+
11
13
  unless ENV["PUMA_DISABLE_SSL"]
12
14
  # don't use pkg_config('openssl') if '--with-openssl-dir' is used
13
15
  has_openssl_dir = dir_config('openssl').any? ||
@@ -592,6 +592,10 @@ case 24:
592
592
  case 60: goto st0;
593
593
  case 62: goto st0;
594
594
  case 63: goto tr39;
595
+ case 92: goto st0;
596
+ case 96: goto st0;
597
+ case 123: goto st0;
598
+ case 125: goto st0;
595
599
  case 127: goto st0;
596
600
  }
597
601
  if ( 0 <= (*p) && (*p) <= 31 )
@@ -607,7 +611,7 @@ st25:
607
611
  if ( ++p == pe )
608
612
  goto _test_eof25;
609
613
  case 25:
610
- #line 611 "ext/puma_http11/http11_parser.c"
614
+ #line 615 "ext/puma_http11/http11_parser.c"
611
615
  switch( (*p) ) {
612
616
  case 32: goto tr41;
613
617
  case 34: goto st0;
@@ -627,7 +631,7 @@ st26:
627
631
  if ( ++p == pe )
628
632
  goto _test_eof26;
629
633
  case 26:
630
- #line 631 "ext/puma_http11/http11_parser.c"
634
+ #line 635 "ext/puma_http11/http11_parser.c"
631
635
  switch( (*p) ) {
632
636
  case 32: goto tr44;
633
637
  case 34: goto st0;
@@ -17,6 +17,9 @@
17
17
  escape = ("%" xdigit xdigit);
18
18
  uchar = (unreserved | escape | "%");
19
19
  pchar = (uchar | ":" | "@" | "&" | "=" | "+" | ";");
20
+ # RFC 3986 disallows these in paths; browsers never send them unescaped there.
21
+ path_unwise = ("{" | "}" | "`" | "\\");
22
+ path_char = pchar -- path_unwise;
20
23
  tspecials = ("(" | ")" | "<" | ">" | "@" | "," | ";" | ":" | "\\" | "\"" | "/" | "[" | "]" | "?" | "=" | "{" | "}" | " " | "\t");
21
24
 
22
25
  # elements
@@ -26,7 +29,7 @@
26
29
  scheme = ( alpha | digit | "+" | "-" | "." )* ;
27
30
  absolute_uri = (scheme ":" (uchar | reserved )*);
28
31
 
29
- path = ( pchar+ ( "/" pchar* )* ) ;
32
+ path = ( path_char+ ( "/" path_char* )* ) ;
30
33
  query = ( uchar | reserved )* %query_string ;
31
34
  param = ( pchar | "/" )* ;
32
35
  params = ( param ( ";" param )* ) ;
@@ -228,7 +228,7 @@ sslctx_alloc(VALUE klass) {
228
228
  VALUE
229
229
  sslctx_initialize(VALUE self, VALUE mini_ssl_ctx) {
230
230
  SSL_CTX* ctx;
231
- int ssl_options;
231
+ int ssl_options, private_key_result;
232
232
  VALUE key, cert, ca, verify_mode, ssl_cipher_filter, ssl_ciphersuites, no_tlsv1, no_tlsv1_1,
233
233
  verification_flags, session_id_bytes, cert_pem, key_pem, key_password_command, key_password;
234
234
  BIO *bio;
@@ -292,15 +292,19 @@ sslctx_initialize(VALUE self, VALUE mini_ssl_ctx) {
292
292
  StringValue(key_password);
293
293
  password_cb = password_callback;
294
294
  password = RSTRING_PTR(key_password);
295
- SSL_CTX_set_default_passwd_cb(ctx, password_cb);
296
- SSL_CTX_set_default_passwd_cb_userdata(ctx, (void *) password);
297
295
  }
298
296
  }
299
297
 
300
298
  if (!NIL_P(key)) {
301
299
  StringValue(key);
302
300
 
303
- if (SSL_CTX_use_PrivateKey_file(ctx, RSTRING_PTR(key), SSL_FILETYPE_PEM) != 1) {
301
+ SSL_CTX_set_default_passwd_cb(ctx, password_cb);
302
+ SSL_CTX_set_default_passwd_cb_userdata(ctx, (void *) password);
303
+ private_key_result = SSL_CTX_use_PrivateKey_file(ctx, RSTRING_PTR(key), SSL_FILETYPE_PEM);
304
+ SSL_CTX_set_default_passwd_cb(ctx, NULL);
305
+ SSL_CTX_set_default_passwd_cb_userdata(ctx, NULL);
306
+
307
+ if (private_key_result != 1) {
304
308
  raise_file_error("SSL_CTX_use_PrivateKey_file", RSTRING_PTR(key));
305
309
  }
306
310
  }
@@ -440,7 +444,14 @@ sslctx_initialize(VALUE self, VALUE mini_ssl_ctx) {
440
444
 
441
445
  if (!NIL_P(ssl_cipher_filter)) {
442
446
  StringValue(ssl_cipher_filter);
443
- SSL_CTX_set_cipher_list(ctx, RSTRING_PTR(ssl_cipher_filter));
447
+ ERR_clear_error();
448
+ if (SSL_CTX_set_cipher_list(ctx, RSTRING_PTR(ssl_cipher_filter)) != 1) {
449
+ if (ERR_GET_REASON(ERR_peek_last_error()) == SSL_R_NO_CIPHER_MATCH) {
450
+ ERR_clear_error();
451
+ } else {
452
+ raise_param_error("SSL_CTX_set_cipher_list", "ssl_cipher_filter");
453
+ }
454
+ }
444
455
  }
445
456
  else {
446
457
  SSL_CTX_set_cipher_list(ctx, "HIGH:!aNULL@STRENGTH");
@@ -36,8 +36,8 @@ private static short[] init__puma_parser_key_offsets_0()
36
36
  return new short [] {
37
37
  0, 0, 8, 17, 27, 29, 30, 31, 32, 33, 34, 36,
38
38
  39, 41, 44, 45, 61, 62, 78, 85, 91, 99, 107, 117,
39
- 125, 134, 142, 150, 159, 168, 177, 186, 195, 204, 213, 222,
40
- 231, 240, 249, 258, 267, 276, 285, 294, 303, 312, 313
39
+ 125, 138, 146, 154, 163, 172, 181, 190, 199, 208, 217, 226,
40
+ 235, 244, 253, 262, 271, 280, 289, 298, 307, 316, 317
41
41
  };
42
42
  }
43
43
 
@@ -57,23 +57,23 @@ private static char[] init__puma_parser_trans_keys_0()
57
57
  31, 13, 127, 0, 8, 10, 31, 32, 60, 62, 127, 0,
58
58
  31, 34, 35, 32, 60, 62, 127, 0, 31, 34, 35, 43,
59
59
  58, 45, 46, 48, 57, 65, 90, 97, 122, 32, 34, 35,
60
- 60, 62, 127, 0, 31, 32, 34, 35, 60, 62, 63, 127,
61
- 0, 31, 32, 34, 35, 60, 62, 127, 0, 31, 32, 34,
62
- 35, 60, 62, 127, 0, 31, 32, 36, 95, 45, 46, 48,
63
- 57, 65, 90, 32, 36, 95, 45, 46, 48, 57, 65, 90,
64
- 32, 36, 95, 45, 46, 48, 57, 65, 90, 32, 36, 95,
65
- 45, 46, 48, 57, 65, 90, 32, 36, 95, 45, 46, 48,
66
- 57, 65, 90, 32, 36, 95, 45, 46, 48, 57, 65, 90,
67
- 32, 36, 95, 45, 46, 48, 57, 65, 90, 32, 36, 95,
68
- 45, 46, 48, 57, 65, 90, 32, 36, 95, 45, 46, 48,
69
- 57, 65, 90, 32, 36, 95, 45, 46, 48, 57, 65, 90,
70
- 32, 36, 95, 45, 46, 48, 57, 65, 90, 32, 36, 95,
71
- 45, 46, 48, 57, 65, 90, 32, 36, 95, 45, 46, 48,
72
- 57, 65, 90, 32, 36, 95, 45, 46, 48, 57, 65, 90,
73
- 32, 36, 95, 45, 46, 48, 57, 65, 90, 32, 36, 95,
74
- 45, 46, 48, 57, 65, 90, 32, 36, 95, 45, 46, 48,
75
- 57, 65, 90, 32, 36, 95, 45, 46, 48, 57, 65, 90,
76
- 32, 0
60
+ 60, 62, 127, 0, 31, 32, 34, 35, 60, 62, 63, 92,
61
+ 96, 123, 125, 127, 0, 31, 32, 34, 35, 60, 62, 127,
62
+ 0, 31, 32, 34, 35, 60, 62, 127, 0, 31, 32, 36,
63
+ 95, 45, 46, 48, 57, 65, 90, 32, 36, 95, 45, 46,
64
+ 48, 57, 65, 90, 32, 36, 95, 45, 46, 48, 57, 65,
65
+ 90, 32, 36, 95, 45, 46, 48, 57, 65, 90, 32, 36,
66
+ 95, 45, 46, 48, 57, 65, 90, 32, 36, 95, 45, 46,
67
+ 48, 57, 65, 90, 32, 36, 95, 45, 46, 48, 57, 65,
68
+ 90, 32, 36, 95, 45, 46, 48, 57, 65, 90, 32, 36,
69
+ 95, 45, 46, 48, 57, 65, 90, 32, 36, 95, 45, 46,
70
+ 48, 57, 65, 90, 32, 36, 95, 45, 46, 48, 57, 65,
71
+ 90, 32, 36, 95, 45, 46, 48, 57, 65, 90, 32, 36,
72
+ 95, 45, 46, 48, 57, 65, 90, 32, 36, 95, 45, 46,
73
+ 48, 57, 65, 90, 32, 36, 95, 45, 46, 48, 57, 65,
74
+ 90, 32, 36, 95, 45, 46, 48, 57, 65, 90, 32, 36,
75
+ 95, 45, 46, 48, 57, 65, 90, 32, 36, 95, 45, 46,
76
+ 48, 57, 65, 90, 32, 0
77
77
  };
78
78
  }
79
79
 
@@ -85,7 +85,7 @@ private static byte[] init__puma_parser_single_lengths_0()
85
85
  return new byte [] {
86
86
  0, 2, 3, 4, 2, 1, 1, 1, 1, 1, 0, 1,
87
87
  0, 1, 1, 4, 1, 4, 3, 2, 4, 4, 2, 6,
88
- 7, 6, 6, 3, 3, 3, 3, 3, 3, 3, 3, 3,
88
+ 11, 6, 6, 3, 3, 3, 3, 3, 3, 3, 3, 3,
89
89
  3, 3, 3, 3, 3, 3, 3, 3, 3, 1, 0
90
90
  };
91
91
  }
@@ -111,8 +111,8 @@ private static short[] init__puma_parser_index_offsets_0()
111
111
  return new short [] {
112
112
  0, 0, 6, 13, 21, 24, 26, 28, 30, 32, 34, 36,
113
113
  39, 41, 44, 46, 57, 59, 70, 76, 81, 88, 95, 102,
114
- 110, 119, 127, 135, 142, 149, 156, 163, 170, 177, 184, 191,
115
- 198, 205, 212, 219, 226, 233, 240, 247, 254, 261, 263
114
+ 110, 123, 131, 139, 146, 153, 160, 167, 174, 181, 188, 195,
115
+ 202, 209, 216, 223, 230, 237, 244, 251, 258, 265, 267
116
116
  };
117
117
  }
118
118
 
@@ -131,20 +131,20 @@ private static byte[] init__puma_parser_indicies_0()
131
131
  1, 1, 1, 25, 29, 1, 1, 1, 28, 30, 1, 1,
132
132
  1, 1, 1, 31, 32, 1, 1, 1, 1, 1, 33, 34,
133
133
  35, 34, 34, 34, 34, 1, 8, 1, 9, 1, 1, 1,
134
- 1, 35, 36, 1, 38, 1, 1, 39, 1, 1, 37, 40,
135
- 1, 42, 1, 1, 1, 1, 41, 43, 1, 45, 1, 1,
136
- 1, 1, 44, 2, 46, 46, 46, 46, 46, 1, 2, 47,
137
- 47, 47, 47, 47, 1, 2, 48, 48, 48, 48, 48, 1,
138
- 2, 49, 49, 49, 49, 49, 1, 2, 50, 50, 50, 50,
139
- 50, 1, 2, 51, 51, 51, 51, 51, 1, 2, 52, 52,
140
- 52, 52, 52, 1, 2, 53, 53, 53, 53, 53, 1, 2,
141
- 54, 54, 54, 54, 54, 1, 2, 55, 55, 55, 55, 55,
142
- 1, 2, 56, 56, 56, 56, 56, 1, 2, 57, 57, 57,
143
- 57, 57, 1, 2, 58, 58, 58, 58, 58, 1, 2, 59,
144
- 59, 59, 59, 59, 1, 2, 60, 60, 60, 60, 60, 1,
145
- 2, 61, 61, 61, 61, 61, 1, 2, 62, 62, 62, 62,
146
- 62, 1, 2, 63, 63, 63, 63, 63, 1, 2, 1, 1,
147
- 0
134
+ 1, 35, 36, 1, 38, 1, 1, 39, 1, 1, 1, 1,
135
+ 1, 1, 37, 40, 1, 42, 1, 1, 1, 1, 41, 43,
136
+ 1, 45, 1, 1, 1, 1, 44, 2, 46, 46, 46, 46,
137
+ 46, 1, 2, 47, 47, 47, 47, 47, 1, 2, 48, 48,
138
+ 48, 48, 48, 1, 2, 49, 49, 49, 49, 49, 1, 2,
139
+ 50, 50, 50, 50, 50, 1, 2, 51, 51, 51, 51, 51,
140
+ 1, 2, 52, 52, 52, 52, 52, 1, 2, 53, 53, 53,
141
+ 53, 53, 1, 2, 54, 54, 54, 54, 54, 1, 2, 55,
142
+ 55, 55, 55, 55, 1, 2, 56, 56, 56, 56, 56, 1,
143
+ 2, 57, 57, 57, 57, 57, 1, 2, 58, 58, 58, 58,
144
+ 58, 1, 2, 59, 59, 59, 59, 59, 1, 2, 60, 60,
145
+ 60, 60, 60, 1, 2, 61, 61, 61, 61, 61, 1, 2,
146
+ 62, 62, 62, 62, 62, 1, 2, 63, 63, 63, 63, 63,
147
+ 1, 2, 1, 1, 0
148
148
  };
149
149
  }
150
150
 
@@ -383,36 +383,41 @@ public class MiniSSL extends RubyObject { // MiniSSL::Engine
383
383
  }
384
384
 
385
385
  MiniSSLBuffer inboundAppData = new MiniSSLBuffer(engine.getSession().getApplicationBufferSize());
386
- doOp(SSLOperation.UNWRAP, inboundNetData, inboundAppData);
387
-
388
- HandshakeStatus handshakeStatus = engine.getHandshakeStatus();
389
- boolean done = false;
390
- while (!done) {
391
- SSLEngineResult res;
392
- switch (handshakeStatus) {
393
- case NEED_WRAP:
394
- res = doOp(SSLOperation.WRAP, inboundAppData, outboundNetData);
395
- handshakeStatus = res.getHandshakeStatus();
396
- break;
397
- case NEED_UNWRAP:
398
- res = doOp(SSLOperation.UNWRAP, inboundNetData, inboundAppData);
399
- if (res.getStatus() == Status.BUFFER_UNDERFLOW) {
400
- // need more data before we can shake more hands
386
+ int consumedTo;
387
+ do {
388
+ consumedTo = inboundNetData.position();
389
+ doOp(SSLOperation.UNWRAP, inboundNetData, inboundAppData);
390
+
391
+ HandshakeStatus handshakeStatus = engine.getHandshakeStatus();
392
+ boolean done = false;
393
+ while (!done) {
394
+ SSLEngineResult res;
395
+ switch (handshakeStatus) {
396
+ case NEED_WRAP:
397
+ res = doOp(SSLOperation.WRAP, inboundAppData, outboundNetData);
398
+ handshakeStatus = res.getHandshakeStatus();
399
+ break;
400
+ case NEED_UNWRAP:
401
+ res = doOp(SSLOperation.UNWRAP, inboundNetData, inboundAppData);
402
+ if (res.getStatus() == Status.BUFFER_UNDERFLOW) {
403
+ // need more data before we can shake more hands
404
+ done = true;
405
+ }
406
+ handshakeStatus = res.getHandshakeStatus();
407
+ break;
408
+ case NEED_TASK:
409
+ Runnable runnable;
410
+ while ((runnable = engine.getDelegatedTask()) != null) {
411
+ runnable.run();
412
+ }
413
+ handshakeStatus = engine.getHandshakeStatus();
414
+ break;
415
+ default:
401
416
  done = true;
402
- }
403
- handshakeStatus = res.getHandshakeStatus();
404
- break;
405
- case NEED_TASK:
406
- Runnable runnable;
407
- while ((runnable = engine.getDelegatedTask()) != null) {
408
- runnable.run();
409
- }
410
- handshakeStatus = engine.getHandshakeStatus();
411
- break;
412
- default:
413
- done = true;
417
+ }
414
418
  }
415
- }
419
+ } while (inboundAppData.position() == 0 && !closed &&
420
+ inboundNetData.hasRemaining() && inboundNetData.position() > consumedTo);
416
421
 
417
422
  if (inboundNetData.hasRemaining()) {
418
423
  inboundNetData.compact();
@@ -482,14 +487,19 @@ public class MiniSSL extends RubyObject { // MiniSSL::Engine
482
487
 
483
488
  @JRubyMethod
484
489
  public IRubyObject shutdown() {
485
- if (closed || engine.isInboundDone() && engine.isOutboundDone()) {
486
- if (engine.isOutboundDone()) {
487
- engine.closeOutbound();
488
- }
490
+ // The peer may be speaking plain HTTP if the handshake did not finish.
491
+ if (closed || !handshake || engine.isInboundDone() && engine.isOutboundDone()) {
492
+ return getRuntime().getTrue();
493
+ }
494
+
495
+ // Generate close_notify for MiniSSL::Socket#close to send.
496
+ engine.closeOutbound();
497
+ try {
498
+ doOp(SSLOperation.WRAP, outboundAppData, outboundNetData);
499
+ } catch (SSLException e) {
489
500
  return getRuntime().getTrue();
490
- } else {
491
- return getRuntime().getFalse();
492
501
  }
502
+ return getRuntime().getFalse();
493
503
  }
494
504
 
495
505
  private static RubyClass getSSLError(Ruby runtime) {
@@ -13,6 +13,10 @@
13
13
  #include <ctype.h>
14
14
  #include "http11_parser.h"
15
15
 
16
+ #ifdef HAVE_PRCTL
17
+ #include <sys/prctl.h>
18
+ #endif
19
+
16
20
  #define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
17
21
 
18
22
  static VALUE eHttpParserError;
@@ -385,7 +389,8 @@ static VALUE HttpParser_execute(VALUE self, VALUE req_hash, VALUE data, VALUE st
385
389
  long dlen = 0;
386
390
 
387
391
  from = FIX2INT(start);
388
- RSTRING_GETMEM(data, dptr, dlen);
392
+ dptr = RSTRING_PTR(data);
393
+ dlen = (long)RSTRING_LEN(data);
389
394
 
390
395
  if(from >= dlen) {
391
396
  rb_raise(eHttpParserError, "%s", "Requested start is after data buffer end.");
@@ -398,7 +403,7 @@ static VALUE HttpParser_execute(VALUE self, VALUE req_hash, VALUE data, VALUE st
398
403
  if(puma_parser_has_error(http)) {
399
404
  rb_raise(eHttpParserError, "%s", "Invalid HTTP format, parsing fails. Are you trying to open an SSL connection to a non-SSL Puma?");
400
405
  } else {
401
- return INT2FIX(puma_parser_nread(http));
406
+ return SIZET2NUM(puma_parser_nread(http));
402
407
  }
403
408
  }
404
409
  }
@@ -444,7 +449,7 @@ static VALUE HttpParser_nread(VALUE self)
444
449
  {
445
450
  puma_parser *http = HttpParser_unwrap(self);
446
451
 
447
- return INT2FIX(http->nread);
452
+ return SIZET2NUM(http->nread);
448
453
  }
449
454
 
450
455
  /**
@@ -459,6 +464,24 @@ static VALUE HttpParser_body(VALUE self) {
459
464
  return http->body;
460
465
  }
461
466
 
467
+ /**
468
+ * call-seq:
469
+ * Puma.enable_child_subreaper -> true or false
470
+ *
471
+ * Marks the calling process as a child subreaper so that orphaned descendants
472
+ * are reparented to it. Returns false where this is unsupported.
473
+ */
474
+ static VALUE Puma_enable_child_subreaper(VALUE self) {
475
+ #ifdef HAVE_PRCTL
476
+ if (prctl(PR_SET_CHILD_SUBREAPER, 1) < 0) {
477
+ rb_sys_fail("prctl(PR_SET_CHILD_SUBREAPER)");
478
+ }
479
+ return Qtrue;
480
+ #else
481
+ return Qfalse;
482
+ #endif
483
+ }
484
+
462
485
  #ifdef HAVE_OPENSSL_BIO_H
463
486
  void Init_mini_ssl(VALUE mod);
464
487
  #endif
@@ -482,6 +505,8 @@ RUBY_FUNC_EXPORTED void Init_puma_http11(void)
482
505
  rb_global_variable(&eHttpParserError);
483
506
  eHttpParserError = rb_define_class_under(mPuma, "HttpParserError", rb_eStandardError);
484
507
 
508
+ rb_define_singleton_method(mPuma, "enable_child_subreaper", Puma_enable_child_subreaper, 0);
509
+
485
510
  rb_define_alloc_func(cHttpParser, HttpParser_alloc);
486
511
  rb_define_method(cHttpParser, "initialize", HttpParser_init, 0);
487
512
  rb_define_method(cHttpParser, "reset", HttpParser_reset, 0);
data/lib/puma/binder.rb CHANGED
@@ -309,6 +309,13 @@ module Puma
309
309
  end
310
310
  end
311
311
 
312
+ # Removes and returns the activated socket for +url+ as <tt>[key, socket]</tt>,
313
+ # or +nil+ if none was activated for it.
314
+ def take_activated_socket(url)
315
+ key = activated_keys_for(url).find { |k| @activated_sockets.key?(k) }
316
+ [key, @activated_sockets.delete(key)] if key
317
+ end
318
+
312
319
  def localhost_authority
313
320
  @localhost_authority ||= Localhost::Authority.fetch if defined?(Localhost::Authority) && !Puma::IS_JRUBY
314
321
  end
@@ -486,6 +493,28 @@ module Puma
486
493
 
487
494
  private
488
495
 
496
+ def activated_keys_for(url)
497
+ uri = URI.parse url
498
+ case uri.scheme
499
+ when "tcp", "ssl"
500
+ [[:tcp, uri.host, uri.port]]
501
+ when "unix"
502
+ path = "#{uri.host}#{uri.path}".gsub("%20", " ")
503
+ return [] if path.start_with?("@")
504
+
505
+ real_path = begin
506
+ File.realdirpath(path)
507
+ rescue SystemCallError
508
+ path
509
+ end
510
+ [[:unix, path], [:unix, real_path]].uniq
511
+ else
512
+ []
513
+ end
514
+ rescue URI::InvalidURIError
515
+ []
516
+ end
517
+
489
518
  # @!attribute [r] loopback_addresses
490
519
  def loopback_addresses
491
520
  t = Socket.ip_address_list.select do |addrinfo|
data/lib/puma/cli.rb CHANGED
@@ -138,6 +138,12 @@ module Puma
138
138
  user_config.fork_worker(*args.compact)
139
139
  end
140
140
 
141
+ o.on "--mold-worker=[REQUESTS]", Array,
142
+ "Fork new workers from a mold promoted from an existing worker. Cluster mode only",
143
+ "Promote a new mold at each comma-separated REQUESTS threshold (default 1000)" do |thresholds|
144
+ user_config.mold_worker(*thresholds)
145
+ end
146
+
141
147
  o.on "-I", "--include PATH", "Specify $LOAD_PATH directories" do |arg|
142
148
  $LOAD_PATH.unshift(*arg.split(':'))
143
149
  end