kortschak's fix
This commit is contained in:
parent
e1e95b9686
commit
f605e1138d
1 changed files with 4 additions and 1 deletions
|
|
@ -111,7 +111,6 @@ func (s *Session) SendResult(r *Result) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Session) runUnsafe(input interface{}) (otto.Value, error) {
|
func (s *Session) runUnsafe(input interface{}) (otto.Value, error) {
|
||||||
s.kill = make(chan struct{})
|
|
||||||
defer func() {
|
defer func() {
|
||||||
if r := recover(); r != nil {
|
if r := recover(); r != nil {
|
||||||
if r == ErrKillTimeout {
|
if r == ErrKillTimeout {
|
||||||
|
|
@ -125,9 +124,12 @@ func (s *Session) runUnsafe(input interface{}) (otto.Value, error) {
|
||||||
// Use buffered chan to prevent blocking.
|
// Use buffered chan to prevent blocking.
|
||||||
s.env.Interrupt = make(chan func(), 1)
|
s.env.Interrupt = make(chan func(), 1)
|
||||||
|
|
||||||
|
ready := make(chan struct{})
|
||||||
|
s.kill = make(chan struct{})
|
||||||
if s.timeout >= 0 {
|
if s.timeout >= 0 {
|
||||||
go func() {
|
go func() {
|
||||||
time.Sleep(s.timeout)
|
time.Sleep(s.timeout)
|
||||||
|
<-ready
|
||||||
close(s.kill)
|
close(s.kill)
|
||||||
s.envLock.Lock()
|
s.envLock.Lock()
|
||||||
defer s.envLock.Unlock()
|
defer s.envLock.Unlock()
|
||||||
|
|
@ -143,6 +145,7 @@ func (s *Session) runUnsafe(input interface{}) (otto.Value, error) {
|
||||||
s.envLock.Lock()
|
s.envLock.Lock()
|
||||||
env := s.env
|
env := s.env
|
||||||
s.envLock.Unlock()
|
s.envLock.Unlock()
|
||||||
|
close(ready)
|
||||||
return env.Run(input)
|
return env.Run(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue