Repository: petergoldstein/dalli (Ruby)

Issue:
No request in progress
I'm seeing this error pop up in my logs intermittently, always with this jbuilder template:

```
json.array! @projects, partial: 'project', as: :project, cached: ->(project) { [project.location, project] }
```

Recently, this template was changed, and the error started after changing `cached: true` to what it is above.

Abbreviated stacktrace:

```
vendor/bundle/ruby/3.0.0/gems/dalli-3.2.5/lib/dalli/protocol/connection_manager.rb:107:in `confirm_in_progress!': [Dalli] No request in progress. This may be a bug in Dalli. (ActionView::Template::Error)
    from vendor/bundle/ruby/3.0.0/gems/dalli-3.2.5/lib/dalli/protocol/base.rb:179:in `verify_pipelined_state'
    from vendor/bundle/ruby/3.0.0/gems/dalli-3.2.5/lib/dalli/protocol/base.rb:75:in `pipeline_response_setup'
    from vendor/bundle/ruby/3.0.0/gems/dalli-3.2.5/lib/dalli/pipelined_getter.rb:81:in `finish_query_for_server'
    from vendor/bundle/ruby/3.0.0/gems/dalli-3.2.5/lib/dalli/pipelined_getter.rb:66:in `block in finish_queries'
    from vendor/bundle/ruby/3.0.0/gems/dalli-3.2.5/lib/dalli/pipelined_getter.rb:62:in `each'
    from vendor/bundle/ruby/3.0.0/gems/dalli-3.2.5/lib/dalli/pipelined_getter.rb:62:in `finish_queries'
    from vendor/bundle/ruby/3.0.0/gems/dalli-3.2.5/lib/dalli/pipelined_getter.rb:35:in `setup_requests'
    from vendor/bundle/ruby/3.0.0/gems/dalli-3.2.5/lib/dalli/pipelined_getter.rb:20:in `block in process'
    from vendor/bundle/ruby/3.0.0/gems/dalli-3.2.5/lib/dalli/ring.rb:78:in `lock'
    from vendor/bundle/ruby/3.0.0/gems/dalli-3.2.5/lib/dalli/pipelined_getter.rb:19:in `process'
    from vendor/bundle/ruby/3.0.0/gems/dalli-3.2.5/lib/dalli/client.rb:108:in `block in get_multi'
    from vendor/bundle/ruby/3.0.0/gems/dalli-3.2.5/lib/dalli/client.rb:107:in `get_multi'
    from vendor/bundle/ruby/3.0.0/gems/activesupport-6.1.7.4/lib/active_support/cache/mem_cache_store.rb:165:in `block in read_multi_entries'
```


Discussion:
I am getting the same error quite a few times.
Did you happen to find any resolution yet?

Getting no response and not knowing how to debug this library myself, I resolved by switching from memcached to redis for our cache store and not using this library any longer 🤷



Patch:
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)


Test patch:
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|