Just fight with suddenly broken drush

$ drush status
Drush command could not be completed.                                                                                                             [error]

And found, that, if I disable MultiLink Redirect -

$ drush status
 Drupal version         :  6.17                                  
 Site URI               :  http://default                        
 Database driver        :  mysqli                                
 Database hostname      :  localhost                             
 Database username      :  example_drupal                          
 Database name          :  www_example                        
 Database               :  Connected                             
 Drupal bootstrap       :  Successful                            
 Drupal user            :  Anonymous                             
 Default theme          :  example                             
 Administration theme   :  pushbutton                            
 PHP configuration      :  /etc/php5/cli/php.ini                 
 Drush version          :  4.0-dev                               
 Drush configuration    :                                        
 Drupal root            :  /home/vaulter/www/example.localhost 
 Site path              :  sites/default                         
 File directory path    :  sites/default/files                   

Comments

Andy Inman’s picture

Status: Active » Postponed (maintainer needs more info)

I regret I have no experience with Drush. Presumably it is trying to use some url which was getting redirected (rightly or wrongly). Was there anything in the Drupal log? Could it be an out of memory problem for example? If you take a look at the multilink redirect module, you'll see it's fairly simple - perhaps you could try to find a solution?

Simon Georges’s picture

Status: Postponed (maintainer needs more info) » Active

I've just reproduced the bug. Activating Multilink_redirect generate this output for drush :

Initialized Drupal 6.19 root directory at /var/www/site                                                                                 [notice]
Initialized Drupal site default at sites/default                                                                                             [notice]
session_start(): Cannot send session cookie - headers already sent by (output started at drush/includes/drush.inc:794)                  [warning]
bootstrap.inc:1162
session_start(): Cannot send session cache limiter - headers already sent (output started at drush/includes/drush.inc:794)              [warning]
bootstrap.inc:1162
Cannot modify header information - headers already sent by (output started at drush/includes/drush.inc:794) bootstrap.inc:726           [warning]
Cannot modify header information - headers already sent by (output started at drush/includes/drush.inc:794) bootstrap.inc:727           [warning]
Cannot modify header information - headers already sent by (output started at drush/includes/drush.inc:794) bootstrap.inc:728           [warning]
Cannot modify header information - headers already sent by (output started at drush/includes/drush.inc:794) bootstrap.inc:729           [warning]
Drush command could not be completed. 

I'm guessing this has something to do with the hook_init()... The only documentation I manged to find mentionned that node_load() should not be called from hook_init(). And I see that _multilink_getnode() calls multilink_buildnode() that performs node_load().

I hope it helps...

Regards,

Andy Inman’s picture

Hi, thanks for that info, very useful. I've not had a chance to look at this yet, Could you give me a link to the docs you refer to? http://api.drupal.org/api/function/hook_init/6 does not mention any restriction on calling node_load() and implies - when this hook is called, all modules are already loaded in memory - that internal Drupal and add-on module functions should be available.

If node_load() is indeed the problem, then it would only happen for non-cached links - I'm referring to multilink's internal caching - see _multilink_getnode() - node_load would not get called if the result were already cached. Try simply commenting-out the node_load (line 316 in multilink.module) - does that make the problem go away? (if you do this, invalid cache entries will be created, so clear multilink's cache table afterwards.)

If we can confirm that node_load is what triggers the problem, then it should be fairly easy to replace node_load with a database query or other function call. An alternative might be to disable redirection when running under Drush - redirection is intended to help users arrive at the correct page, it's probably not needed when running Drush scripts?

Andy Inman’s picture

Don't know if its any help, but the latest version allows the redirection to by bypassed based on permission/role - do Drush scripts effectively run as uid==1 ? If so then it might work now, or if Drush runs as some other user id, then it should be possible to achieve the same.

Andy Inman’s picture

Status: Active » Fixed

Please confirm whether #4 provides a solution. I am supposing that it does and so marking this as "fixed".

Status: Fixed » Closed (fixed)

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

sumpfralle’s picture

Version: 6.x-2.1 » 6.x-2.4
Status: Closed (fixed) » Active

The bug seems to persist with 6.x-2.4 :(
multilink disabled: drush works fine
multilink enabled: drush fails

I am using drush 4.4. The same happens with v3.3.

$ drush -d status
Bootstrap to phase 0. [0.02 sec, 2.2 MB] [bootstrap]
Drush bootstrap phase : _drush_bootstrap_drush() [0.02 sec, 2.43 MB] [bootstrap]
Drush bootstrap phase : _drush_bootstrap_drupal_root() [0.05 sec, 5.83 MB] [bootstrap]
Initialized Drupal 6.19 root directory at /data/drupal [0.06 sec, 6.72 MB] [notice]
Drush bootstrap phase : _drush_bootstrap_drupal_site() [0.06 sec, 6.73 MB] [bootstrap]
Initialized Drupal site fab.senselab.org at sites/fab.senselab.org [0.06 sec, 6.73 MB] [notice]
Drush bootstrap phase : _drush_bootstrap_drupal_configuration() [0.07 sec, 6.74 MB] [bootstrap]
Drush bootstrap phase : _drush_bootstrap_drupal_database() [0.07 sec, 6.78 MB] [bootstrap]
Successfully connected to the Drupal database. [0.07 sec, 6.78 MB] [bootstrap]
Drush bootstrap phase : _drush_bootstrap_drupal_full() [0.07 sec, 7.16 MB] [bootstrap]
Drush command terminated abnormally due to an unrecoverable error. [0.25 sec, 26.99 MB]

do you have any idea how I could debug this issue?
cheers,
Lars

Andy Inman’s picture

Assigned: Unassigned » Andy Inman

I hit this problem myself and confirmed if you disable the Redirection module, then drush works. I guess there must be some easy way to detect that Drupal is being run under drush, and disable redirection - any ideas?

I'll take a closer look at this when I get the chance.

dmatamales’s picture

subscribing

Andy Inman’s picture

Status: Active » Needs review

This problem seems to have gone away - could anyone else confirm? I haven't changed MultiLink specifically to address this issue, so assume that drush or something else has changed. Testing with Drupal 6.22, Drush 4.4, MultiLink 2.5. drush status and other drush commands seem to work fine.

david.gil’s picture

Status: Needs review » Active

With Drupal 7.9, Drush 4.5 it still gives the same error.

Andy Inman’s picture

Thanks for the report David. Are you using the MultiLink "Redirect Cached" module or just the Redirect?

I've opened a new issue against the D7 version here: http://drupal.org/node/1365882

sumpfralle’s picture

Version: 6.x-2.4 » 6.x-2.7

I experienced the same issue: enabling "multilink redirect" causes drush to break. The "redirect cached" module is not in use. Disabling the multilink redirect module immediately fixes the problem ("drush status" works again). I use Drush 4.4.

I posted the list of all installed modules here: http://pastebin.com/TZ4DQyrb

Andy Inman’s picture

It's working fine for me with Drupal 6.22 and Drush 5.4. Any chance you could try that version?

Andy Inman’s picture

Ah, I just remembered that I did add a specific check in the 7.x branch:

    // Only redirect if $_POST is empty, processing index.php and not under Drush #1278930: MultiLink D7 version initial release
    if (empty($_POST) && $_SERVER['SCRIPT_NAME'] == '/index.php' && !function_exists('drush_main')) {

That would need to go into lines 82/83 of multilink_redirect.module where we currently have:

    // Only redirect if $_POST is empty and processing main index.php.
    if (empty($_POST) && $_SERVER['SCRIPT_NAME'] == '/index.php') {

So, it looks like this does need to be implemented in the 6.x branch, though I don't why it only fails with some configurations and not others.

truyenle’s picture

Confirm it, break my Drush also. Drupal 6.26

Andy Inman’s picture

truyenle, please see the solution in #15. That's needed at line 82/83 of multilink_redirect.module.

I need to released an update with this fix included.

Andy Inman’s picture

Status: Active » Closed (fixed)

Now fixed in release 2.8.