Skip to content

Commit

Permalink
Don't share the same semaphore by multiple storage instances
Browse files Browse the repository at this point in the history
  • Loading branch information
odinserj committed Oct 13, 2020
1 parent 7319063 commit 2eabb17
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/Hangfire.SqlServer/SqlServerJobQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ internal class SqlServerJobQueue : IPersistentJobQueue
private static readonly TimeSpan LongPollingThreshold = TimeSpan.FromSeconds(1);
private static readonly int PollingQuantumMs = 1000;
private static readonly int MinPollingDelayMs = 50;
private static readonly ConcurrentDictionary<string, SemaphoreSlim> Semaphores = new ConcurrentDictionary<string, SemaphoreSlim>();
private static readonly ConcurrentDictionary<Tuple<SqlServerStorage, string>, SemaphoreSlim> Semaphores =
new ConcurrentDictionary<Tuple<SqlServerStorage, string>, SemaphoreSlim>();

private readonly SqlServerStorage _storage;
private readonly SqlServerStorageOptions _options;
Expand Down Expand Up @@ -93,7 +94,7 @@ private SqlServerTimeoutJob DequeueUsingSlidingInvisibilityTimeout(string[] queu

var useLongPolling = false;
var queuesString = String.Join("_", queues.OrderBy(x => x));
var semaphore = Semaphores.GetOrAdd(queuesString, new SemaphoreSlim(initialCount: 1));
var semaphore = Semaphores.GetOrAdd(Tuple.Create(_storage, queuesString), new SemaphoreSlim(initialCount: 1));

var pollingDelayMs = Math.Min(
Math.Max((int)_options.QueuePollInterval.TotalMilliseconds, MinPollingDelayMs),
Expand Down

0 comments on commit 2eabb17

Please sign in to comment.