From 51bf6d576b56b4fe9e3e8d51b0d4e43f1d123ddf Mon Sep 17 00:00:00 2001 From: Eugene Kenny Date: Thu, 25 Jan 2024 00:24:05 +0000 Subject: [PATCH] Don't reconnect to send pipelined request no-op If sending the pipelined get commands fails with a network error, the socket will be closed when we try to send the no-op command. `alive?` reconnects if possible, but we only need to send the no-op if the get commands were successfully sent. Before c01d4105d82d7526dd645900137fb7c4f403ca90, reconnecting to send a no-op was harmless, but now that pipelined requests are tracked in their entirety, an error is raised since there is no request in progress. --- lib/dalli/pipelined_getter.rb | 2 +- test/integration/test_network.rb | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/dalli/pipelined_getter.rb b/lib/dalli/pipelined_getter.rb index cc34bc5c..5fbb8bb2 100644 --- a/lib/dalli/pipelined_getter.rb +++ b/lib/dalli/pipelined_getter.rb @@ -60,7 +60,7 @@ def finish_queries(servers) deleted = [] servers.each do |server| - next unless server.alive? + next unless server.connected? begin finish_query_for_server(server) diff --git a/test/integration/test_network.rb b/test/integration/test_network.rb index b2332244..e66f4396 100644 --- a/test/integration/test_network.rb +++ b/test/integration/test_network.rb @@ -113,6 +113,16 @@ end end + it 'handles timeout error during pipelined get' do + with_nil_logger do + memcached(p, 19_191) do |dc| + dc.send(:ring).server_for_key('abc').sock.stub(:write, proc { raise Timeout::Error }) do + assert_empty dc.get_multi(['abc']) + end + end + end + end + it 'handles asynchronous Thread#raise' do with_nil_logger do memcached(p, 19_191) do |dc|