jenkins-bot has submitted this change and it was merged.

Change subject: Clean up state of libxml on failed import.
......................................................................


Clean up state of libxml on failed import.

Make sure we always call XMLReader::close() to clean up libxml's internal state,
even if import fails with an exception. Otherwise, any subsequent attempt at 
importing
(or otherwise using an XMLReader) will fail with:

  XMLReader::open(): Unable to open source data

This is particularly annoying for unit tests which should be allowed to fail
without dragging down subsequent tests. Even more importantly, they may
explicitly be testing a failure case, which should not cause subsequent tests
to fail.

NOTE: Wikibase patch Id035ecebebb67 is blocked on this,
please re-check once this is merged.

Change-Id: I31c014df39aa11c11ded70050ef12a8e2c5fefc5
---
M includes/Import.php
1 file changed, 36 insertions(+), 24 deletions(-)

Approvals:
  Aaron Schulz: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/Import.php b/includes/Import.php
index 36028ea..7eff5da 100644
--- a/includes/Import.php
+++ b/includes/Import.php
@@ -497,36 +497,48 @@
 
                $keepReading = $this->reader->read();
                $skip = false;
-               while ( $keepReading ) {
-                       $tag = $this->reader->name;
-                       $type = $this->reader->nodeType;
+               $rethrow = null;
+               try {
+                       while ( $keepReading ) {
+                               $tag = $this->reader->name;
+                               $type = $this->reader->nodeType;
 
-                       if ( !Hooks::run( 'ImportHandleToplevelXMLTag', array( 
$this ) ) ) {
-                               // Do nothing
-                       } elseif ( $tag == 'mediawiki' && $type == 
XMLReader::END_ELEMENT ) {
-                               break;
-                       } elseif ( $tag == 'siteinfo' ) {
-                               $this->handleSiteInfo();
-                       } elseif ( $tag == 'page' ) {
-                               $this->handlePage();
-                       } elseif ( $tag == 'logitem' ) {
-                               $this->handleLogItem();
-                       } elseif ( $tag != '#text' ) {
-                               $this->warn( "Unhandled top-level XML tag $tag" 
);
+                               if ( !Hooks::run( 'ImportHandleToplevelXMLTag', 
array( $this ) ) ) {
+                                       // Do nothing
+                               } elseif ( $tag == 'mediawiki' && $type == 
XMLReader::END_ELEMENT ) {
+                                       break;
+                               } elseif ( $tag == 'siteinfo' ) {
+                                       $this->handleSiteInfo();
+                               } elseif ( $tag == 'page' ) {
+                                       $this->handlePage();
+                               } elseif ( $tag == 'logitem' ) {
+                                       $this->handleLogItem();
+                               } elseif ( $tag != '#text' ) {
+                                       $this->warn( "Unhandled top-level XML 
tag $tag" );
 
-                               $skip = true;
+                                       $skip = true;
+                               }
+
+                               if ( $skip ) {
+                                       $keepReading = $this->reader->next();
+                                       $skip = false;
+                                       $this->debug( "Skip" );
+                               } else {
+                                       $keepReading = $this->reader->read();
+                               }
                        }
-
-                       if ( $skip ) {
-                               $keepReading = $this->reader->next();
-                               $skip = false;
-                               $this->debug( "Skip" );
-                       } else {
-                               $keepReading = $this->reader->read();
-                       }
+               } catch ( Exception $ex ) {
+                       $rethrow = $ex;
                }
 
+               // finally
                libxml_disable_entity_loader( $oldDisable );
+               $this->reader->close();
+
+               if ( $rethrow ) {
+                       throw $rethrow;
+               }
+
                return true;
        }
 

-- 
To view, visit https://gerrit.wikimedia.org/r/189925
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I31c014df39aa11c11ded70050ef12a8e2c5fefc5
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: Aaron Schulz <[email protected]>
Gerrit-Reviewer: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: Reedy <[email protected]>
Gerrit-Reviewer: TTO <[email protected]>
Gerrit-Reviewer: Tim Starling <[email protected]>
Gerrit-Reviewer: Umherirrender <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to