Skip to content

Commit

Permalink
Merge branch 'fix_race' into 'master'
Browse files Browse the repository at this point in the history
Fix race

See merge request integration-system/isp-lib!17
  • Loading branch information
Комиссаров Ян Вадимович committed Oct 13, 2021
2 parents 997a72d + 98ea159 commit dd6de1d
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 10 deletions.
2 changes: 1 addition & 1 deletion bootstrap/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

const (
LibraryVersion = "2.9.0"
LibraryVersion = "2.9.1"
)

func init() {
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/asaskevich/govalidator v0.0.0-20180315120708-ccb8e960c48f
github.com/buaazp/fasthttprouter v0.1.1
github.com/cenkalti/backoff/v4 v4.1.0
github.com/dop251/goja v0.0.0-20210427212725-462d53687b0d
github.com/dop251/goja v0.0.0-20211011172007-d99e4b8cbf48
github.com/fsnotify/fsnotify v1.4.9
github.com/go-pg/pg/v9 v9.2.1
github.com/go-redis/redis/v8 v8.8.2
Expand Down Expand Up @@ -35,6 +35,7 @@ require (
github.com/swaggo/http-swagger v1.0.0
github.com/swaggo/swag v1.7.0
github.com/valyala/fasthttp v1.24.0
golang.org/x/text v0.3.7 // indirect
google.golang.org/genproto v0.0.0-20210602131652-f16073e35f0c
google.golang.org/grpc v1.38.0
google.golang.org/protobuf v1.26.0
Expand Down
7 changes: 4 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ github.com/docker/go-connections v0.4.0/go.mod h1:Gbd7IOopHjR8Iph03tsViu4nIes5Xh
github.com/docker/go-units v0.4.0 h1:3uh0PgVws3nIA0Q+MwDC8yjEPf9zjRfZZWXZYDct3Tw=
github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
github.com/dop251/goja v0.0.0-20201221183957-6b6d5e2b5d80/go.mod h1:Mw6PkjjMXWbTj+nnj4s3QPXq1jaT0s5pC0iFD4+BOAA=
github.com/dop251/goja v0.0.0-20210427212725-462d53687b0d h1:enuVjS1vVnToj/GuGZ7QegOAIh1jF340Sg6NXcoMohs=
github.com/dop251/goja v0.0.0-20210427212725-462d53687b0d/go.mod h1:R9ET47fwRVRPZnOGvHxxhuZcbrMCuiqOz3Rlrh4KSnk=
github.com/dop251/goja v0.0.0-20211011172007-d99e4b8cbf48 h1:iZOop7pqsg+56twTopWgwCGxdB5SI2yDO8Ti7eTRliQ=
github.com/dop251/goja v0.0.0-20211011172007-d99e4b8cbf48/go.mod h1:R9ET47fwRVRPZnOGvHxxhuZcbrMCuiqOz3Rlrh4KSnk=
github.com/dop251/goja_nodejs v0.0.0-20210225215109-d91c329300e7/go.mod h1:hn7BA7c8pLvoGndExHudxTDKZ84Pyvv+90pbBjbTz0Y=
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1:+020luEh2TKB4/GOp8oxxtq0Daoen/Cii55CzbTV6DU=
Expand Down Expand Up @@ -967,8 +967,9 @@ golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
Expand Down
14 changes: 10 additions & 4 deletions scripts/goja.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package scripts
import (
"bytes"
"sync"
"sync/atomic"
"time"

"github.com/dop251/goja"
Expand Down Expand Up @@ -40,18 +41,23 @@ func (m *Engine) Execute(s Script, arg interface{}, opts ...ExecOption) (interfa
for _, o := range opts {
o(config)
}
config.timer = time.AfterFunc(config.scriptTimeout, func() {
vm.Interrupt("execution timeout")
})
var timer *time.Timer
isAlive := int32(1)
defer func() {
config.timer.Stop()
atomic.StoreInt32(&isAlive, 0)
timer.Stop()
vm.ClearInterrupt()
m.pool.Put(vm)
}()

config.set(vm)
defer config.unset(vm)

timer = time.AfterFunc(config.scriptTimeout, func() {
if atomic.LoadInt32(&isAlive) == 1 {
vm.Interrupt("execution timeout")
}
})
res, err := vm.RunProgram(s.prog)
if err != nil {
return nil, castErr(err)
Expand Down
1 change: 0 additions & 1 deletion scripts/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ type ExecOption func(opt *configOptions)

type configOptions struct {
scriptTimeout time.Duration
timer *time.Timer
arg interface{}
logBuf *bytes.Buffer
data map[string]interface{}
Expand Down

0 comments on commit dd6de1d

Please sign in to comment.