rails-pg-adapter 0.1.7 → 0.1.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/lib/rails_pg_adapter/patch.rb +35 -30
- data/lib/rails_pg_adapter/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: 75fd0eeee68afb5b74ee0b5ab2b5ebcc931265c4633918c7b4677e58b2678a85
|
4
|
+
data.tar.gz: fd33f8cbef14a5817662ba9adceabc35245995515f7d8d22a0a92127a58cee91
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3c653f6457e09eb06f25abd20bdb756805e9dfacad132a036965ebce2f244a5f59b0d99599103f121f6df0d26455283719576eff224906a2c636dcb805c058b3
|
7
|
+
data.tar.gz: 65dc3285ad45a51fbb77022f3b892f5cf00281e188561c16d58180c99e8f6b2c80bc66fe7b7ef6b663a0c6f25197dd20bd88b4414ef35a9862dcc7bd118a67c8
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
## [0.1.9] - 2023-05-04
|
2
|
+
|
3
|
+
- Retry on too many connections error as well
|
4
|
+
|
5
|
+
## [0.1.8] - 2023-04-28
|
6
|
+
|
7
|
+
- Make retry on ActiveRecord::NoDatabaseError stricter
|
8
|
+
|
1
9
|
## [0.1.7] - 2023-04-21
|
2
10
|
|
3
11
|
- Simplify connection management and introduce upper bound to retries
|
@@ -14,22 +14,40 @@ module RailsPgAdapter
|
|
14
14
|
"connection is closed",
|
15
15
|
"could not connect",
|
16
16
|
"is not currently accepting connections",
|
17
|
+
"too many connections"
|
17
18
|
].freeze
|
18
19
|
CONNECTION_ERROR_RE = /#{CONNECTION_ERROR.map { |w| Regexp.escape(w) }.join("|")}/.freeze
|
19
20
|
|
20
21
|
CONNECTION_SCHEMA_ERROR = ["PG::UndefinedColumn"].freeze
|
21
22
|
CONNECTION_SCHEMA_RE = /#{CONNECTION_SCHEMA_ERROR.map { |w| Regexp.escape(w) }.join("|")}/.freeze
|
22
23
|
|
24
|
+
class << self
|
25
|
+
def supported_errors?(e)
|
26
|
+
return true if failover_error?(e.message)
|
27
|
+
return true if missing_column_error?(e.message)
|
28
|
+
false
|
29
|
+
end
|
30
|
+
|
31
|
+
def failover_error?(error_message)
|
32
|
+
CONNECTION_ERROR_RE.match?(error_message) && ::RailsPgAdapter.failover_patch?
|
33
|
+
end
|
34
|
+
|
35
|
+
def missing_column_error?(error_message)
|
36
|
+
CONNECTION_SCHEMA_RE.match?(error_message) &&
|
37
|
+
::RailsPgAdapter.reset_column_information_patch?
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
23
41
|
private
|
24
42
|
|
25
43
|
def exec_cache(*args)
|
26
|
-
sleep_times = RailsPgAdapter.configuration.reconnect_with_backoff.dup
|
44
|
+
sleep_times = ::RailsPgAdapter.configuration.reconnect_with_backoff.dup
|
27
45
|
begin
|
28
46
|
super(*args)
|
29
47
|
rescue ::ActiveRecord::StatementInvalid,
|
30
48
|
::ActiveRecord::ConnectionNotEstablished,
|
31
49
|
::ActiveRecord::NoDatabaseError => e
|
32
|
-
raise unless supported_errors?(e)
|
50
|
+
raise unless ::RailsPgAdapter::Patch.supported_errors?(e)
|
33
51
|
|
34
52
|
if try_reconnect?(e)
|
35
53
|
sleep_time = sleep_times.shift
|
@@ -44,13 +62,13 @@ module RailsPgAdapter
|
|
44
62
|
end
|
45
63
|
|
46
64
|
def exec_no_cache(*args)
|
47
|
-
sleep_times = RailsPgAdapter.configuration.reconnect_with_backoff.dup
|
65
|
+
sleep_times = ::RailsPgAdapter.configuration.reconnect_with_backoff.dup
|
48
66
|
begin
|
49
67
|
super(*args)
|
50
68
|
rescue ::ActiveRecord::StatementInvalid,
|
51
69
|
::ActiveRecord::ConnectionNotEstablished,
|
52
70
|
::ActiveRecord::NoDatabaseError => e
|
53
|
-
raise unless supported_errors?(e)
|
71
|
+
raise unless ::RailsPgAdapter::Patch.supported_errors?(e)
|
54
72
|
|
55
73
|
if try_reconnect?(e)
|
56
74
|
sleep_time = sleep_times.shift
|
@@ -66,8 +84,8 @@ module RailsPgAdapter
|
|
66
84
|
|
67
85
|
def try_reconnect?(e)
|
68
86
|
return false if in_transaction?
|
69
|
-
return false unless failover_error?(e.message)
|
70
|
-
return false unless RailsPgAdapter.reconnect_with_backoff?
|
87
|
+
return false unless ::RailsPgAdapter::Patch.failover_error?(e.message)
|
88
|
+
return false unless ::RailsPgAdapter.reconnect_with_backoff?
|
71
89
|
|
72
90
|
begin
|
73
91
|
disconnect_conn!
|
@@ -78,15 +96,13 @@ module RailsPgAdapter
|
|
78
96
|
end
|
79
97
|
|
80
98
|
def handle_error(e)
|
81
|
-
if failover_error?(e.message)
|
99
|
+
if ::RailsPgAdapter::Patch.failover_error?(e.message)
|
82
100
|
warn("clearing connections due to #{e} - #{e.message}")
|
83
101
|
disconnect_conn!
|
84
102
|
raise(e)
|
85
103
|
end
|
86
104
|
|
87
|
-
unless missing_column_error?(e.message)
|
88
|
-
return
|
89
|
-
end
|
105
|
+
return unless ::RailsPgAdapter::Patch.missing_column_error?(e.message)
|
90
106
|
|
91
107
|
warn("clearing column information due to #{e} - #{e.message}")
|
92
108
|
|
@@ -94,14 +110,6 @@ module RailsPgAdapter
|
|
94
110
|
raise
|
95
111
|
end
|
96
112
|
|
97
|
-
def failover_error?(error_message)
|
98
|
-
CONNECTION_ERROR_RE.match?(error_message)
|
99
|
-
end
|
100
|
-
|
101
|
-
def missing_column_error?(error_message)
|
102
|
-
CONNECTION_SCHEMA_RE.match?(error_message)
|
103
|
-
end
|
104
|
-
|
105
113
|
def disconnect_conn!
|
106
114
|
disconnect!
|
107
115
|
::ActiveRecord::Base.connection_pool.remove(::ActiveRecord::Base.connection)
|
@@ -115,15 +123,7 @@ module RailsPgAdapter
|
|
115
123
|
def warn(msg)
|
116
124
|
return unless defined?(Rails)
|
117
125
|
return if Rails.logger.nil?
|
118
|
-
::Rails.logger.warn("[RailsPgAdapter::Patch] #{msg}")
|
119
|
-
end
|
120
|
-
|
121
|
-
def supported_errors?(e)
|
122
|
-
return true if failover_error?(e.message) && RailsPgAdapter.failover_patch?
|
123
|
-
if missing_column_error?(e.message) && RailsPgAdapter.reset_column_information_patch?
|
124
|
-
return true
|
125
|
-
end
|
126
|
-
false
|
126
|
+
::Rails.logger.warn("[::RailsPgAdapter::Patch] #{msg}")
|
127
127
|
end
|
128
128
|
end
|
129
129
|
end
|
@@ -138,15 +138,20 @@ module ActiveRecord
|
|
138
138
|
old_new_client_method = instance_method(:new_client)
|
139
139
|
|
140
140
|
define_method(:new_client) do |args|
|
141
|
-
sleep_times = RailsPgAdapter.configuration.reconnect_with_backoff.dup
|
141
|
+
sleep_times = ::RailsPgAdapter.configuration.reconnect_with_backoff.dup
|
142
142
|
begin
|
143
143
|
old_new_client_method.bind(self).call(args)
|
144
144
|
rescue ::ActiveRecord::ConnectionNotEstablished, ::ActiveRecord::NoDatabaseError => e
|
145
|
-
|
145
|
+
unless ::RailsPgAdapter::Patch.supported_errors?(e) &&
|
146
|
+
::RailsPgAdapter.reconnect_with_backoff?
|
147
|
+
raise
|
148
|
+
end
|
146
149
|
|
147
150
|
sleep_time = sleep_times.shift
|
148
151
|
raise unless sleep_time
|
149
|
-
warn(
|
152
|
+
warn(
|
153
|
+
"Could not establish a connection from new_client, retrying again in #{sleep_time} sec.",
|
154
|
+
)
|
150
155
|
sleep(sleep_time)
|
151
156
|
retry
|
152
157
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails-pg-adapter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tines Engineering
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-04
|
11
|
+
date: 2023-05-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|