{"record":{"id":"8071841384f3197c","repo":"abpframework/abp","slug":"the-distributed-lock-name-lockname-is-already","errorCode":null,"errorMessage":"The distributed lock name '{lockName}' is already used by another background job worker. Each worker must have a unique lock name.","messagePattern":"The distributed lock name '(.+?)' is already used by another background job worker\\. Each worker must have a unique lock name\\.","errorType":"exception","errorClass":"AbpException","httpStatus":null,"severity":"error","filePath":"framework/src/Volo.Abp.BackgroundJobs/Volo/Abp/BackgroundJobs/AbpBackgroundJobWorkerOptions.cs","lineNumber":144,"sourceCode":"    /// <param name=\"jobArgsTypes\">The job argument types handled exclusively by this worker.</param>\n    public AbpBackgroundJobWorkerOptions AddDedicatedWorker(string lockName, params Type[] jobArgsTypes)\n    {\n        Check.NotNullOrEmpty(jobArgsTypes, nameof(jobArgsTypes));\n\n        var configuration = new BackgroundJobWorkerConfiguration(lockName, jobArgsTypes.Distinct().ToArray());\n\n        var duplicateType = configuration.JobArgsTypes.FirstOrDefault(\n            type => WorkerConfigurations.Any(c => c.JobArgsTypes.Contains(type)));\n        if (duplicateType != null)\n        {\n            throw new AbpException(\n                $\"The background job args type '{duplicateType.FullName}' is already assigned to a dedicated worker. \" +\n                $\"Each job type can be handled by only one dedicated worker.\");\n        }\n\n        if (lockName == DistributedLockName || WorkerConfigurations.Any(c => c.LockName == lockName))\n        {\n            throw new AbpException(\n                $\"The distributed lock name '{lockName}' is already used by another background job worker. \" +\n                $\"Each worker must have a unique lock name.\");\n        }\n\n        WorkerConfigurations.Add(configuration);\n        return this;\n    }\n\n    public AbpBackgroundJobWorkerOptions AddDedicatedWorker<TArgs>(string lockName)\n    {\n        return AddDedicatedWorker(lockName, typeof(TArgs));\n    }\n\n    public AbpBackgroundJobWorkerOptions AddDedicatedWorker<TArgs1, TArgs2>(string lockName)\n    {\n        return AddDedicatedWorker(lockName, typeof(TArgs1), typeof(TArgs2));\n    }\n","sourceCodeStart":126,"sourceCodeEnd":162,"githubUrl":"https://github.com/abpframework/abp/blob/7ed43b1931b9df46a50c0c59148a18645641d0df/framework/src/Volo.Abp.BackgroundJobs/Volo/Abp/BackgroundJobs/AbpBackgroundJobWorkerOptions.cs#L126-L162","documentation":"Thrown by AbpBackgroundJobWorkerOptions.AddDedicatedWorker when the supplied lockName equals the global DistributedLockName or matches the LockName of any existing BackgroundJobWorkerConfiguration. Each dedicated worker needs a unique distributed lock so workers don't contend under the same lock identity.","triggerScenarios":"Calling AddDedicatedWorker(lockName, ...) with a lockName that is already in use - either the global DistributedLockName or another worker's LockName.","commonSituations":"Two workers registered with the same hard-coded lock name; a lock name colliding with the default DistributedLockName; refactoring that copied a worker registration and forgot to rename the lock; multiple modules choosing generic lock names.","solutions":["Give each dedicated worker a distinct, descriptive lock name.","Avoid reusing the global DistributedLockName value for any worker.","Audit all AddDedicatedWorker call sites and deduplicate lock names.","Derive lock names from the job type or feature to avoid collisions."],"exampleFix":"// before\noptions.AddDedicatedWorker(\"jobs-lock\", typeof(EmailJobArgs));\noptions.AddDedicatedWorker(\"jobs-lock\", typeof(SmsJobArgs)); // throws\n// after\noptions.AddDedicatedWorker(\"email-jobs-lock\", typeof(EmailJobArgs));\noptions.AddDedicatedWorker(\"sms-jobs-lock\", typeof(SmsJobArgs));","handlingStrategy":"validation","validationCode":"var usedLocks = options.WorkerConfigurations.Select(c => c.LockName)\n    .Append(options.DistributedLockName).ToHashSet();\nif (usedLocks.Contains(lockName)) { /* pick a distinct name */ }","typeGuard":"null","tryCatchPattern":"try { options.AddDedicatedWorker(lockName, types); }\ncatch (AbpException ex) when (ex.Message.Contains(\"unique lock name\"))\n{ /* choose a different lock name */ }","preventionTips":["Derive lock names from the feature/job type to ensure uniqueness.","Never reuse the global DistributedLockName for a worker.","Audit all AddDedicatedWorker call sites at startup.","Add a startup sanity test asserting unique lock names."],"tags":["background-jobs","abp","configuration","distributed-lock","duplicate"],"backgroundTag":null,"analyzedSha":"7ed43b1931b9df46a50c0c59148a18645641d0df","analyzedAt":"2026-08-13T16:26:11.351Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}