 +       */
 +      int OK=true;
 +      int ret;
-+      while (OK) {
-+         ret = fd->wait_data_intr(5*60, 0); /* wait for data few minutes */
++      while (OK && expect_EndJob) {
 +
++         /* Even if the job is canceled, we let a chance to FD to 
++          * send EndJob message 
++          */
++         if (job_canceled(jcr)) { 
++            OK=false;
+          }
+-         if (job_canceled(jcr)) {
+-            break;
++         
++         /* wait for data few minutes */
++         ret = fd->wait_data_intr(5*60, 0); 
 +         if (ret == 1) {       /* get data */
 +            n = bget_dirmsg(fd);
-+            if (n >= 0 && !fd_ok && 
++            if (n >= 0 && 
 +                (sscanf(fd->msg, EndJob, &jcr->FDJobStatus, &JobFiles,
 +                        &ReadBytes, &JobBytes, &Errors, &VSS, &Encrypt) == 7 ||
 +                 sscanf(fd->msg, OldEndJob, &jcr->FDJobStatus, &JobFiles,
 +                        &ReadBytes, &JobBytes, &Errors) == 5)) {
-+               OK=false;        /* end of loop */
 +               fd_ok = true;
 +               set_jcr_job_status(jcr, jcr->FDJobStatus);
++               OK=false;        /* end of loop */
 +            } else {
 +               Jmsg(jcr, M_WARNING, 0, _("Unexpected Client Job message: %s\n"),
 +                    fd->msg);

-   Dmsg1(400, "after wait for sd. use=%d\n", jcr->use_count());
+   Dmsg1(400, "wait for sd and fd. use=%d\n", jcr->use_count());
+   /* Get status from SD and FD */
+   wait_for_job_termination(jcr);   /* TODO: don't expect the EndJob message */
+   Dmsg1(400, "after wait for sd and fd. use=%d\n", jcr->use_count());
    return false;
 }
 
@@ -343,7 +343,7 @@
  *   are done, we return the job status.
  * Also used by restore.c
  */
-int wait_for_job_termination(JCR *jcr, int timeout)
+int wait_for_job_termination(JCR *jcr)
 {
    int32_t n = 0;
    BSOCK *fd = jcr->file_bsock;
@@ -353,40 +353,43 @@
    uint64_t JobBytes = 0;
    int VSS = 0;
    int Encrypt = 0;

+         if (is_bnet_error(fd)) {
+            Jmsg(jcr, M_FATAL, 0, _("Network error with FD during %s: ERR=%s\n"),
+                 job_type_to_str(jcr->get_JobType()), fd->bstrerror());
+            OK=false;
          }
       }
