drush-ops / drush

Drush is a command-line shell and scripting interface for Drupal, a veritable Swiss Army knife designed to make life easier for those who spend their working hours hacking away at the command prompt.
https://www.drush.org
2.34k stars 1.08k forks source link

drush_backend_batch_process() get stuck because of db_transaction() #2267

Open mxr576 opened 8 years ago

mxr576 commented 8 years ago

It it really a weird issue, does someone experienced something similar to this? I have a code like this:


function first() {
  $transaction = db_transaction();
  try {
    second();

    try {

    }
    catch(Exception $e) {
      throw $e;
    }
  }
  catch (Exception $e) {
    $transaction->rollback();
  }
}

function second() {
  _build_batch();
  $batch = &batch_get();
  if (drupal_is_cli()) {
    $batch['progressive'] = FALSE;
    drush_backend_batch_process();
  }
  else {
  }
}

It seems, because of the $transaction that I've introduced in the first() function the following db_insert() from _drush_backend_batch_process() is not able to commit the insert of this new row to the batch table, therefore the progressing of the batch get stuck, until it is not being halted by someone.

      db_insert('batch')
        ->fields(array(
          'bid' => $batch['id'],
          'timestamp' => REQUEST_TIME,
          'token' => drush_get_token($batch['id']),
          'batch' => serialize($batch),
        ))
        ->execute();

While the _drush_backend_batch_process() was running I also wasn't able to insert this row with the same bid to the batch table by using any external tool, so it seems this row in the batch table has been locked inclusively.

When I remove the transaction from the first() function then this problem goes away, but there was a reason why I used that, so I don't see this a stable solution to this problem.

I've Drush 8.1.2 installed.

mxr576 commented 8 years ago

676 might be related?