garnet: Regression: Garnet 1.0.49 fails on unknown commands in Lua

Describe the bug

Garnet 1.0.49 has issues with processing unknown commands in Lua (1.0.48 works more as expected).

Steps to reproduce the bug

With Garnet 1.0.48 using StackExchange.Redis ScriptEvaluate, we get:

  • invoking redis.call("missing") returns an empty string
  • invoking return redis.call("missing") returns the string ERR unknown command

With Garnet 1.0.49 the above calls result in exceptions and the server log shows the following records (they do not look as something by design):

05::14::27 fail: Session[0] [127.0.0.1:61856] [00480155] During Lua script execution System.Runtime.InteropServices.SEHException (0x80004005): External component has thrown an exception.    at KeraLua.NativeMethods.lua_error(IntPtr luaState)    at Garnet.server.LuaStateWrapper.RaiseErrorFromStack() in /_/libs/server/Lua/LuaStateWrapper.cs:line 476    at Garnet.server.LuaRunner.LuaStaticError(Int32 constStringRegistryIndex) in /_/libs/server/Lua/LuaRunner.cs:line 656    at Garnet.server.LuaRunner.ProcessResponse(Byte* ptr, Int32 length) in /_/libs/server/Lua/LuaRunner.cs:line 698    at Garnet.server.LuaRunner.ProcessCommandFromScripting[TGarnetApi](TGarnetApi api) in /_/libs/server/Lua/LuaRunner.cs:line 634
05::14::27 fail: Session[0] [127.0.0.1:61856] [00480155] Error executing Lua script System.Runtime.InteropServices.SEHException (0x80004005): External component has thrown an exception.    at KeraLua.NativeMethods.lua_error(IntPtr luaState)    at Garnet.server.LuaStateWrapper.RaiseErrorFromStack() in /_/libs/server/Lua/LuaStateWrapper.cs:line 476    at Garnet.server.LuaStateWrapper.RaiseError(String msg) in /_/libs/server/Lua/LuaStateWrapper.cs:line 466    at Garnet.server.LuaRunner.ProcessCommandFromScripting[TGarnetApi](TGarnetApi api) in /_/libs/server/Lua/LuaRunner.cs:line 642    at Garnet.server.LuaRunner.garnet_call_txn(IntPtr luaStatePtr) in /_/libs/server/Lua/LuaRunner.cs:line 502    at KeraLua.NativeMethods.lua_pcallk(IntPtr luaState, Int32 nargs, Int32 nresults, Int32 errorfunc, IntPtr ctx, IntPtr k)    at KeraLua.Lua.PCall(Int32 arguments, Int32 results, Int32 errorFunctionIndex)    at Garnet.server.LuaRunner.RunCommon[TResponse](TResponse& resp) in /_/libs/server/Lua/LuaRunner.cs:line 1084    at Garnet.server.LuaRunner.RunForSession(Int32 count, RespServerSession outerSession) in /_/libs/server/Lua/LuaRunner.cs:line 853    at Garnet.server.RespServerSession.ExecuteScript(Int32 count, LuaRunner scriptRunner) in /_/libs/server/Lua/LuaCommands.cs:line 264

Expected behavior

The above Lua scripts are intentionally not quite right, using unknown commands. They should probably cause some errors, e.g. like in Garnet 1.0.48 but not like in 1.0.49

Release version

1.0.49

IDE

.NET 9

OS version

Windows 11

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 17 (13 by maintainers)

Most upvoted comments

UPDATE: nope, sorry, still the same issue but this is a separate issue, if an issue at all. It gives [string "return redis.pcall("missing")"]:1: attempt to call a nil value (field 'pcall')

Yeah, that’s because Garnet’s Lua preamble hasn’t defined all the things Redis does - so redis.pcall(...) just straight up does not exist (there are plenty of others where that is true too, not just pcall). It’s not a regression, but a place for future improvement. I intend to get to it eventually, but it’s not top of my list right now.

Yeah, .NET 9 does it. Interesting.

While reported from KeraLua, you get it with a plain p/invoke too.

Digging through lua_error, ultimately it’s just a longjmp.

Very strange… but it twigged a memory. .NET team has been working on exception performance, and recently defaults a new implementation on.

If I disable it (setting environment variable DOTNET_LegacyExceptionHandling to 1 ) the error goes away.

So I think this is a .NET regression, I’m putting together a minimum repro and will open an issue over there.

@nightroman, as a sanity check, can you apply that setting and see if the issue goes away?

edit: Oops, misclicked and closed this by accident - reopened. Sorry for the email spam!