reconnectOnError fails to handle errors stemming from Lua scripts
Problem statement
reconnectOnError works great ... except that it doesn't handle errors thrown by Lua scripts. Those are uncaught, and get thrown to the caller.
For example, during a primary/replica failover, a script doing writes will cause this error to bubble up to the caller, regardless of reconnectOnError.
ReplyError: ERR Error running script (call to f_<sha1here>): @user_script:88:
@user_script: 88: -READONLY You can't write against a read only replica.So, my typical reconnectOnError: err => err.message.includes('read only') doesn't work because it isn't called. As a result, reconnection doesn't happen, causing app downtime that could have been easily avoided by reconnecting on this kind of error.
Right, or am I missing something?
Existing issues about this
None that I could find in ioredis issues.
Searching the web more broadly for my specific error I found https://github.com/StackExchange/StackExchange.Redis/issues/2074 , the same issue for another Redis client (for C#).
API thoughts
API ideas let users catch such errors:
- User-configured
reconnectOnErrorcould be passed a new second argument namedsource, that would bequery|script. (This one is kinda semver-breaking, as passing to reconnectOnError errors that didn't use to be passed to it). - A new option
reconnectOnScriptErrorcould be added.
Are these reasonable? Would you welcome a PR for one of them? If yes, any implementation advice? I was starting to look at
https://github.com/luin/ioredis/blob/308017a6b9429c16b074e03e70f5524499476fa9/lib/Script.ts#L42-L70
Source: redis/ioredis