Repository navigation
lock,cli: renew Redis lock leases and lengthen suspend/resume timeout - #490
Conversation
Suspend/resume hold the per-task lock across Substrate snapshot/restore, which for microVM sandboxes can exceed both the CLI's 60s deadline and the 30s Redis lock TTL. Once the TTL lapsed, another request could take the lock while the first was still mutating the task. - RedisLocker now renews a held lease every TTL/3 (token-checked) until unlock, so the TTL only bounds how long a crashed holder's lock lingers. The rationale for renewal over a single long TTL is documented on RedisLocker. - Raise the CLI suspend/resume RPC timeout to 5 minutes. - Add a Redis-backed renewal test, skipped unless REDIS_ADDR is set. Signed-off-by: siyuanfoundation <[email protected]>
There was a problem hiding this comment.
Code Review
This pull request introduces a background lease renewal mechanism for RedisLocker to keep held locks alive, and increases the suspend/resume RPC timeouts to 5 minutes. The review feedback points out a potential blocking issue in the unlock function if the Redis client is slow or hung, because the renewal goroutine uses a non-cancelable context for its Redis calls. It is recommended to pass a cancelable context to the renewal goroutine instead of a stop channel to ensure active Redis operations can be canceled immediately during unlock.
rich7420
left a comment
There was a problem hiding this comment.
Verified the renewal/unlock ordering and test error paths locally against Redis. These suggestions address the confirmed cases; paired suggestions should be applied in one batch.
mayawang
left a comment
There was a problem hiding this comment.
Thanks @siyuanfoundation, renewal with the token check is the right fix, and documenting the trade-off and the fencing limitation is really helpful. Approving.
- Pass a cancelable context into RedisLocker.renew instead of a stop channel so unlock() immediately cancels any in-flight renewal RPC and exits quietly. - Keep <-done synchronization so the renewal goroutine finishes before unlock returns. - Assert context.DeadlineExceeded on contender lock attempt in TestRedisLocker_RenewsLeaseWhileHeld.
d42908d to
96709cb
Compare
|
Thanks @mayawang and @rich7420 for the reviews! Updated in
|
mayawang
left a comment
There was a problem hiding this comment.
Re-approving with the cancelable renewal context, tests pass on main including -race on the lock package. Thanks @rich7420 for testing this against Redis. On keeping the wait in unlock: I'm fine with it, since the release itself goes to the same Redis and would stall on a hung connection anyway, and the token checks keep both orders safe.
Summary
Split out from #474 per review discussion (#474 (comment)).
Suspend/resume hold the per-task lock across Substrate snapshot/restore, which for microVM sandboxes can exceed both the CLI's 15s deadline and the 30s Redis lock TTL. Once the TTL lapsed, another request could take the lock while the first was still mutating the task.
RedisLockernow renews a held lease every TTL/3 (token-checked via Lua script) until unlock, so the TTL only bounds how long a crashed holder's lock lingers. The rationale for renewal over a single long TTL is documented onRedisLocker.lifecycleRPCTimeout).TestRedisLocker_RenewsLeaseWhileHeld), skipped unlessREDIS_ADDRis set.Relates to #483.