From 59d201e148318fb89fe8f4c110ecd4e4d5a79f26 Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Thu, 3 Jun 2021 17:48:44 -0400 Subject: [PATCH] submatview: fix a bug with Store.Get When info.Timeout is 0, it should have no timeout. Previously it was using a 0 duration timeout which caused it to return without waiting. This bug was masked by using a timeout in the tests. Removing the timeout caused the tests to fail. --- agent/submatview/store.go | 7 +++++-- agent/submatview/store_test.go | 1 - 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/agent/submatview/store.go b/agent/submatview/store.go index 80e9f30b7d..58acf5db33 100644 --- a/agent/submatview/store.go +++ b/agent/submatview/store.go @@ -118,8 +118,11 @@ func (s *Store) Get(ctx context.Context, req Request) (Result, error) { } defer s.releaseEntry(key) - ctx, cancel := context.WithTimeout(ctx, info.Timeout) - defer cancel() + if info.Timeout > 0 { + var cancel context.CancelFunc + ctx, cancel = context.WithTimeout(ctx, info.Timeout) + defer cancel() + } result, err := materializer.getFromView(ctx, info.MinIndex) // context.DeadlineExceeded is translated to nil to match the timeout diff --git a/agent/submatview/store_test.go b/agent/submatview/store_test.go index ea0e01c2bd..9363c772b3 100644 --- a/agent/submatview/store_test.go +++ b/agent/submatview/store_test.go @@ -160,7 +160,6 @@ func (r *fakeRequest) CacheInfo() cache.RequestInfo { Key: key, Token: "abcd", Datacenter: "dc1", - Timeout: 4 * time.Second, MinIndex: r.index, } }