From c98e6b7c7af2a24a7bd54c7b5a8983ef3a01e849 Mon Sep 17 00:00:00 2001 From: Damian Lee Date: Thu, 19 Nov 2015 09:10:34 +0000 Subject: [PATCH 1/3] Run terminate before the shell runs to avoid database errors when the core-cli command finishes --- commands/core/cli.drush.inc | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/commands/core/cli.drush.inc b/commands/core/cli.drush.inc index 572deb212d..a196c41f54 100644 --- a/commands/core/cli.drush.inc +++ b/commands/core/cli.drush.inc @@ -63,6 +63,18 @@ 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 closed. So when we return back to the + // parent process after, there is no connection. Call terminate() regardless, + // this is a no-op for all DrupalBoot classes except DrupalBoot8. This will be + // called after the command in preflight still, but the subscriber instances + // are already created from before. + if ($bootstrap = drush_get_bootstrap_object()) { + $bootstrap->terminate(); + } + $shell->run(); } From f409c3f7d425a772b9f558ad38619c14c04cd90a Mon Sep 17 00:00:00 2001 From: Damian Lee Date: Thu, 19 Nov 2015 09:57:50 +0000 Subject: [PATCH 2/3] Close database connection manually for Drupal 7 in core-cli --- commands/core/cli.drush.inc | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/commands/core/cli.drush.inc b/commands/core/cli.drush.inc index a196c41f54..61c4ea907c 100644 --- a/commands/core/cli.drush.inc +++ b/commands/core/cli.drush.inc @@ -66,16 +66,23 @@ function drush_cli_core_cli() { // 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 closed. So when we return back to the - // parent process after, there is no connection. Call terminate() regardless, - // this is a no-op for all DrupalBoot classes except DrupalBoot8. This will be - // called after the command in preflight still, but the subscriber instances - // are already created from before. + // 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(); } $shell->run(); + + // To fix the above problem in Drupal 7, the connection can be closed manually. + // This will make sure a new connection is created again if/when needed in + // registered shutdown functions. + if (drush_drupal_major_version() == 7) { + Database::closeConnection(); + } } /** From 79de2c5c36750e47c8f2ba4656aaa38be8290770 Mon Sep 17 00:00:00 2001 From: Damian Lee Date: Thu, 19 Nov 2015 10:05:04 +0000 Subject: [PATCH 3/3] Close D7 database connection before the shell is run --- commands/core/cli.drush.inc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/commands/core/cli.drush.inc b/commands/core/cli.drush.inc index 61c4ea907c..f967e83f91 100644 --- a/commands/core/cli.drush.inc +++ b/commands/core/cli.drush.inc @@ -75,14 +75,14 @@ function drush_cli_core_cli() { $bootstrap->terminate(); } - $shell->run(); - // To fix the above problem in Drupal 7, the connection can be closed manually. - // This will make sure a new connection is created again if/when needed in - // registered shutdown functions. + // 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(); } /**