Andreas Thienemann b41752
Andreas Thienemann b41752
This patch should fix the spurious connection drops that fail jobs
Andreas Thienemann b41752
as reported in bug #888.
Andreas Thienemann b41752
Apply it to version 2.0.3 (possibly earlier versions of 2.0) with:
Andreas Thienemann b41752
Andreas Thienemann b41752
  cd <bacula-source>
Andreas Thienemann b41752
  patch -p0 <2.0.3-tls-disconnect.patch
Andreas Thienemann b41752
  make
Andreas Thienemann b41752
  ...
Andreas Thienemann b41752
  make install
Andreas Thienemann b41752
Andreas Thienemann b41752
Index: src/lib/tls.c
Andreas Thienemann b41752
===================================================================
Andreas Thienemann b41752
--- src/lib/tls.c	(revision 4668)
Andreas Thienemann b41752
+++ src/lib/tls.c	(working copy)
Andreas Thienemann b41752
@@ -540,14 +540,6 @@
Andreas Thienemann b41752
     * The first time to initiate the shutdown handshake, and the second to
Andreas Thienemann b41752
     * receive the peer's reply.
Andreas Thienemann b41752
     *
Andreas Thienemann b41752
-    * However, it is valid to close the SSL connection after the initial
Andreas Thienemann b41752
-    * shutdown notification is sent to the peer, without waiting for the
Andreas Thienemann b41752
-    * peer's reply, as long as you do not plan to re-use that particular
Andreas Thienemann b41752
-    * SSL connection object.
Andreas Thienemann b41752
-    *
Andreas Thienemann b41752
-    * Because we do not re-use SSL connection objects, I do not bother
Andreas Thienemann b41752
-    * calling SSL_shutdown a second time.
Andreas Thienemann b41752
-    *
Andreas Thienemann b41752
     * In addition, if the underlying socket is blocking, SSL_shutdown()
Andreas Thienemann b41752
     * will not return until the current stage of the shutdown process has
Andreas Thienemann b41752
     * completed or an error has occured. By setting the socket blocking
Andreas Thienemann b41752
@@ -560,6 +552,10 @@
Andreas Thienemann b41752
    flags = bnet_set_blocking(bsock);
Andreas Thienemann b41752
 
Andreas Thienemann b41752
    err = SSL_shutdown(bsock->tls->openssl);
Andreas Thienemann b41752
+   if (err == 0) {
Andreas Thienemann b41752
+      /* Finish up the closing */
Andreas Thienemann b41752
+      err = SSL_shutdown(bsock->tls->openssl);
Andreas Thienemann b41752
+   }
Andreas Thienemann b41752
 
Andreas Thienemann b41752
    switch (SSL_get_error(bsock->tls->openssl, err)) {
Andreas Thienemann b41752
       case SSL_ERROR_NONE:
Andreas Thienemann b41752
@@ -574,8 +570,6 @@
Andreas Thienemann b41752
          break;
Andreas Thienemann b41752
    }
Andreas Thienemann b41752
 
Andreas Thienemann b41752
-   /* Restore saved flags */
Andreas Thienemann b41752
-   bnet_restore_blocking(bsock, flags);
Andreas Thienemann b41752
 }
Andreas Thienemann b41752
 
Andreas Thienemann b41752
 /* Does all the manual labor for tls_bsock_readn() and tls_bsock_writen() */