]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
Fix #8576 Cancel duplicate self deadlock
authorAlain Spineux <alain@baculasystems.com>
Wed, 29 Dec 2021 18:27:23 +0000 (19:27 +0100)
committerEric Bollengier <eric@baculasystems.com>
Thu, 24 Mar 2022 08:03:04 +0000 (09:03 +0100)
- The DIR self dedlock itself when trying to cancel a dusplicate job
- Use the cancel_thread to do the job

bacula/src/dird/job.c

index 8e7c71f78dfec0ce030486e553d489a95b4c1437..a7274b21f09228b44a1771da95f6c1201b783c24 100644 (file)
@@ -1195,14 +1195,15 @@ bool allow_duplicate_job(JCR *jcr)
          }
          if (cancel_dup || job->CancelRunningDuplicates) {
             /* Zap the duplicated job djcr */
-            UAContext *ua = new_ua_context(jcr);
             Jmsg(jcr, M_INFO, 0, _("Cancelling duplicate JobId=%d.\n"), djcr->JobId);
-            cancel_job(ua, djcr, 60);
-            bmicrosleep(0, 500000);
-            djcr->setJobStatus(JS_Canceled);
-            cancel_job(ua, djcr, 60);
-            free_ua_context(ua);
-            Dmsg2(800, "Cancel dup %p JobId=%d\n", djcr, djcr->JobId);
+            pthread_t thid;
+            int status;
+            djcr->inc_use_count(); // cancel_thread() calls free_jcr()
+            if ((status=pthread_create(&thid, NULL, cancel_thread, (void *)djcr)) != 0) {
+               berrno be;
+               Jmsg1(jcr, M_WARNING, 0, _("Cannot create cancel thread: ERR=%s\n"), be.bstrerror(status));
+               free_jcr(jcr);
+            }
          } else {
              /* Zap current job */
             jcr->setJobStatus(JS_Canceled);