diff --git a/lib/SimpleSAML/Metadata/Sources/MDQ.php b/lib/SimpleSAML/Metadata/Sources/MDQ.php
index d85a09ba158a7ce2d9b655d9b3a41bc536598540..975f79246690ff581b83b376ca4d874ef2fe6aa7 100644
--- a/lib/SimpleSAML/Metadata/Sources/MDQ.php
+++ b/lib/SimpleSAML/Metadata/Sources/MDQ.php
@@ -262,7 +262,8 @@ class MDQ extends \SimpleSAML_Metadata_MetaDataStorageSource
      *
      * @return array An associative array with metadata for the given entity, or NULL if we are unable to
      *         locate the entity.
-     * @throws \Exception If an error occurs while downloading metadata, validating the signature or writing to cache.
+     * @throws \Exception If an error occurs while validating the signature or the metadata is in an
+     *         incorrect set.
      */
     public function getMetaData($index, $set)
     {
@@ -272,7 +273,13 @@ class MDQ extends \SimpleSAML_Metadata_MetaDataStorageSource
         Logger::info(__CLASS__.': loading metadata entity ['.$index.'] from ['.$set.']');
 
         // read from cache if possible
-        $data = $this->getFromCache($set, $index);
+        try {
+            $data = $this->getFromCache($set, $index);
+        } catch (\Exception $e) {
+            Logger::error($e->getMessage());
+            // proceed with fetching metadata even if the cache is broken
+            $data = null;
+        }
 
         if ($data !== null && array_key_exists('expires', $data) && $data['expires'] < time()) {
             // metadata has expired
@@ -292,14 +299,15 @@ class MDQ extends \SimpleSAML_Metadata_MetaDataStorageSource
         try {
             $xmldata = HTTP::fetch($mdq_url);
         } catch (\Exception $e) {
-            Logger::warning('Fetching metadata for '.$index.': '.$e->getMessage());
+            // Avoid propagating the exception, make sure we can handle the error later
+            $xmldata = false;
         }
 
         if (empty($xmldata)) {
             $error = error_get_last();
-            throw new \Exception(
-                'Error downloading metadata for "'.$index.'" from "'.$mdq_url.'": '.$error['message']
-            );
+            Logger::info('Unable to fetch metadata for "'.$index.'" from '.$mdq_url.': '.
+                (is_array($error) ? $error['message'] : 'no error available'));
+            return null;
         }
 
         /** @var string $xmldata */
@@ -317,7 +325,12 @@ class MDQ extends \SimpleSAML_Metadata_MetaDataStorageSource
             throw new \Exception(__CLASS__.': no metadata for set "'.$set.'" available from "'.$index.'".');
         }
 
-        $this->writeToCache($set, $index, $data);
+        try {
+            $this->writeToCache($set, $index, $data);
+        } catch (\Exception $e) {
+            // Proceed without writing to cache
+            Logger::error('Error writing MDQ result to cache: '.$e->getMessage());
+        }
 
         return $data;
     }
diff --git a/lib/SimpleSAML/Utils/HTTP.php b/lib/SimpleSAML/Utils/HTTP.php
index abeca2e287b2d439be9f404992fd27d750a81bc4..03b4d1bab3dfa211614ff08c78c11a396eab5e00 100644
--- a/lib/SimpleSAML/Utils/HTTP.php
+++ b/lib/SimpleSAML/Utils/HTTP.php
@@ -444,7 +444,7 @@ class HTTP
         }
 
         $context = stream_context_create($context);
-        $data = file_get_contents($url, false, $context);
+        $data = @file_get_contents($url, false, $context);
         if ($data === false) {
             $error = error_get_last();
             throw new \SimpleSAML_Error_Exception('Error fetching '.var_export($url, true).':'.