connection_pool 2.3.0 → 2.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Changes.md +5 -0
- data/README.md +1 -1
- data/lib/connection_pool/version.rb +1 -1
- data/lib/connection_pool.rb +45 -3
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e87682a6e57e8b0214de9c0713a7466a2b06399dc52d700fbf182cdf9e5b6606
|
4
|
+
data.tar.gz: d12337513b62d4677663403c512afad165275bdf848987182ce03637a1de6482
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eca2c1f8ebe52039f00df70ddfe5525cc0408acd8ae9849a8d1412bec670e7d3a05d3609db933e3e906cd83307d39f754dd5f1d7b48b50b847090b5bf485b55a
|
7
|
+
data.tar.gz: fc9a62b4b0ba5a406543e8f6399bd566f2f31c6c9a6ce2772e3550c1c2a75945c8a34defeda10c83e23cbfe5fe50d0e8861f57ea23935d7c97540aa97b04a635
|
data/Changes.md
CHANGED
data/README.md
CHANGED
@@ -48,7 +48,7 @@ end
|
|
48
48
|
|
49
49
|
This will only modify the resource-get timeout for this particular
|
50
50
|
invocation.
|
51
|
-
This is useful if you want to fail-fast on certain non
|
51
|
+
This is useful if you want to fail-fast on certain non-critical
|
52
52
|
sections when a resource is not available, or conversely if you are comfortable blocking longer on a particular resource.
|
53
53
|
This is not implemented in the `ConnectionPool::Wrapper` class.
|
54
54
|
|
data/lib/connection_pool.rb
CHANGED
@@ -44,6 +44,47 @@ class ConnectionPool
|
|
44
44
|
Wrapper.new(options, &block)
|
45
45
|
end
|
46
46
|
|
47
|
+
if Process.respond_to?(:fork)
|
48
|
+
INSTANCES = ObjectSpace::WeakMap.new
|
49
|
+
private_constant :INSTANCES
|
50
|
+
|
51
|
+
def self.after_fork
|
52
|
+
INSTANCES.values.each do |pool|
|
53
|
+
# We're on after fork, so we know all other threads are dead.
|
54
|
+
# All we need to do is to ensure the main thread doesn't have a
|
55
|
+
# checked out connection
|
56
|
+
pool.checkin(force: true)
|
57
|
+
|
58
|
+
pool.reload do |connection|
|
59
|
+
# Unfortunately we don't know what method to call to close the connection,
|
60
|
+
# so we try the most common one.
|
61
|
+
connection.close if connection.respond_to?(:close)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
nil
|
65
|
+
end
|
66
|
+
|
67
|
+
if ::Process.respond_to?(:_fork) # MRI 3.1+
|
68
|
+
module ForkTracker
|
69
|
+
def _fork
|
70
|
+
pid = super
|
71
|
+
if pid == 0
|
72
|
+
ConnectionPool.after_fork
|
73
|
+
end
|
74
|
+
pid
|
75
|
+
end
|
76
|
+
end
|
77
|
+
Process.singleton_class.prepend(ForkTracker)
|
78
|
+
end
|
79
|
+
else
|
80
|
+
INSTANCES = nil
|
81
|
+
private_constant :INSTANCES
|
82
|
+
|
83
|
+
def self.after_fork
|
84
|
+
# noop
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
47
88
|
def initialize(options = {}, &block)
|
48
89
|
raise ArgumentError, "Connection pool requires a block" unless block
|
49
90
|
|
@@ -55,6 +96,7 @@ class ConnectionPool
|
|
55
96
|
@available = TimedStack.new(@size, &block)
|
56
97
|
@key = :"pool-#{@available.object_id}"
|
57
98
|
@key_count = :"pool-#{@available.object_id}-count"
|
99
|
+
INSTANCES[self] = self if INSTANCES
|
58
100
|
end
|
59
101
|
|
60
102
|
def with(options = {})
|
@@ -81,16 +123,16 @@ class ConnectionPool
|
|
81
123
|
end
|
82
124
|
end
|
83
125
|
|
84
|
-
def checkin
|
126
|
+
def checkin(force: false)
|
85
127
|
if ::Thread.current[@key]
|
86
|
-
if ::Thread.current[@key_count] == 1
|
128
|
+
if ::Thread.current[@key_count] == 1 || force
|
87
129
|
@available.push(::Thread.current[@key])
|
88
130
|
::Thread.current[@key] = nil
|
89
131
|
::Thread.current[@key_count] = nil
|
90
132
|
else
|
91
133
|
::Thread.current[@key_count] -= 1
|
92
134
|
end
|
93
|
-
|
135
|
+
elsif !force
|
94
136
|
raise ConnectionPool::Error, "no connections are checked out"
|
95
137
|
end
|
96
138
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: connection_pool
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Perham
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2023-03-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -88,7 +88,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
88
88
|
- !ruby/object:Gem::Version
|
89
89
|
version: '0'
|
90
90
|
requirements: []
|
91
|
-
rubygems_version: 3.
|
91
|
+
rubygems_version: 3.4.7
|
92
92
|
signing_key:
|
93
93
|
specification_version: 4
|
94
94
|
summary: Generic connection pool for Ruby
|