rails-pg-adapter 0.1.5 → 0.1.7

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 432740419d2edda4a33caf34ba5efa2af778456763db8864c632b3d813f1953e
4
- data.tar.gz: 60a026760c20847ace00bf181878c0039eface04fa30ff51227e677be88f95c0
3
+ metadata.gz: b13533de6e67440feaaee7799c583984672793b16b10aee60ca89091cadef545
4
+ data.tar.gz: e6927d01f1604871d426d8fa894dc400ac3626191c151b034b12771ee68b91ac
5
5
  SHA512:
6
- metadata.gz: 5fb1aac2ec7330a599cc9005d339fab13613b409cf37152a003826b760c02b8b4060b0134d50799be4db7d77e6db4165b6ef99d0b1df0399133749f4746c5a25
7
- data.tar.gz: 0450d73b3e3330da51c01d64a922828da6b32fe1d500d2c719ee40bd5dbbc2ac2c40d87cc93bc3a8a53676c3476f61180684a6bf05cf301d876f393eab6b5bee
6
+ metadata.gz: d60b542abec512d9f5d1567f65d4327e3bc299d8ac740616fbec5aeb394f612698db6c74f5a462640cd96bdb1fb7013ff433f28780ef5cb5c3c0157ca0fa10b4
7
+ data.tar.gz: 16bbac80afd152b275c451243331318be772c88b9dcce2ddb1eb30be5875556f489b476b55e3b34ec618e6047a00405ca6d9caa73729d83d480101c1849a0ec8
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## [0.1.7] - 2023-04-21
2
+
3
+ - Simplify connection management and introduce upper bound to retries
4
+
5
+ ## [0.1.6] - 2023-04-19
6
+
7
+ - Disconnect and remove connection when in read-only
8
+
1
9
  ## [0.1.5] - 2023-04-19
2
10
 
3
11
  - Retry queries when not in transaction
@@ -13,6 +13,7 @@ module RailsPgAdapter
13
13
  "the database system is starting up",
14
14
  "connection is closed",
15
15
  "could not connect",
16
+ "is not currently accepting connections",
16
17
  ].freeze
17
18
  CONNECTION_ERROR_RE = /#{CONNECTION_ERROR.map { |w| Regexp.escape(w) }.join("|")}/.freeze
18
19
 
@@ -22,19 +23,45 @@ module RailsPgAdapter
22
23
  private
23
24
 
24
25
  def exec_cache(*args)
25
- super(*args)
26
- rescue ::ActiveRecord::StatementInvalid, ::ActiveRecord::ConnectionNotEstablished => e
27
- raise unless supported_errors?(e)
28
-
29
- try_reconnect?(e) ? retry : handle_error(e)
26
+ sleep_times = RailsPgAdapter.configuration.reconnect_with_backoff.dup
27
+ begin
28
+ super(*args)
29
+ rescue ::ActiveRecord::StatementInvalid,
30
+ ::ActiveRecord::ConnectionNotEstablished,
31
+ ::ActiveRecord::NoDatabaseError => e
32
+ raise unless supported_errors?(e)
33
+
34
+ if try_reconnect?(e)
35
+ sleep_time = sleep_times.shift
36
+ handle_error(e) unless sleep_time
37
+ warn("Retry query failed, retrying again in #{sleep_time} sec.")
38
+ sleep(sleep_time)
39
+ retry
40
+ else
41
+ handle_error(e)
42
+ end
43
+ end
30
44
  end
31
45
 
32
46
  def exec_no_cache(*args)
33
- super(*args)
34
- rescue ::ActiveRecord::StatementInvalid, ::ActiveRecord::ConnectionNotEstablished => e
35
- raise unless supported_errors?(e)
36
-
37
- try_reconnect?(e) ? retry : handle_error(e)
47
+ sleep_times = RailsPgAdapter.configuration.reconnect_with_backoff.dup
48
+ begin
49
+ super(*args)
50
+ rescue ::ActiveRecord::StatementInvalid,
51
+ ::ActiveRecord::ConnectionNotEstablished,
52
+ ::ActiveRecord::NoDatabaseError => e
53
+ raise unless supported_errors?(e)
54
+
55
+ if try_reconnect?(e)
56
+ sleep_time = sleep_times.shift
57
+ handle_error(e) unless sleep_time
58
+ warn("Retry query failed, retrying again in #{sleep_time} sec.")
59
+ sleep(sleep_time)
60
+ retry
61
+ else
62
+ handle_error(e)
63
+ end
64
+ end
38
65
  end
39
66
 
40
67
  def try_reconnect?(e)
@@ -43,7 +70,7 @@ module RailsPgAdapter
43
70
  return false unless RailsPgAdapter.reconnect_with_backoff?
44
71
 
45
72
  begin
46
- reconnect!
73
+ disconnect_conn!
47
74
  true
48
75
  rescue ::ActiveRecord::ConnectionNotEstablished
49
76
  false
@@ -53,11 +80,13 @@ module RailsPgAdapter
53
80
  def handle_error(e)
54
81
  if failover_error?(e.message) && RailsPgAdapter.failover_patch?
55
82
  warn("clearing connections due to #{e} - #{e.message}")
56
- disconnect_and_remove_conn!
83
+ disconnect_conn!
57
84
  raise(e)
58
85
  end
59
86
 
60
- return unless missing_column_error?(e.message) && RailsPgAdapter.reset_column_information_patch?
87
+ unless missing_column_error?(e.message) && RailsPgAdapter.reset_column_information_patch?
88
+ return
89
+ end
61
90
 
62
91
  warn("clearing column information due to #{e} - #{e.message}")
63
92
 
@@ -73,7 +102,7 @@ module RailsPgAdapter
73
102
  CONNECTION_SCHEMA_RE.match?(error_message)
74
103
  end
75
104
 
76
- def disconnect_and_remove_conn!
105
+ def disconnect_conn!
77
106
  disconnect!
78
107
  ::ActiveRecord::Base.connection_pool.remove(::ActiveRecord::Base.connection)
79
108
  end
@@ -112,12 +141,12 @@ module ActiveRecord
112
141
  sleep_times = RailsPgAdapter.configuration.reconnect_with_backoff.dup
113
142
  begin
114
143
  old_new_client_method.bind(self).call(args)
115
- rescue ::ActiveRecord::ConnectionNotEstablished => e
144
+ rescue ::ActiveRecord::ConnectionNotEstablished, ::ActiveRecord::NoDatabaseError => e
116
145
  raise(e) unless RailsPgAdapter.failover_patch? && RailsPgAdapter.reconnect_with_backoff?
117
146
 
118
147
  sleep_time = sleep_times.shift
119
148
  raise unless sleep_time
120
- warn( "Could not establish a connection from new_client, retrying again in #{sleep_time} sec.")
149
+ warn("Could not establish a connection from new_client, retrying again in #{sleep_time} sec.")
121
150
  sleep(sleep_time)
122
151
  retry
123
152
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailsPgAdapter
4
- VERSION = "0.1.5"
4
+ VERSION = "0.1.7"
5
5
  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.5
4
+ version: 0.1.7
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-19 00:00:00.000000000 Z
11
+ date: 2023-04-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails