Skip to content

Commit 8bc4d35

Browse files
address comment: trim close doc strings
Signed-off-by: James Xin <james.xin@improving.com>
1 parent b2ed4d7 commit 8bc4d35

1 file changed

Lines changed: 2 additions & 23 deletions

File tree

lib/valkey.rb

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -272,11 +272,7 @@ def initialize(options = {})
272272
end
273273

274274
@connection = res[:conn_ptr]
275-
# Serializes `close` so two threads cannot both capture the handle and
276-
# double-decrement its Arc refcount (issue #212). We use `Mutex#try_lock`
277-
# in `close`, not `#synchronize`, so trap-context callers still work:
278-
# only `#lock`/`#synchronize` raise ThreadError from a trap, `#try_lock`
279-
# returns false and moves on.
275+
# Lock for serializing close(). See `close` for why try_lock is used.
280276
@close_lock = Mutex.new
281277
Bindings.free_connection_response(response_ptr)
282278

@@ -298,24 +294,7 @@ def initialize(options = {})
298294
@in_multi_block = false
299295
end
300296

301-
# Closes the client and frees the native connection. Idempotent and
302-
# thread-safe: `@close_lock.try_lock` lets exactly one caller free the
303-
# handle, while every other concurrent `close` (and every subsequent one)
304-
# is a no-op. Without this, two threads could both read `@connection`
305-
# before either nulled it, both call `close_client`, and double-decrement
306-
# the Arc refcount - which is UB per Rust (issue #212).
307-
#
308-
# `try_lock` (not `synchronize`) is deliberate: `Mutex#synchronize` /
309-
# `#lock` raise ThreadError from a trap context, but `#try_lock` does not.
310-
# That keeps the standard `Signal.trap("TERM") { client.close }` shutdown
311-
# idiom working - the trap either wins the lock and closes, or another
312-
# thread has already closed and it silently returns.
313-
#
314-
# In-flight commands are safe: every glide-ffi command entry point does
315-
# `Arc::increment_strong_count` on the handle before using it, and
316-
# `close_client` only decrements, so the native ClientAdapter outlives any
317-
# request still executing and is dropped once the last one finishes.
318-
# Verified with 12 concurrent blocking calls held open across a `close`.
297+
# Closes the client and frees the native connection.
319298
def close
320299
return unless @close_lock&.try_lock
321300

0 commit comments

Comments
 (0)