slowpoke 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -1
- data/README.md +26 -5
- data/lib/generators/slowpoke/templates/503.html +6 -6
- data/lib/slowpoke.rb +24 -0
- data/lib/slowpoke/middleware.rb +5 -13
- data/lib/slowpoke/railtie.rb +1 -1
- data/lib/slowpoke/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 79e082a34ab895956d7086764a63dc6f4dbedeee15f7557f727a5b23fa51ad08
|
4
|
+
data.tar.gz: e7b7aa0452587608fbf2a03f4dad9289562b9ece95a07fc98cf526e9ac3cfb5f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4e4d9eee0e505d0163b1d34e7a8a34b35f399261cacb216d422478b0a81d7637b54a967749d4feb8de04ff40e03ef88f6cb066dbed6fbdf168851e454aaed343
|
7
|
+
data.tar.gz: c2fb32575fc524033c39dc351022421da93cb928747251f463c53b6352adeca75ce635d02dbd35587af8c8b5e5a9d5e5092de798afab6171364ceaf9af7c7bee
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -2,9 +2,9 @@
|
|
2
2
|
|
3
3
|
[Rack::Timeout](https://github.com/heroku/rack-timeout) enhancements for Rails
|
4
4
|
|
5
|
-
-
|
5
|
+
- safer service timeouts
|
6
|
+
- dynamic timeouts
|
6
7
|
- custom error pages
|
7
|
-
- [safer service timeouts](https://github.com/heroku/rack-timeout/issues/39)
|
8
8
|
|
9
9
|
## Installation
|
10
10
|
|
@@ -47,7 +47,7 @@ The default timeout is 15 seconds. You can change this in `config/environments/p
|
|
47
47
|
config.slowpoke.timeout = 5
|
48
48
|
```
|
49
49
|
|
50
|
-
For
|
50
|
+
For dynamic timeouts, use:
|
51
51
|
|
52
52
|
```ruby
|
53
53
|
config.slowpoke.timeout = lambda do |env|
|
@@ -66,9 +66,30 @@ end
|
|
66
66
|
|
67
67
|
To learn more, see the [Rack::Timeout documentation](https://github.com/heroku/rack-timeout).
|
68
68
|
|
69
|
-
##
|
69
|
+
## Safer Service Timeouts
|
70
70
|
|
71
|
-
|
71
|
+
Rack::Timeout can raise an exception at any point in the code, which can leave your app in an [unclean state](https://www.schneems.com/2017/02/21/the-oldest-bug-in-ruby-why-racktimeout-might-hose-your-server/). The safest way to recover from a request timeout is to spawn a new process. This is the default behavior for Slowpoke.
|
72
|
+
|
73
|
+
For threaded servers like Puma, this means killing all threads when any one of them times out. This can have a significant impact on performance.
|
74
|
+
|
75
|
+
You can customize this behavior with:
|
76
|
+
|
77
|
+
```ruby
|
78
|
+
Slowpoke.on_timeout do |env|
|
79
|
+
next if Rails.env.development? || Rails.env.test?
|
80
|
+
|
81
|
+
exception = env["action_dispatch.exception"]
|
82
|
+
if exception && exception.backtrace.first.include?("/active_record/")
|
83
|
+
Slowpoke.kill
|
84
|
+
end
|
85
|
+
end
|
86
|
+
```
|
87
|
+
|
88
|
+
Note: To access `env["action_dispatch.exception"]` in development, temporarily add to `config/environments/development.rb`:
|
89
|
+
|
90
|
+
```ruby
|
91
|
+
config.consider_all_requests_local = false
|
92
|
+
```
|
72
93
|
|
73
94
|
## Database Timeouts
|
74
95
|
|
@@ -4,7 +4,7 @@
|
|
4
4
|
<title>This page took too long to load (503)</title>
|
5
5
|
<meta name="viewport" content="width=device-width,initial-scale=1">
|
6
6
|
<style>
|
7
|
-
|
7
|
+
.rails-default-error-page {
|
8
8
|
background-color: #EFEFEF;
|
9
9
|
color: #2E2F30;
|
10
10
|
text-align: center;
|
@@ -12,13 +12,13 @@
|
|
12
12
|
margin: 0;
|
13
13
|
}
|
14
14
|
|
15
|
-
div.dialog {
|
15
|
+
.rails-default-error-page div.dialog {
|
16
16
|
width: 95%;
|
17
17
|
max-width: 33em;
|
18
18
|
margin: 4em auto 0;
|
19
19
|
}
|
20
20
|
|
21
|
-
div.dialog > div {
|
21
|
+
.rails-default-error-page div.dialog > div {
|
22
22
|
border: 1px solid #CCC;
|
23
23
|
border-right-color: #999;
|
24
24
|
border-left-color: #999;
|
@@ -31,13 +31,13 @@
|
|
31
31
|
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
32
32
|
}
|
33
33
|
|
34
|
-
h1 {
|
34
|
+
.rails-default-error-page h1 {
|
35
35
|
font-size: 100%;
|
36
36
|
color: #730E15;
|
37
37
|
line-height: 1.5em;
|
38
38
|
}
|
39
39
|
|
40
|
-
div.dialog > p {
|
40
|
+
.rails-default-error-page div.dialog > p {
|
41
41
|
margin: 0 0 1em;
|
42
42
|
padding: 1em;
|
43
43
|
background-color: #F7F7F7;
|
@@ -54,7 +54,7 @@
|
|
54
54
|
</style>
|
55
55
|
</head>
|
56
56
|
|
57
|
-
<body>
|
57
|
+
<body class="rails-default-error-page">
|
58
58
|
<!-- This file lives in public/503.html -->
|
59
59
|
<div class="dialog">
|
60
60
|
<div>
|
data/lib/slowpoke.rb
CHANGED
@@ -9,6 +9,30 @@ require "slowpoke/version"
|
|
9
9
|
|
10
10
|
module Slowpoke
|
11
11
|
ENV_KEY = "slowpoke.timed_out".freeze
|
12
|
+
|
13
|
+
def self.kill
|
14
|
+
if defined?(::PhusionPassenger)
|
15
|
+
`passenger-config detach-process #{Process.pid}`
|
16
|
+
elsif defined?(::Puma)
|
17
|
+
Process.kill("TERM", Process.pid)
|
18
|
+
else
|
19
|
+
Process.kill("QUIT", Process.pid)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.on_timeout(&block)
|
24
|
+
if block_given?
|
25
|
+
@on_timeout = block
|
26
|
+
else
|
27
|
+
@on_timeout
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
on_timeout do |env|
|
32
|
+
next if Rails.env.development? || Rails.env.test?
|
33
|
+
|
34
|
+
Slowpoke.kill
|
35
|
+
end
|
12
36
|
end
|
13
37
|
|
14
38
|
# remove noisy logger
|
data/lib/slowpoke/middleware.rb
CHANGED
@@ -7,19 +7,11 @@ module Slowpoke
|
|
7
7
|
def call(env)
|
8
8
|
@app.call(env)
|
9
9
|
ensure
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
if defined?(::PhusionPassenger)
|
16
|
-
`passenger-config detach-process #{Process.pid}`
|
17
|
-
elsif defined?(::Puma)
|
18
|
-
Process.kill("TERM", Process.pid)
|
19
|
-
else
|
20
|
-
Process.kill("QUIT", Process.pid)
|
21
|
-
end
|
22
|
-
end
|
10
|
+
# extremely important
|
11
|
+
# protect the process with a restart
|
12
|
+
# https://github.com/heroku/rack-timeout/issues/39
|
13
|
+
# can't do in timed_out state consistently
|
14
|
+
Slowpoke.on_timeout.call(env) if env[Slowpoke::ENV_KEY]
|
23
15
|
end
|
24
16
|
end
|
25
17
|
end
|
data/lib/slowpoke/railtie.rb
CHANGED
data/lib/slowpoke/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: slowpoke
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kane
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-12-
|
11
|
+
date: 2019-12-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|