I get this error when trying to use the drush feeds-import from within a module with exec.

The request loops for 105 seconds then fails on two nodes.

Running drush feeds-import manually works as expected.

I'm trying to have a node save kick off a feed import on some other sites with drush aliases.

Comments

nicxvan created an issue. See original summary.

nicxvan’s picture

Logs from failed import:

2015-12-24 15:41:32	2015-12-24 15:39:49	Imported in 102 seconds.	info
2015-12-24 15:41:32	2015-12-24 15:39:49	Failed importing 2 nodes.	error
2015-12-24 15:41:32	2015-12-24 15:39:49	SQLSTATE[HY000]: General error: 1205 Lock wait timeout exceeded; try restarting transaction
Original item

array(
  'title' => 'Name of Ad',
  'active date' => '10/07/2015 12:24 pm',
  'ad group' => 'Sidebar Ads',
  'ad image' => 'site.com/sites/default/files/field/image/image.png',
  'ad type' => 'graphic',
  'end date' => '10/07/2016 12:00 am',
  'link target' => 'Open destination URL in a new window',
  'status' => 'This ad is active',
  'url address' => 'http://siteb.com/',
  'uuid' => 'f13cddbd-0cd3-4d8e-bd3f-e0c401b1ac4d',
)
Entity

(object) array(
  'language' => 'und',
  'type' => 'simpleads',
  'changed' => 1450989589,
  'created' => 1450989589,
  'is_new' => TRUE,
  'status' => 1,
  'promote' => 0,
  'sticky' => 0,
  'uid' => '1',
  'revision' => FALSE,
  'log' => 'Created by FeedsNodeProcessor',
  'title' => 'Name of Ad',
  'timestamp' => 1450989589,
  'publish_on' => 0,
  'unpublish_on' => 0,
  'uuid' => '0bc25c90-b161-46c0-aa9a-983ce66e8f25',
  'vuuid' => '8635f40e-d85c-419b-9284-8922d2399a53',
  'nid' => '1560',
  'comment' => 0,
  'tnid' => 0,
  'translate' => 0,
  'vid' => '1645',
)
MegaChriz’s picture

Feeds doesn't support drush officially yet, it is only available as a patch in #608408: Drush integration for Feeds, which still needs work. There recently was a fix for a timeout, see #2624344: Import via pushImport() keeps looping / never completes. I see you already commented on that issue, so assume you already are using the latest dev?

I haven't investigated the drush patch at all yet, so I'm not sure how I can help you further on this.

kenorb’s picture

Category: Bug report » Support request
Status: Active » Closed (duplicate)

#2640498: WD node: PDOException: SQLSTATE[HY000]: General error: 1205 Lock wait [error]

Lock wait timeout exceeded

Just increase your timeout limits or improve the Drupal performance in overall.

nicxvan’s picture

What is the duplicate issue?

kenorb’s picture

kenorb’s picture

...

kenorb’s picture

Status: Active » Closed (duplicate)
Related issues: +#608408: Drush integration for Feeds

This should be duplicated of #608408: Drush integration for Feeds (as per #3), because the issue is against the patch which wasn't committed yet and it's still under review. So it should be a comment instead (that patch needs work). Or should contribute to the existing patch. Unless it's the same happening in UI (not from CLI), then free to re-open.

MegaChriz’s picture

Status: Closed (duplicate) » Fixed

I have read a bit on what this error means. Source: #2059439: PDOException: SQLSTATE[HY000]: General error: 1205 Lock wait timeout exceeded; try restarting transaction.

Basically you have a slow running transaction.

So this error means that a database transaction takes too long to complete. In the issue summary is stated that a Feeds import is triggered upon saving a node. I assume you used the hook hook_node_update() for this?

Database transaction in node_save() is open during the whole call of that function

If you look at the contents of the node_save() function you see that a database transaction is opened at the start of the function. It is closed as soon as the execution of the function ends (the PHP garbage collector will call DatabaseTransaction::__destruct(), because the DatabaseTransaction object no longer needs to stay in memory when node_save() ends).
So when hooks like hook_node_presave(), hook_node_insert() and hook_node_update() are invoked, the node_save() transaction is still open.

You can use the Queue API

Running an import with Feeds can take a long time. If it takes longer than say 100 seconds, it is probably a bad idea to run an import right away from within a hook_node_update() implementation, because the node_save() transaction is still open.
Instead, it would be a better idea to queue the operation, so the import would run on cron. You could use the Queue API to create such a queue. The "worker callback" which you define in an implementation of hook_cron_queue_info(), would then execute the code you now have in the implementation of hook_node_update(). Be sure to pass enough context to the Queue item, but keep the data also as small as possible. It is preferable to not pass a whole node object to a queue, but instead only the node ID. Something like this:

/**
 * Implements hook_node_update().
 */
function mymodule_node_update($node) {
  $queue = DrupalQueue::get('myQueue');
  $queue->createItem(array(
    'nid' => $node->nid,
  ));
}

/**
 * Implements hook_cron_queue_info().
 */
function mymodule_cron_queue_info() {
  $queues = array();
  $queues['myQueue'] = array(
    'worker callback' => 'mymodule_run_import',
    'time' => 60,
  );
  return $queues;
}

/**
 * Worker callback for queue "myQueue".
 */
function mymodule_run_import($item) {
  $node = node_load($item['nid']);
  
  // Your import logic here...
}
MegaChriz’s picture

As you said you were calling exec(), an other solution might be to run that command in the background if you do not need the return value of exec() and if there isn't all too much other logic in your hook_node_update() implementation.

Example:

exec('drush feeds-import my_importer > /dev/null 2>/dev/null &');

Source: http://stackoverflow.com/questions/8961470/how-to-make-shell-exec-run-in...

nicxvan’s picture

I think I looked at that stack overflow.

I was using hook_entity_update.

I can post the code below, this was for a local install to test.

function local_utils_entity_update($entity, $type) {

    $x = 1;
    switch($entity->type) {
        case 'article':
            $message = exec('/home/nic/.composer/vendor/bin/drush @sites feeds-import simpleads -y 2>&1 &', $output, $status);
            break;
    }

}

I never did get it working, I ended up just going with setting the feeds to run hourly.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.