Skip to content

Commit

Permalink
Merge pull request #572 from textileio/sander/timeout-vm
Browse files Browse the repository at this point in the history
db: ensure vm doesnt run forever
  • Loading branch information
sanderpick authored Jan 5, 2022
2 parents 0eb8098 + e24b357 commit 3be6a41
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions db/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ var (
errCantCreateExistingInstance = errors.New("can't create already existing instance")

baseKey = dsPrefix.ChildString("collection")

vmTimeout = time.Millisecond * 200
)

const (
Expand Down Expand Up @@ -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{
Expand Down

0 comments on commit 3be6a41

Please sign in to comment.