diff --git a/core/modules/system/lib/Drupal/system/Tests/System/ShutdownFunctionsTest.php b/core/modules/system/lib/Drupal/system/Tests/System/ShutdownFunctionsTest.php
index 96b2f8d..9fc3a91 100644
--- a/core/modules/system/lib/Drupal/system/Tests/System/ShutdownFunctionsTest.php
+++ b/core/modules/system/lib/Drupal/system/Tests/System/ShutdownFunctionsTest.php
@@ -33,6 +33,19 @@ public static function getInfo() {
    * Test shutdown functions.
    */
   function testShutdownFunctions() {
+    // When running on FastCGI, fastcgi_finish_request() sends the output buffer
+    // to the client and terminates the connection before shutdown functions are
+    // invoked. Shutdown functions are still executed, but they can no longer
+    // add output to the stream. That circumstance breaks this test.
+    // Normally a strpos(PHP_SAPI, 'cgi') !== FALSE check would be sufficient,
+    // but since the test runner may be executed from the command line, the
+    // PHP_SAPI is 'cli', whereas the tested shutdown functions are invoked in
+    // the child site (in which PHP_SAPI will contain 'cgi').
+    // In a CLI environment, FastCGI cannot be identified. Therefore, this
+    // condition is deferred to the actual controller in the child site, which
+    // will force-execute all registered shutdown functions manually.
+    // @see system_test_page_shutdown_functions()
+
     $arg1 = $this->randomName();
     $arg2 = $this->randomName();
     $this->drupalGet('system-test/shutdown-functions/' . $arg1 . '/' . $arg2);
diff --git a/core/modules/system/tests/modules/system_test/system_test.module b/core/modules/system/tests/modules/system_test/system_test.module
index 040d9f3..f3125ff 100644
--- a/core/modules/system/tests/modules/system_test/system_test.module
+++ b/core/modules/system/tests/modules/system_test/system_test.module
@@ -134,6 +134,14 @@ function system_test_page_build(&$page) {
  */
 function system_test_page_shutdown_functions($arg1, $arg2) {
   drupal_register_shutdown_function('_system_test_first_shutdown_function', $arg1, $arg2);
+
+  // Force-execute registered shutdown functions on FastCGI (php-fpm), because
+  // the fastcgi_finish_request() will terminate the response stream before
+  // shutdown functions are processed.
+  // @see \Drupal\system\Tests\System\ShutdownFunctionsTest
+  if (strpos(PHP_SAPI, 'cgi') !== FALSE) {
+    _drupal_shutdown_function();
+  }
 }
 
 /**
