UNLOCK uses the redis WATCH command to detect changes on a key to determine whether a transaction, in this case, deletion of the locked key, should proceed. i.e.
Here the EXEC will clear the WATCHed state of 'key', however, this is not true if isLocked(key) is FALSE or if an exception occurs after the WATCH and before the EXEC such that the cached connection being used is reused with the said key still in it's WATCHed state.
This issue addresses the first case whilst the latter, of exceptions, is addressed by
HPCC-15710 (see below).
Since UNWATCH only returns an "OK" as a REDIS_REPLY_STATUS and doesn't contain information that this "OK" is in response to the UNWATCH, there is no way to guarantee a successful UNWATCH when having encountered an exception. For this reason, the correct solution is to simply close the connection. Such exception handling is true of all exceptions using pipelined commands which is true of all plugin functions as the AUTH and SELECT commands are pipelined upon opening a new connection. This is implemented by