From e24b3576c7f09ec8d1bc0c6611dbc0d0d3a1167c Mon Sep 17 00:00:00 2001 From: Sander Pick Date: Tue, 4 Jan 2022 19:18:55 -0800 Subject: [PATCH] db: ensure vm doesnt run forever Signed-off-by: Sander Pick --- db/collection.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/db/collection.go b/db/collection.go index 3b5b67a7..b7b6f9b3 100644 --- a/db/collection.go +++ b/db/collection.go @@ -43,6 +43,8 @@ var ( errCantCreateExistingInstance = errors.New("can't create already existing instance") baseKey = dsPrefix.ChildString("collection") + + vmTimeout = time.Millisecond * 200 ) const ( @@ -85,6 +87,9 @@ func newCollection(d *DB, config CollectionConfig) (*Collection, error) { return nil, err } vm := goja.New() + time.AfterFunc(vmTimeout, func() { + vm.Interrupt("validator timed out") + }) wv := []byte(config.WriteValidator) rf := []byte(config.ReadFilter) c := &Collection{