nrk / redis-lua

A Lua client library for the redis key value storage system.
MIT License
731 stars 239 forks source link

Pub/Sub is not tolerant of timeouts #61

Open drauschenbach opened 5 years ago

drauschenbach commented 5 years ago

Since Lua uses cooperative multitasking and is single-threaded in most environments, libraries like LuaSocket depend heavily on timeouts and doing small batches of work at a time.

As a Redis subscriber, I have a similar requirement, and want to receive notifications within a function call that has a max-runtime duration budget. So I set a LuaSocket timeout:

client.network.socket:settimeout(0.25)
for message, abort in client:pubsub({subscribe=topics}) do
  -- Handle message and abort
  if (my elapsed time budget is up) then return end
end

But the client library is currently unforgiving of LuaSocket timeout errors and treats them like a hard failure:

lua: .///mytestfile.lua:46: /usr/local/share/lua/5.2/redis.lua:271: attempt to index local 'payload' (a nil value)