Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Comment | File | Size | Author |
---|---|---|---|
#3 | kint+big_pipe — NOT first output.png | 92.24 KB | Wim Leers |
#3 | kint+big_pipe — first output (BigPipe disabled).png | 123.49 KB | Wim Leers |
#3 | kint+big_pipe — first output (verbose error logging).png | 80.91 KB | Wim Leers |
#3 | kint+big_pipe — first output (default error logging).png | 40.9 KB | Wim Leers |
Comments
Comment #2
Wim LeersComment #3
Wim LeersI gave this another look.
I installed the
devel
module and itskint
submodule. Then I did this:While BigPipe is enabled, the end result looks like this:
If you're using
settings.local.php
, which you should if you're developing, then you'll have$config['system.logging']['error_level'] = 'verbose';
, and that will make the exact same thing look like this:However, disable BigPipe, and then it'll look like this:
It'd be easy to blame BigPipe. The real root cause however is not BigPipe, but either:
index.php
is as barebone as it can be, and it's equivalent with Symfony's: https://github.com/symfony/symfony-standard/blob/master/web/app.php — the problem here is that$response->send()
is called after the session has already been closed in$kernel->handle($request)
, and BigPipe needs the session while sending the response\Drupal\Core\StackMiddleware\Session
session middleware instead, because this is what is saving (and closing) the session\Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage::save()
, which is what is effectively closing the session.\Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage::start()
, which checks if headers are already sent and then causes the fatal error you see in the screenshots, even though no headers need to be sent, because we're merely reopening the same sessionIn other words, this shows that neither Kint, nor Symfony's HTTP kernel, nor Symfony's session handling, nor StackPHP are designed with streamed responses in mind.
A nearly identical issue exists with using
phpseclib
+ any Symfony app: https://github.com/symfony/symfony/issues/18819 — but since in that case the output is not intentional, but an error, it's easy to work around. In the case of kint, it's very much intentional.Note that in searching for "Symfony session header_sent", I actually stumbled upon #2597520: Don't save the session before $response->send(), which is where I was trying to change session handling, but that attempt failed. None of the session system experts there suggested a better approach.
Finally, note that the
kint()
output worked! It's just that it broke the rest of the page. For the above reasons.The above is what happens if you call
kint()
before any output has started. But when usingkint()
while rendering the page, (i.e. after initial HTML has already been sent) it works fine, with or without BigPipe:To get this, I reverted the change above, and instead made this change:
In other words:
kint()
after initial content has been sent works finekint()
before any content has been sent breaks BigPipe's streamed responses, but the Kint output itself works fine. Solving this requires untangling many layers of interdependencies in the session handling system in Symfony, which was never designed to support interrupted streamed responses.kint()
means potentially interrupting a stream. Which means the above behavior is pretty much by design! It's annoying. But blamekint()
, Symfony or even PHP (for not supporting streamed responses better), but there is unfortunately very little BigPipe can do.(In the course of writing this, I tried to at least a dozen different hacks to get this to work anyway. And I failed.)
Comment #4
mondrakeThanks for all reasearch and efforts, @Wim Leers
Comment #5
Wim LeersYou're welcome!
Have you seen the problem you reported at #2678662-10: Ensure BigPipe does not break when HTML document contains CDATA sections or inline scripts matching certain patterns many times since you reported it 4 months ago?
Comment #6
mondrake#5 actually in my dev I just disabled BigPipe, sorry, and never looked at that again. Once I find some time I'll check what the situation is now.
Comment #7
Wim Leers