Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drush_backend_batch_process() should clear batch_get() #3773

Closed
pfrenssen opened this issue Nov 8, 2018 · 6 comments
Closed

drush_backend_batch_process() should clear batch_get() #3773

pfrenssen opened this issue Nov 8, 2018 · 6 comments

Comments

@pfrenssen
Copy link
Member

Describe the bug
This is coming out of a bug report that was filed for Search API: Issue #3011340: Multiple index update causes drush config import to get stuck.

If a batch operation is added with batch_set() and then processed using drush_backend_batch_process() then the list of batch operations is not cleared. If a second call to drush_backend_batch_process() is made in the same request, then the original set of batch operations is requeued, leading to unexpected results.

To Reproduce

// Define a batch operation.
$batch_definition = [
  'operations' => [[[$this, 'processBatch'], [$task_ids, $conditions]]],
];
batch_set($batch_definition);

// This call will execute the batch operation.
drush_backend_batch_process();

// Define a second batch operation.
$batch_definition = [
  'operations' => [[[$this, 'processBatch'], [$task_ids, $conditions]]],
];
batch_set($batch_definition);

// This call will execute both the first and the second batch operation.
// Since the first one has already been processed this might cause unexpected results.
drush_backend_batch_process();

Expected behavior
drush_backend_batch_process() should clean up batch_get() after it is done.

Workaround

$result = drush_backend_batch_process();
if ($result['context']['drush_batch_process_finished'] === TRUE) {
  $batch = &batch_get();
  $batch = NULL;
}

System Configuration

Q A
Drush version? master
Drupal version? 8.x-dev
PHP version 7.2
OS? Linux
@weitzman
Copy link
Member

weitzman commented Dec 3, 2018

I guess the code below is not sufficient? If we need more code tahts probably where it should go

drush/includes/batch.inc

Lines 345 to 349 in eaf9c3e

if (drush_drupal_major_version() >= 8) {
/** @var \Drupal\Core\Batch\BatchStorage $batch_storage */
$batch_storage = \Drupal::service('batch.storage');
$batch_storage->delete($batch['id']);
}

@batkor
Copy link

batkor commented Nov 12, 2019

subscribe
Thanks @pfrenssen

@lpeabody
Copy link

Just wanted to include this as a potentially related issue https://www.drupal.org/node/3068196, piggybacked from https://www.drupal.org/project/search_api/issues/3019652#comment-13167514. It provides additional context around the discussion @pfrenssen posted in the description.

@plach79
Copy link
Contributor

plach79 commented Nov 3, 2021

Posted a PR implementing @pfrenssen's suggestion at #4886

@plach79
Copy link
Contributor

plach79 commented Nov 3, 2021

For reference I discovered this while testing a fix for https://www.drupal.org/project/user_email_verification/issues/3245192.

@weitzman
Copy link
Member

weitzman commented Nov 5, 2021

Fixed in #4886

@weitzman weitzman closed this as completed Nov 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants