mCaptcha / cache

Redis module that implements mCaptcha cache and counter
https://mcaptcha.org
GNU Affero General Public License v3.0
5 stars 3 forks source link

Use safety objects to run jobs scheduled within bucket #1

Closed realaravinth closed 3 years ago

realaravinth commented 3 years ago

Bucket's expiration callback is executed after the bucket is deleted. As a result, all jobs scheduled within the bucket are lost. This means, we could end up with stagnant values(visitor counts) in mcaptcha objects.

Timers are not persisted during rdb saves. So when cache is restored from disk, the above issue will happen. Rather than relying on timers execute jobs, use a safety object, upon who's expiry, the bucket's (callback runner) will be executed.

realaravinth commented 3 years ago

It seems there's already a mechanism in place to do this job. A dummy entry is made right after bucket creation, who's expiry acts as a fallback to trigger execution of scheduled jobs.

https://github.com/mCaptcha/cache/blob/a1f9bcb247f4d2c6d85c902fdec3b1aeaf276ab1/src/bucket.rs#L232

I should work on simplifying the whole thing or at the very least document all hacks used.