connection_pool 2.5.4 → 2.5.5

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: e6266fe91b9d1e5285e6e4cd873b0721b18b2c49140fff54b43c9df4d5acd7b1
4
- data.tar.gz: cc95e0178a26a01d9fc3933d8b65468d203c7fb6ed415312f86e392551659db8
3
+ metadata.gz: 24c74a1caa5e04827c47155b75e19805bcda4c329e28793309dfa95b5881c4bd
4
+ data.tar.gz: 23aadf2da494be8c3314039700606cd4e01b58d6cae1f45e3b7cdef57a98e7bd
5
5
  SHA512:
6
- metadata.gz: 9641879d84cc20db729d1780283fca3a0328e957502369bd22dbbdd0f6601974204acdd8dcd1929e79da505402b73f3fe5eaf2842cfe64d542640ab1e70ad21c
7
- data.tar.gz: 34afe9f57cbaff9b08066725964d776e81e1e0e484eccd54c361cc2a77fe24fbda181c9576754367515799f24f8095504ce2b4c8718f37a90b75c559782be0b4
6
+ metadata.gz: 0f2385ddf4619ebc1bf9e2f202024b330c170ae2e4e7e63480be0f556242140af75eb3d272f6d262b2fc859625f0861c560af6a58c20bea3d69b005e2d248472
7
+ data.tar.gz: 0ac5103c69aa2e8226d2fa872714f9bd611b24ea171e91ce3d7a3c9be62b9887e24916cf4b6b1e5bc8c407349f87c3ea855c4659dbf5f3f137cd45738301d1a6
data/Changes.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # connection_pool Changelog
2
2
 
3
+ 2.5.5
4
+ ------
5
+
6
+ - Support `ConnectionPool::TimedStack#pop(exception: false)` [#207]
7
+ to avoid using exceptions as control flow.
8
+
3
9
  2.5.4
4
10
  ------
5
11
 
@@ -54,9 +54,12 @@ class ConnectionPool::TimedStack
54
54
  # immediately returned. If no connection is available within the given
55
55
  # timeout a ConnectionPool::TimeoutError is raised.
56
56
  #
57
- # +:timeout+ is the only checked entry in +options+ and is preferred over
58
- # the +timeout+ argument (which will be removed in a future release). Other
59
- # options may be used by subclasses that extend TimedStack.
57
+ # @option options [Float] :timeout (0.5) Wait this many seconds for an available entry
58
+ # @option options [Class] :exception (ConnectionPool::TimeoutError) Exception class to raise
59
+ # if an entry was not available within the timeout period. Use `exception: false` to return nil.
60
+ #
61
+ # The +timeout+ argument will be removed in 3.0.
62
+ # Other options may be used by subclasses that extend TimedStack.
60
63
  def pop(timeout = 0.5, options = {})
61
64
  options, timeout = timeout, 0.5 if Hash === timeout
62
65
  timeout = options.fetch :timeout, timeout
@@ -73,7 +76,14 @@ class ConnectionPool::TimedStack
73
76
  return connection if connection
74
77
 
75
78
  to_wait = deadline - current_time
76
- raise ConnectionPool::TimeoutError, "Waited #{timeout} sec, #{length}/#{@max} available" if to_wait <= 0
79
+ if to_wait <= 0
80
+ exc = options.fetch(:exception, ConnectionPool::TimeoutError)
81
+ if exc
82
+ raise ConnectionPool::TimeoutError, "Waited #{timeout} sec, #{length}/#{@max} available"
83
+ else
84
+ return nil
85
+ end
86
+ end
77
87
  @resource.wait(@mutex, to_wait)
78
88
  end
79
89
  end
@@ -1,3 +1,3 @@
1
1
  class ConnectionPool
2
- VERSION = "2.5.4"
2
+ VERSION = "2.5.5"
3
3
  end
@@ -104,6 +104,9 @@ class ConnectionPool
104
104
  end
105
105
 
106
106
  def with(options = {})
107
+ # We need to manage exception handling manually here in order
108
+ # to work correctly with `Timeout.timeout` and `Thread#raise`.
109
+ # Otherwise an interrupted Thread can leak connections.
107
110
  Thread.handle_interrupt(Exception => :never) do
108
111
  conn = checkout(options)
109
112
  begin
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.5.4
4
+ version: 2.5.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Perham