From 335c45c578e0f819e6cc26431c7e08a35992d8a0 Mon Sep 17 00:00:00 2001 From: Dmitrii Stepanov Date: Mon, 24 Jun 2024 13:59:12 +0300 Subject: [PATCH] [#149] selector: Add read timeout If there are no objects for 10 second, then return nil. It is required to prevent VU iteration hang if there are no objects pushed to registry. Signed-off-by: Dmitrii Stepanov --- internal/registry/obj_selector.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/internal/registry/obj_selector.go b/internal/registry/obj_selector.go index ef9e0d9..78abb37 100644 --- a/internal/registry/obj_selector.go +++ b/internal/registry/obj_selector.go @@ -9,6 +9,8 @@ import ( "go.etcd.io/bbolt" ) +const nextObjectTimeout = 10 * time.Second + type ObjFilter struct { Status string Age int @@ -57,7 +59,16 @@ func NewObjSelector(registry *ObjRegistry, selectionSize int, kind SelectorKind, // - underlying registry context is done, nil objects will be returned on the // currently blocked and every further NextObject calls. func (o *ObjSelector) NextObject() *ObjectInfo { - return <-o.objChan + if o.kind == SelectorOneshot { + return <-o.objChan + } + + select { + case <-time.After(nextObjectTimeout): + return nil + case obj := <-o.objChan: + return obj + } } // Count returns total number of objects that match filter of the selector.