Skip to content

Commit 722fbaa

Browse files
Ensure incomplete releases retire resources
Signed-off-by: Samuel Williams <samuel.williams@shopify.com> Assisted-By: devx/618580b0-d55f-4c2e-95b6-87e648f60543
1 parent b0210f8 commit 722fbaa

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

‎lib/async/pool/controller.rb‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ def acquire
166166

167167
# Make the resource resources and let waiting tasks know that there is something resources.
168168
def release(resource)
169+
processed = false
170+
169171
usage = decrement_usage(resource)
170172
return false unless usage
171173

@@ -178,17 +180,21 @@ def release(resource)
178180
# The resource must not be acquired again, but it cannot be retired
179181
# until all existing users have released it:
180182
@available.delete(resource)
181-
return retire(resource) if usage.zero?
183+
184+
if usage.zero?
185+
processed = retire(resource)
186+
return processed
187+
end
182188
end
183189

184190
@mutex.synchronize{@condition.broadcast}
185191

186192
# @policy.released(self, resource)
187193

194+
processed = true
188195
return true
189-
rescue Exception
190-
retire(resource)
191-
raise
196+
ensure
197+
retire(resource) unless processed
192198
end
193199

194200
# Drain the pool, closing all resources.

0 commit comments

Comments
 (0)