diff --git a/controller/scan.go b/controller/scan.go index db62ee24..2ba19809 100644 --- a/controller/scan.go +++ b/controller/scan.go @@ -27,14 +27,16 @@ func (c *Controller) cmdScan(msg *server.Message) (res resp.Value, err error) { vs := msg.Values[1:] s, err := c.cmdScanArgs(vs) - defer s.Close() - defer func() { - if r := recover(); r != nil { - res = server.NOMessage - err = errors.New(r.(string)) - return - } - }() + if s.usingLua() { + defer s.Close() + defer func() { + if r := recover(); r != nil { + res = server.NOMessage + err = errors.New(r.(string)) + return + } + }() + } if err != nil { return server.NOMessage, err } diff --git a/controller/search.go b/controller/search.go index 71225aaf..e5a8a991 100644 --- a/controller/search.go +++ b/controller/search.go @@ -42,11 +42,15 @@ func (s liveFenceSwitches) Error() string { } func (s liveFenceSwitches) Close() { - for _, whereeval := range s.searchScanBaseTokens.whereevals { + for _, whereeval := range s.whereevals { whereeval.Close() } } +func (s liveFenceSwitches) usingLua() bool { + return len(s.whereevals) > 0 +} + func (c *Controller) cmdSearchArgs(cmd string, vs []resp.Value, types []string) (s liveFenceSwitches, err error) { if vs, s.searchScanBaseTokens, err = c.parseSearchScanBaseTokens(cmd, vs); err != nil { return @@ -295,14 +299,16 @@ func (c *Controller) cmdNearby(msg *server.Message) (res resp.Value, err error) vs := msg.Values[1:] wr := &bytes.Buffer{} s, err := c.cmdSearchArgs("nearby", vs, nearbyTypes) - defer s.Close() - defer func() { - if r := recover(); r != nil { - res = server.NOMessage - err = errors.New(r.(string)) - return - } - }() + if s.usingLua() { + defer s.Close() + defer func() { + if r := recover(); r != nil { + res = server.NOMessage + err = errors.New(r.(string)) + return + } + }() + } if err != nil { return server.NOMessage, err } @@ -402,15 +408,16 @@ func (c *Controller) cmdWithinOrIntersects(cmd string, msg *server.Message) (res wr := &bytes.Buffer{} s, err := c.cmdSearchArgs(cmd, vs, withinOrIntersectsTypes) - defer s.Close() - defer func() { - if r := recover(); r != nil { - res = server.NOMessage - err = errors.New(r.(string)) - return - } - }() - + if s.usingLua() { + defer s.Close() + defer func() { + if r := recover(); r != nil { + res = server.NOMessage + err = errors.New(r.(string)) + return + } + }() + } if err != nil { return server.NOMessage, err } @@ -485,14 +492,16 @@ func (c *Controller) cmdSearch(msg *server.Message) (res resp.Value, err error) wr := &bytes.Buffer{} s, err := c.cmdSeachValuesArgs(vs) - defer s.Close() - defer func() { - if r := recover(); r != nil { - res = server.NOMessage - err = errors.New(r.(string)) - return - } - }() + if s.usingLua() { + defer s.Close() + defer func() { + if r := recover(); r != nil { + res = server.NOMessage + err = errors.New(r.(string)) + return + } + }() + } if err != nil { return server.NOMessage, err }