How to set expiry for lock on resource?

176 Views Asked by At

My program will be utilising a shared resource so a lock on this resource is required.

When a processing task on this resource is started it will obtain a lock on the resource. When it completes it will release the lock.

To cater for crashes and power failures during the processing task which would leave the lock on forever, the lock should have an expiry time.

If the time taken to perform a processing task involving the resource is usually between 0 and 5 seconds, I would think that the expiry time should be about 10 minutes or even 1 hour.

How then should I cater for the unusual scenario of the processing task actually taking longer than the expiry time?

Should the task itself have an expiry time less than the lock expiry time?

1

There are 1 best solutions below

0
On

I guess that you are dealing with remote resource. Lock handling should be done on it's side. The caller should specify the lock timeout when it's acquiring it, and you should support a methot for lock owner to request longer timeout if neaded.