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

Change subject: Reset scoped session for upload jobs after deferred updates
......................................................................


Reset scoped session for upload jobs after deferred updates

Bug: T126450
Change-Id: I8a6588209647252a4509078aaa7bf0cb1d9d299a
---
M includes/jobqueue/Job.php
M includes/jobqueue/JobRunner.php
M includes/jobqueue/jobs/AssembleUploadChunksJob.php
M includes/jobqueue/jobs/PublishStashedFileJob.php
4 files changed, 31 insertions(+), 0 deletions(-)

Approvals:
  Krinkle: Looks good to me, but someone else must approve
  Brian Wolff: Looks good to me, but someone else must approve
  Gergő Tisza: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/jobqueue/Job.php b/includes/jobqueue/Job.php
index 2d13c7e..abab142 100644
--- a/includes/jobqueue/Job.php
+++ b/includes/jobqueue/Job.php
@@ -47,6 +47,9 @@
        /** @var string Text for error that occurred last */
        protected $error;
 
+       /** @var callable[] */
+       protected $teardownCallbacks = [];
+
        /**
         * Run the job
         * @return bool Success
@@ -280,6 +283,25 @@
        }
 
        /**
+        * @param callable $callback
+        * @since 1.27
+        */
+       protected function addTeardownCallback( $callback ) {
+               $this->teardownCallbacks[] = $callback;
+       }
+
+       /**
+        * Do any final cleanup after run(), deferred updates, and all DB 
commits happen
+        *
+        * @since 1.27
+        */
+       public function teardown() {
+               foreach ( $this->teardownCallbacks as $callback ) {
+                       call_user_func( $callback );
+               }
+       }
+
+       /**
         * Insert a single job into the queue.
         * @return bool True on success
         * @deprecated since 1.21
diff --git a/includes/jobqueue/JobRunner.php b/includes/jobqueue/JobRunner.php
index 3919318..60372d1 100644
--- a/includes/jobqueue/JobRunner.php
+++ b/includes/jobqueue/JobRunner.php
@@ -265,6 +265,7 @@
 
                        DeferredUpdates::doUpdates();
                        $this->commitMasterChanges( $job );
+                       $job->teardown();
                } catch ( Exception $e ) {
                        MWExceptionHandler::rollbackMasterChangesAndLog( $e );
                        $status = false;
diff --git a/includes/jobqueue/jobs/AssembleUploadChunksJob.php 
b/includes/jobqueue/jobs/AssembleUploadChunksJob.php
index 4de19bc..3699afe 100644
--- a/includes/jobqueue/jobs/AssembleUploadChunksJob.php
+++ b/includes/jobqueue/jobs/AssembleUploadChunksJob.php
@@ -35,6 +35,10 @@
        public function run() {
                /** @noinspection PhpUnusedLocalVariableInspection */
                $scope = RequestContext::importScopedSession( 
$this->params['session'] );
+               $this->addTeardownCallback( function () use ( &$scope ) {
+                       ScopedCallback::consume( $scope ); // T126450
+               } );
+
                $context = RequestContext::getMain();
                $user = $context->getUser();
                try {
diff --git a/includes/jobqueue/jobs/PublishStashedFileJob.php 
b/includes/jobqueue/jobs/PublishStashedFileJob.php
index 5f8af8b..caedf46 100644
--- a/includes/jobqueue/jobs/PublishStashedFileJob.php
+++ b/includes/jobqueue/jobs/PublishStashedFileJob.php
@@ -37,6 +37,10 @@
        public function run() {
                /** @noinspection PhpUnusedLocalVariableInspection */
                $scope = RequestContext::importScopedSession( 
$this->params['session'] );
+               $this->addTeardownCallback( function () use ( &$scope ) {
+                       ScopedCallback::consume( $scope ); // T126450
+               } );
+
                $context = RequestContext::getMain();
                $user = $context->getUser();
                try {

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I8a6588209647252a4509078aaa7bf0cb1d9d299a
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Aaron Schulz <[email protected]>
Gerrit-Reviewer: Aaron Schulz <[email protected]>
Gerrit-Reviewer: Brian Wolff <[email protected]>
Gerrit-Reviewer: GergÅ‘ Tisza <[email protected]>
Gerrit-Reviewer: Krinkle <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to