Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return Lua VM to the pool only after it's error was processed #932

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 9 additions & 3 deletions server/runtime_lua.go
Expand Up @@ -1265,7 +1265,6 @@ func (rp *RuntimeProviderLua) Rpc(ctx context.Context, id string, headers, query
r.vm.SetContext(vmCtx)
result, fnErr, code, isCustomErr := r.InvokeFunction(RuntimeExecutionModeRPC, lf, headers, queryParams, userID, username, vars, expiry, sessionID, clientIP, clientPort, lang, payload)
r.vm.SetContext(context.Background())
rp.Put(r)

if fnErr != nil {
if !isCustomErr {
Expand All @@ -1279,8 +1278,11 @@ func (rp *RuntimeProviderLua) Rpc(ctx context.Context, id string, headers, query
code = 13
}

return "", clearFnError(fnErr, rp, lf), code
err = clearFnError(fnErr, rp, lf)
rp.Put(r) // don't return VM until error originated in that VM is processed
return "", err, code
}
rp.Put(r)

if result == nil {
return "", nil, 0
Expand Down Expand Up @@ -2092,7 +2094,11 @@ func clearFnError(fnErr error, rp *RuntimeProviderLua, lf *lua.LFunction) error
}
return errors.New(msg)
}
return fnErr

// fnErr contains reference to the LuaVM we are about to return to pool,
// create new error with same error message, but dropping any references
// to the Lua VM objects
return errors.New(fnErr.Error())
}

func checkRuntimeLuaVM(logger *zap.Logger, config Config, version string, stdLibs map[string]lua.LGFunction, moduleCache *RuntimeLuaModuleCache) error {
Expand Down