Suggestions for those arriving at this issue based on the error message

  • Look for calls to drupal_goto. These calls should be wrapped in a call to drupal_is_cli before doing a drupal_goto.
  • Look for calls to 'exit;' in the code path
  • Make sure the uri in the drush alias is exactly as it is accessed in browser. If http://example.com redirects to http://www.example.com then you must type www.example.com in the drush alias uri.
  • Make a brand new install of Drupal and see if the problem happens again. If not - what is different between the sites?
  • Some modules that can cause this problem include require_login, secure_site, mobile_tools, restrict_ip

original report

Linux 2.6.18-194.32.1.el5
PHP 5.2.17 (cli), /etc/php.ini memory_limit = 2G (there's no other php.ini file)
Parallels Plesk Panel 9.5.4

drush fails inside drupal root, but drush status completes outside drupal root. spent an hour in #drupal with no luck. any help?

[root@ drush(outside drupal root)]# drush -v -d status
Bootstrap to phase 0. [0.03 sec, 1.98 MB] [bootstrap]
Drush bootstrap phase : _drush_bootstrap_drush() [0.03 sec, 2.18 MB] [bootstrap]
Found command: core-status (commandfile=core) [0.07 sec, 5.01 MB] [bootstrap]
Initializing drush commandfile: user [0.07 sec, 5.01 MB] [bootstrap]
PHP configuration : /etc/php.ini
Drush version : 4.4
Drush configuration :
Drush alias files :

Command dispatch complete [0.07 sec, 5.01 MB] [notice]
Peak memory usage was 5.06 MB [0.07 sec, 5.01 MB] [memory]

[root@ httpdocs(inside drupal root)]# drush -v -d status
Bootstrap to phase 0. [0.03 sec, 1.98 MB] [bootstrap]
Drush bootstrap phase : _drush_bootstrap_drush() [0.03 sec, 2.18 MB] [bootstrap]
Drush bootstrap phase : _drush_bootstrap_drupal_root() [0.07 sec, 5.01 MB] [bootstrap]
Initialized Drupal 6.20 root directory at /var/www/vhosts/*/httpdocs [0.09 sec, 5.81 MB] [notice]
Drush bootstrap phase : _drush_bootstrap_drupal_site() [0.09 sec, 5.81 MB] [bootstrap]
Initialized Drupal site default at sites/default [0.09 sec, 5.81 MB] [notice]
Drush bootstrap phase : _drush_bootstrap_drupal_configuration() [0.11 sec, 5.82 MB] [bootstrap]
Drush bootstrap phase : _drush_bootstrap_drupal_database() [0.11 sec, 5.85 MB] [bootstrap]
Successfully connected to the Drupal database. [0.11 sec, 5.86 MB] [bootstrap]
Drush bootstrap phase : _drush_bootstrap_drupal_full() [0.12 sec, 6.2 MB] [bootstrap]
Drush command terminated abnormally due to an unrecoverable error. [0.36 sec, 31.22 MB] [error]

Comments

jptaranto’s picture

Looks like I'm having exactly the same problems too - although only on one drupal site.

Tried using a different database to no avail.

sidharth_k’s picture

I'm getting the exact same issue with version 4.4

Frustrating ... spent a long time on this :-)

jonhattan’s picture

Status: Active » Postponed (maintainer needs more info)

Only thing I can think of is to comment out ob_start() in includes/environment.inc:968 and see if drupal dumps any error.

sidharth_k’s picture

I am no longer getting this problem.

My setup: my site is available on root url lets say http://www.example.com/

In the drupal root directory (say /var/websites/example) when I do:

drush -l www.example.com <name of drush command>

It works fine and I don't get unrecoverable error. (Please note you must type the url in drush exactly as it is accessed in browser. If http://example.com redirects to http://www.example.com then you must type www.example.com in drush. It will fail otherwise.)

If i just type

drush <name of drush command>

then I get the unrecoverable error
Please note that my site settings are in sites/default

Alex Andrascu’s picture

I'm still getting this on a localhost install. Tried the -l http://localhost option mentioned above but it didn't cope.

:~/www/blottr$ sudo drush -v -d status
Bootstrap to phase 0. [0.02 sec, 1.27 MB]                            [bootstrap]
Drush bootstrap phase : _drush_bootstrap_drush() [0.02 sec, 1.35 MB] [bootstrap]
Drush bootstrap phase : _drush_bootstrap_drupal_root() [0.05 sec, 3.1 MB]                                                                                              [bootstrap]
Initialized Drupal 6.20 root directory at /home/alex/www/blottr [0.07 sec, 3.68 MB]                                                                                       [notice]
Drush bootstrap phase : _drush_bootstrap_drupal_site() [0.07 sec, 3.69 MB]                                                                                             [bootstrap]
Initialized Drupal site default at sites/default [0.07 sec, 3.69 MB]                                                                                                      [notice]
Drush bootstrap phase : _drush_bootstrap_drupal_configuration() [0.07 sec, 3.69 MB]                                                                                    [bootstrap]
Drush bootstrap phase : _drush_bootstrap_drupal_database() [0.08 sec, 3.71 MB]                                                                                         [bootstrap]
Successfully connected to the Drupal database. [0.08 sec, 3.71 MB]                                                                                                     [bootstrap]
Drush bootstrap phase : _drush_bootstrap_drupal_full() [0.08 sec, 3.95 MB]                                                                                             [bootstrap]
Drush command terminated abnormally due to an unrecoverable error. [0.46 sec, 24.8 MB]                                                                                 [error]

moshe weitzman’s picture

Sorry, there is nothing in that debug log that identifies a cause. I suggest trying on a virgin drupal site on the same server and/or on a different server. Could be that a no core module is failing.

AndyZhang’s picture

I encountered the same problem on my site. After some debug I found that it's caused by one of our customized modules. The module implements the hook_init and inside it we redirect the user login process to other site. After I disabled the module drush works correctly. Probably you can have a try to disable some customized modules and see if drush work or not. Good luck.

bkosborne’s picture

Same for me as above. I had mobile tools enabled.... which normally redirects to a mobile site. Disabled to run drush.

moshe weitzman’s picture

Status: Postponed (maintainer needs more info) » Closed (works as designed)

Sounds like misbehaving modules that assume all requests come via the web

epruett’s picture

Seeing this same error on all Drupal 6 localhost sites.
Drush command terminated abnormally due to an unrecoverable error. - error

  • Will run drush st fine.
  • Error on drush up.
  • Error on drush pml.
  • Seeing better performance but still some errors on Drupal 7 localhost sites.

  • Will run drush st fine.
  • Will run drush dl
  • Will run drush en with error but does enable the module.
  • Will run drush pml
  • js’s picture

    For me, the problem was a dumb use of "exit" in a script.

    It took me a very long time before I looked inside drush.php, and found

    // We did not reach the end of the drush_main function,
    // this generally means somewhere in the code a call to exit(),
    // was made. We catch this, so that we can trigger an error in
    // those cases.

    as the needed clue. I hope posting this here helps. Perhaps Drush could have an exit message.

    tonylegrone’s picture

    I have confirmed that using Rerquire Login http://drupal.org/project/require_login crashed drush on one of my sites. Disabling it fix the drush problem.

    There's an apparent fix for it here: http://drupal.org/node/828164, but I didn't need to try it.

    Countzero’s picture

    I can confirm tha this error was triggered by a drupal_goto call in hook_init in a custom module.

    Trying to find some code to test where the request comes from to disable the redirect when drush is the user-agent.

    jptaranto’s picture

    Finally figured out is was caused by the secure_site module being enabled locally. Turned it off via settings.php and drush works great now.

    benjamin_dk’s picture

    +1 with mobile tools being the culprit. Disabled. Thanks for sharing your experience.

    bobfoss’s picture

    @Countzero: Using the $_SERVER['SCRIPT_FILENAME'] you can check if drush.php was run.

    Countzero’s picture

    Thanks bobfoss. Tried a few variables round there but had to move on to the next activity ... Will give it a try next time.

    gambaweb’s picture

    drupal_goto (or some other redirect) at hook_boot or hook_init can case that

    Elijah Lynn’s picture

    This also happened to me when I ran a non applicable command on a drush alias to a remote server. For instance if the remote site has not been setup yet and you run "drush @alias st" it will throw this error (Drush command terminated abnormally due to an unrecoverable error), on a local machine it will output information such as where the php.ini is, the Drush version and location of config and alias files.

    I am not sure if it is possible to output the same information from the remote as it does when you run it locally but just thought I would add this here. At the least the error message could be improved upon. I was using Drush 4.5 on local and remote, if it matters.

    Sutharsan’s picture

    For the record, this error also caused by Single Sign On module, version 6.x-1.1.

    zilverdistel’s picture

    Just wondering, has this been reported in the named modules that cause these problems?

    Greetz,

    Diederik

    Marc Angles’s picture

    I lost a lot of time to find that shield-6.1-1 is doing the same thing

    zhuzhuojiang’s picture

    Thanks @gambaweb,
    For mark, require_login module causes this issume.

    rhibbitts’s picture

    Just ran into the same issue. It's caused by drupal_goto() in a custom module. Wrapping the drupal_goto() in:

    if (!function_exists('drush_main')) { 
    // module contents
    }
    

    fixes the issue.

    ñull’s picture

    When you use the module restrict_ip you have to add 127.0.0.1 on your whitelist otherwise you see this same error. See: #1325370: Ignore drush when checking IPs [Patch attached]

    ressa’s picture

    *EDIT*: Nevermind, I am using the Shield module now during testing.

    I was using a custom module which prompts for user and password while testing a web site. Disabling it made the error go away, and Drush archive-dump now works again. Does anyone know if the code below can be fixed, so that it works with Drush, while enabled?

    /**
     * Implementation of hook_boot().
     *
     * Ask for user credentials and try to authenticate.
     */
    function test_access_boot() {
      require_once DRUPAL_ROOT . '/includes/password.inc';
    
      if (isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])) {
        $query = "SELECT pass FROM {users} WHERE name = :name";
        $result = db_query($query, array(':name' => $_SERVER['PHP_AUTH_USER']));
        $account = new stdClass();
        foreach ($result as $row) {
          $account->pass = $row->pass;
        }
        if (isset($account->pass)) {
          if (user_check_password($_SERVER['PHP_AUTH_PW'], $account)) {
            return;
          }
        }
      }
    
      header('WWW-Authenticate: Basic realm="Development"');
      header('HTTP/1.0 401 Unauthorized');
      exit;
    }
    
    ressa’s picture

    Issue summary: View changes

    some day I'll learn how html works

    snappermorgan’s picture

    You are a lifesaver! I thought I was resigned to disabling each module until I found the culprit. As soon as I read your comment I added the IP address to the whitelist and BOOM, hours of work avoided.

    Consider yourself high-fived.

    dman’s picture

    Me too! Thanks fo this thread - I also found a drupal+goto in a custom modules hook_init.
    Had to disable it at the database lever (as drush dis would not co-operate)
    but it was up again after that.

    greggles’s picture

    Issue summary: View changes

    x

    greggles’s picture

    Issue summary: View changes

    x

    ressa’s picture

    Thank you @sidharth_k! Adding www in front fixed the error, since I have a redirect from non-www to www in my settings.php:

    Please note you must type the url in drush exactly as it is accessed in browser. If http://example.com redirects to http://www.example.com then you must type www.example.com in drush. It will fail otherwise.)

    ressa’s picture

    Issue summary: View changes
    babruix’s picture

    I had that several times, reason usually is drupal_goto in some hook_boot or hook_init.
    Not sure,but maybe it makes sense to add in future this:

      if (function_exists('drush_main')) {
        return;
      }
    

    inside drupal_goto function ?

    Jean-Marc’s picture

    Hi,

    got this issue,

    jm@ubutest:/var/www/itcorail.be/drupal$ sudo drush -vvvv -d status
    [sudo] password for jm: 
    Bootstrap to phase 0. [0.02 sec, 2.79 MB]                            [bootstrap]
    Drush bootstrap phase : _drush_bootstrap_drush() [0.16 sec, 3.02 MB] [bootstrap]
    strtr(): The second argument is not an array drush.inc:643 [0.21 sec,[warning]
    7.17 MB]
    strtr(): The second argument is not an array drush.inc:643 [0.21 sec,[warning]
    7.19 MB]
    strtr(): The second argument is not an array drush.inc:643 [0.21 sec,[warning]
    7.19 MB]
    strtr(): The second argument is not an array drush.inc:643 [0.21 sec,[warning]
    7.22 MB]
    strtr(): The second argument is not an array drush.inc:643 [0.22 sec,[warning]
    7.72 MB]
    strtr(): The second argument is not an array drush.inc:643 [0.22 sec,[warning]
    7.72 MB]
    strtr(): The second argument is not an array drush.inc:643 [0.22 sec,[warning]
    7.72 MB]
    strtr(): The second argument is not an array drush.inc:643 [0.22 sec,[warning]
    7.72 MB]
    strtr(): The second argument is not an array drush.inc:643 [0.22 sec,[warning]
    7.73 MB]
    PHP Fatal error:  Call to undefined function drush_shell_exec_proc_build_options() in /usr/share/drush/commands/core/ssh.drush.inc on line 17
    Drush command terminated abnormally due to an unrecoverable error.   [error]
    Error: Call to undefined function
    drush_shell_exec_proc_build_options() in
    /usr/share/drush/commands/core/ssh.drush.inc, line 17 [0.23 sec, 8.23
    MB]
    

    does anyone has any idea of what to do ?
    Working on Vmware ubuntu x64

    I got this issue since drush cannot be only installed by git clone

    Thanks in advance for your help

    asiby’s picture

    Hi guys

    In my case, I was getting this error message dues to a call to the exit() language construct. Although I was using exit(0) to let Linux know that the execution ended normally without errors (as any other Linux executable would), nothing was working. I am starting to think that it is a PHP bug.

    I removed the exit() call and now Drush is ending normally with the following message...

    Command dispatch complete [1.21 sec, 37.6 MB]                                                                                                                                                                        [notice]
     Timer  Cum (sec)  Count  Avg (msec)
     page   1.148      1      1148.47
    
    Peak memory usage was 37.73 MB [1.21 sec, 37.6 MB]
    grincon’s picture

    restrict_ip was the problem for me. Added 127.0.0.1 to the whitelist and all set.

    Thank you

    rakesh.gectcr’s picture

    #18 Works for me...

    We should not write "drupal_goto (or some other redirect) at hook_boot or hook_init "

    Use Rules modules instead of that...

    liquidcms’s picture

    using Drush 6 (gave up trying to install Drush 7)

    i have tried a simple
    drush up admin_menu --uri=http://[my-local-site]
    on numerous sites

    - many work ok
    - one states: Drush command terminated abnormally due to an unrecoverable error
    - one states: Command pm-update needs the following modules installed/enabled to [error]
    run: update. The drush command 'up admin_menu' could not be executed. [error]

    the 2 that don't work have none of the modules mentioned above and run properly from browser. They do both user PURL which i thought might be an issue; but they give different error messages; so not sure.

    liquidcms’s picture

    and sure enough, on the site that was causing the "Drush command terminated abnormally due to an unrecoverable error" i disabled PURL and drush up works.. unfortunate that Drush won't work with PURL as it is on a lot of sites we do.

    gurukatre’s picture

    The same issue came to me when i used die; in my module.module file.

    wuinfo - Bill Wu’s picture

    Something to add on to:
    https://www.drupal.org/node/1140842#comment-8482899
    https://www.drupal.org/node/1140842#comment-4488068

    with HTTPS:

    I have this problem recently. It turned out to be the 301 redirect script in the settings.php file.

    Basically: I redirect all site traffic to https://www.example.com.

    drush -l https://www.example.com <name of drush command>

    rbilinda’s picture

    Making a redirect in your module using like drupal_goto() without a mechanism like
    function_exists('drush_main') to detect whether they are being called from Drush or not, will cause Drush to fail, especially if it involves login.

    Credit
    @babruix
    https://www.drupal.org/node/1181308
    https://www.drupal.org/node/827478

    Ewout Goosmann’s picture

    When og_purl and purl were disabled, it was possible to run "drush cc all". After enabling the purl module, it was still possible to run drush cc all. When I enabled the og_purl module again, drush throws the error "Drush command terminated abnormally due to an unrecoverable error.".

    When you took a quick look at the code of the og_purl module, it calls

    purl_goto($_GET['q'], $purl_params);
    

    in the og_purl_init function. Probably that's the problem.

    The abnormal thing is that it has worked for weeks/months without updating the module. (Last update was 2014-Nov-13).

    At the moment I don't have a fix for this problem yet.
    Here's a patch: https://www.drupal.org/node/2712389

    stoickthevast’s picture

    After 4 hours of debugging on this problem I found out that in my case it is caused by Trigger and Action. My hook_update_N is to create a node from a json file and my "action and trigger" is a redirection after creating a node. Removing the action fixed the problem.

    DocDJ-forum’s picture

    Trying to upgrade for D7.43 to d8.1, starting with a clean Drupal install, and NO DB, I am getting the same error as reported above. Next, I cleared the cache and did a drush migrate-reset-status, which reported "migration does not exist". So I reran the migration, which reported "migration contact_category is busy with another operation: importing". drush continued a bit further, then failed again with "call to undefined function field_read_fields() in registration.module at line 1286.

    Any ideas what I'm doing wrong.

    ngocketit’s picture

    #18 works. drupal_is_cli() can be used to determine if it's drush request.

    DocDJ-forum’s picture

    I have NO modifications to ANY files, so drupal_is_cli() and discussion of hooks have no meaning for me. I deleted EVERYTHING related to my D8 install, then pulled in all the 8.0.0 files, then the 8.1.2 update files and did the INSTALL.PHP (which is in CORE, not in the root). I then tried drush migrate-upgrade .... and that failed with:

    Error: Call to undefined function field_read_fields() in E:\DJs
    Documents\public_html\Drupal_80\modules\registration\registration.module,
    line 1286

    .

    Is there a better place to report this problem?

    Config: Drupal 8.1.2, PHP 5.6, MySQL 5.6, Apache 2.4, Windows 10 Pro.

    jimkeller’s picture

    Ran into this issue on a Drupal 7 site; turns out that manually disabling the shield module does the trick (steps below). This is mentioned above as well, but Shield calls exit() in hook_boot() after sending the http headers for authorization, which basically just kills the PHP script when running as a CLI.

    To disable the shield module manually:
    1. Login to the database using the mysql console (or phpMyAdmin or whatever) and run the following command:
    UPDATE system SET status=0 WHERE name='shield' AND type='module'

    2. Exit mySQL and run: drush rr
    (if this fails, try: drush dl registry_rebuild and then run drush rr . See: https://www.drupal.org/project/registry_rebuild)

    3. drush should now work

    sidharthap’s picture

    I came across same issue Drush command terminated abnormally due to an unrecoverable error and builds get failed. After spending couple of hours and debugging code I found drupal_goto written in custom code causes the issue after Drupal up gradation.

    I just correct the code not to run in cli ( drupal_is_cli() )mode resolve the issue for me.

    ressa’s picture

    Switching to HTTPS caused this for me, adding https:// in aliases.drushrc.php fixed it:

    <?php
    $aliases['example'] = array(
      'root' => '/home/example/public_html',
      'uri' => 'https://example.org',
    );
    bolshii’s picture

    #34 works for me.

    Thx a lot :)

    ioannis.cherouvim’s picture

    I had this problem on Drupal 7 with Drush 8.4.5 and it turns out that the problem was the following in `settings.php`:

    'init_commands' => array(
      'sql_mode' => "SET sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'",
    ),
    

    Removing it fixed the issue.

    salah1’s picture

    In my case the :warning Drush command terminated abnormally
    was a result of drush crashing due to memory exhaustion.

    See:
    https://drupal.stackexchange.com/questions/161966/what-can-we-do-to-reme...