Skip to content

Commit fbaa327

Browse files
authored
NoWaitForResponseRequest might cause error "Failed to start the sessi… (#1175)
* NoWaitForResponseRequest might cause error "Failed to start the session because headers have already been sent" #1174
1 parent 0b3689a commit fbaa327

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/Plugin/NoWaitForResponseRequest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,17 @@ public function preExecuteRequest(object $event): self
7777
$exception = null;
7878
$microtime1 = microtime(true);
7979
try {
80+
// Avoid error:
81+
// Failed to start the session because headers have already been sent by
82+
// "vendor/solarium/solarium/src/Core/Client/Adapter/Curl.php"
83+
// This fireAndForget() method invokes nowaitforresponserequest type solarium client plugin.
84+
// The nowaitforresponserequest type plugin
85+
// - sets "return_transfer" option to false
86+
// - sets timeout to TimeoutAwareInterface::FAST_TIMEOUT
87+
// before executing Solr command.
88+
// But it could cause error when solr is fast (or data is small) enought to send response before TimeoutAwareInterface::FAST_TIMEOUT.
89+
// So just buffer and discard.
90+
ob_start();
8091
$this->client->getAdapter()->execute($request, $event->getEndpoint());
8192
} catch (HttpException $e) {
8293
// We expect to run into a timeout.
@@ -94,6 +105,8 @@ public function preExecuteRequest(object $event): self
94105
}
95106
} catch (\Exception $exception) {
96107
// Throw this exception after resetting the adapter.
108+
} finally {
109+
ob_end_clean();
97110
}
98111

99112
if ($this->client->getAdapter() instanceof TimeoutAwareInterface) {

0 commit comments

Comments
 (0)