Skip to content

Commit

Permalink
Merge pull request #1785 from damiankloip/psysh-child-db-close
Browse files Browse the repository at this point in the history
Run terminate before the shell runs to avoid database errors when the core-cli command finishes
  • Loading branch information
damiankloip committed Nov 19, 2015
2 parents c133b55 + 79de2c5 commit 26823ec
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions commands/core/cli.drush.inc
Expand Up @@ -63,6 +63,25 @@ function drush_cli_core_cli() {
// run after the user presses ^D. Mark this command as completed to avoid a
// spurious error message.
drush_set_context('DRUSH_EXECUTION_COMPLETED', TRUE);

// Run the terminate event before the shell is run. Otherwise, if the shell
// is forking processes (the default), any child processes will close the
// database connection when they are killed. So when we return back to the
// parent process after, there is no connection. This will be called after the
// command in preflight still, but the subscriber instances are already
// created from before. Call terminate() regardless, this is a no-op for all
// DrupalBoot classes except DrupalBoot8.
if ($bootstrap = drush_get_bootstrap_object()) {
$bootstrap->terminate();
}

// To fix the above problem in Drupal 7, the connection can be closed manually.
// This will make sure a new connection is created again in child loops. So
// any shutdown functions will still run ok after the shell has exited.
if (drush_drupal_major_version() == 7) {
Database::closeConnection();
}

$shell->run();
}

Expand Down

0 comments on commit 26823ec

Please sign in to comment.