-
Notifications
You must be signed in to change notification settings - Fork 132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Distributed Lock is causing issues #329
Comments
Hi @phillijw
I have just tested with a small app on my side. Recurring jobs work fine, and no locks get stuck.
If you are asking about In other words, job execution time and lock timeout are NOT related. This should be working normally without you having to set 6 hours time outs. |
I think the lock is actually coming from the |
Ok, yes, so the main issue I'm seeing is that when I set |
It makes sense now. In terms of distributed locking, hangfire sql and postgres are different. SqlServer uses application locks which are cleared automatically when connection closes. In comparison, Postgres uses a simple table to store locks, which cleans up only inside of code. Postgres is vulnerable to cases when job is interrupted There were discussions in this repo about improving lock mechanism, but as I understand it got stuck with a major issue which was not solved so far. Anyway, for your scenario consider the following recommendations:
|
Hi all, just wanted to respond to this!
We're using Hangfire but with MSSQL. We specifically looked into this, because we wanted to make sure app crashes did not leave any locks hanging. MSSQL uses sp_getapplock, which is tied to the session or transaction, so even killing (kill -9, we did not test power-outage, but I hope it suffices) should release lock. https://learn.microsoft.com/en-us/sql/relational-databases/system-stored-procedures/sp-getapplock-transact-sql?view=sql-server-ver16 I'm NOT a postgres guy, so this is just me suggesting something (because I want to help). For postgres I see there's something called pg_try_advisory_lock and pg_advisory_unlock which should work on the session if I read https://www.postgresql.org/docs/9.1/functions-admin.html correctly. There's also one tied to transaction (see link). We have also been using DistributedLock nuget from madelson, but the SQL version. There's a postgres version which uses these advisory locks: https://github.com/madelson/DistributedLock/blob/master/docs/DistributedLock.Postgres.md so maybe their approach could be a guiding hand to implementing it the same as the MSSQL locks? Hope this can help. Take care. |
The default value of the lock timeout is 10min but if a job takes longer than 10min, it will spawn a new cron job, assuming that the lock timed out. So we set our lock to be more like 6 hours instead. Of course, when the application shuts down, this lock doesn't get cleared which means that job can't run until that lock gets cleared when it expires.
This seems like a bug. Can anyone provide more info on how this works vs how the mssql version works and how to handle it better from my point of view?
The text was updated successfully, but these errors were encountered: