microsoft/garnet · error · GarnetException
Internal Lua Error: {res}
Error message
Internal Lua Error: {res} What it means
Thrown by CompileForRunner when the protected compile call returned a non-OK LuaStatus (res) and the runner produced no RESP error frame. Unlike the RESP-error case, there is no friendly text - only the raw LuaStatus enum value. This indicates the Lua VM itself misbehaved during compilation rather than reporting a normal script error.
Source
Thrown at libs/server/Lua/LuaRunner.cs:444
try
{
LuaRunnerTrampolines.SetCallbackContext(this);
state.PushCFunction(&LuaRunnerTrampolines.CompileForRunner);
var res = state.PCall(0, 0);
if (res == LuaStatus.OK)
{
var resp = runnerAdapter.Response;
var respStart = (byte*)Unsafe.AsPointer(ref MemoryMarshal.GetReference(resp));
var respEnd = respStart + resp.Length;
if (RespReadUtils.TryReadErrorAsSpan(out var errSpan, ref respStart, respEnd))
{
var errStr = Encoding.UTF8.GetString(errSpan);
throw new GarnetException(errStr);
}
}
else
{
throw new GarnetException($"Internal Lua Error: {res}");
}
}
finally
{
runnerAdapter = default;
LuaRunnerTrampolines.ClearCallbackContext(this);
}
}
/// <summary>
/// Compile script for a <see cref="RespServerSession"/>.
///
/// Any errors encountered are written out as Resp errors.
/// </summary>
public unsafe bool CompileForSession(RespServerSession session)
{
state.ExpectLuaStackEmpty();
View on GitHub (pinned to 951b0fc683)
Solutions
- Inspect the LuaStatus value (res) in the logs to map it to a Lua error class (e.g., ERRMEM, ERRERR).
- Check memory pressure and configured memory limits on the Lua/runner.
- Recreate the Lua state / restart the session; if reproducible, file it as an internal bug with the script that triggered it.
Defensive patterns
Strategy: try-catch
Try / catch
catch (GarnetException ex) when (ex.Message.StartsWith("Internal Lua Error")) {
logger.LogError("Lua PCall returned non-OK status during compile: {Msg}", ex.Message);
throw; // typically non-recoverable for this state; report and restart session
} Prevention
- Monitor memory and Lua stack usage on the server.
- Capture the LuaStatus value when this fires - it is the only diagnostic available.
When it happens
Trigger: state.PCall for compilation returns a non-OK status and the runner adapter's response buffer did not contain a parseable RESP error, so the code falls to the else branch and throws 'Internal Lua Error: {res}'.
Common situations: Out-of-memory inside the Lua VM; stack overflow; a corrupted Lua state; a build mismatch. Rare under normal load.
Related errors
- Could not initialize Lua VM: {innerError}
- Could not initialize Lua VM
- Could not initialize Lua sandbox state: {errMsg}
- {errStr}
- Could not run function preamble: {errMsg}
AI-assisted analysis of microsoft/garnet@951b0fc683 (2026-08-13).
Data as JSON: /api/errors/69eb4419627c652d.
Report an issue: GitHub.