connection_pool 3.0.0 → 3.0.1
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 +4 -4
- data/Changes.md +5 -0
- data/connection_pool.gemspec +5 -2
- data/lib/connection_pool/fork.rb +40 -0
- data/lib/connection_pool/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: df5a1a8f1b7d70d93a4403456967159204d6fa5e1c963be3c9fb0eb4363dd2f5
|
|
4
|
+
data.tar.gz: 92788a9007f9bad4187a3d48060cd277c24b6f1e572ca43e84b2d83ae2574806
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 731dc286738cf2b2da51801b194ff169cf2124c9941b6867310accd77924a27ab0f7288ed5e9b1984e1fff9d8e112db5aae31beed2afafd1074d85c992c33dd1
|
|
7
|
+
data.tar.gz: 524a89e82d009395952aae23bc35724629e8d092679780394508821ab7073c9e43c9109229bce8cd8bd8b64a4538fcf235c0890cdf0494f9b673dc8b8d9b6a5e
|
data/Changes.md
CHANGED
data/connection_pool.gemspec
CHANGED
|
@@ -10,8 +10,11 @@ Gem::Specification.new do |s|
|
|
|
10
10
|
s.description = s.summary = "Generic connection pool for Ruby"
|
|
11
11
|
|
|
12
12
|
s.files = ["Changes.md", "LICENSE", "README.md", "connection_pool.gemspec",
|
|
13
|
-
"lib/connection_pool.rb",
|
|
14
|
-
"lib/connection_pool/
|
|
13
|
+
"lib/connection_pool.rb",
|
|
14
|
+
"lib/connection_pool/timed_stack.rb",
|
|
15
|
+
"lib/connection_pool/version.rb",
|
|
16
|
+
"lib/connection_pool/fork.rb",
|
|
17
|
+
"lib/connection_pool/wrapper.rb"]
|
|
15
18
|
s.executables = []
|
|
16
19
|
s.require_paths = ["lib"]
|
|
17
20
|
s.license = "MIT"
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
class ConnectionPool
|
|
2
|
+
if Process.respond_to?(:fork)
|
|
3
|
+
INSTANCES = ObjectSpace::WeakMap.new
|
|
4
|
+
private_constant :INSTANCES
|
|
5
|
+
|
|
6
|
+
def self.after_fork
|
|
7
|
+
INSTANCES.each_value do |pool|
|
|
8
|
+
# We're in after_fork, so we know all other threads are dead.
|
|
9
|
+
# All we need to do is ensure the main thread doesn't have a
|
|
10
|
+
# checked out connection
|
|
11
|
+
pool.checkin(force: true)
|
|
12
|
+
pool.reload do |connection|
|
|
13
|
+
# Unfortunately we don't know what method to call to close the connection,
|
|
14
|
+
# so we try the most common one.
|
|
15
|
+
connection.close if connection.respond_to?(:close)
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
nil
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
module ForkTracker
|
|
22
|
+
def _fork
|
|
23
|
+
pid = super
|
|
24
|
+
if pid == 0
|
|
25
|
+
ConnectionPool.after_fork
|
|
26
|
+
end
|
|
27
|
+
pid
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
Process.singleton_class.prepend(ForkTracker)
|
|
31
|
+
else
|
|
32
|
+
# JRuby, et al
|
|
33
|
+
INSTANCES = nil
|
|
34
|
+
private_constant :INSTANCES
|
|
35
|
+
|
|
36
|
+
def self.after_fork
|
|
37
|
+
# noop
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
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: 3.0.
|
|
4
|
+
version: 3.0.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Mike Perham
|
|
@@ -65,6 +65,7 @@ files:
|
|
|
65
65
|
- README.md
|
|
66
66
|
- connection_pool.gemspec
|
|
67
67
|
- lib/connection_pool.rb
|
|
68
|
+
- lib/connection_pool/fork.rb
|
|
68
69
|
- lib/connection_pool/timed_stack.rb
|
|
69
70
|
- lib/connection_pool/version.rb
|
|
70
71
|
- lib/connection_pool/wrapper.rb
|