[FileBackend] Clear swift connection on invalid HTTP responses.
authorAaron <aschulz@wikimedia.org>
Fri, 31 Aug 2012 17:22:02 +0000 (10:22 -0700)
committerAaron <aschulz@wikimedia.org>
Fri, 31 Aug 2012 17:22:02 +0000 (10:22 -0700)
Change-Id: I1a42b1a4d5fea9ea9fa7b80f97f9b98c29041efb

includes/filebackend/SwiftFileBackend.php

index 4d47302..4ee02aa 100644 (file)
@@ -1202,6 +1202,19 @@ class SwiftFileBackend extends FileBackendStore {
                return $this->conn;
        }
 
+       /**
+        * Close the connection to the Swift proxy
+        *
+        * @return void
+        */
+       protected function closeConnection() {
+               if ( $this->conn ) {
+                       $this->conn->close(); // close active cURL handles in CF_Http object
+                       $this->sessionStarted = 0;
+                       $this->connContainerCache->clear();
+               }
+       }
+
        /**
         * Get the cache key for a container
         *
@@ -1315,6 +1328,7 @@ class SwiftFileBackend extends FileBackendStore {
                }
                if ( $e instanceof InvalidResponseException ) { // possibly a stale token
                        $this->srvCache->delete( $this->getCredsCacheKey( $this->auth->username ) );
+                       $this->closeConnection(); // force a re-connect and re-auth next time
                }
                wfDebugLog( 'SwiftBackend',
                        get_class( $e ) . " in '{$func}' (given '" . FormatJson::encode( $params ) . "')" .