In general, I think several calls to flushBuffer are totally valid, so
even if anyone else called this already in a inner call from forward,
this shouldn't be a problem. A rather suspect that the problem is more
with duplicate tries to set the headers or something along those lines.
So I think we should figure out what really is going on before making
any changes. It seems there is a scenario which is causing this, so it
would be good to convert that into a test.
Regards
Carsten
Am 03.06.2022 um 18:18 schrieb Bertrand Delacretaz:
Hi,
A colleague mentioned getting "SlingRequestProcessorImpl Writer has
already been closed" error messages when using
SlingRequestDispatcher.forward(...), and looking at the code [1] I
wonder if we should change the request flushing behavior.
Unfortunately, unless I missed something that code is not covered by
units tests, but I suppose nested calls to
SlingRequestDispatcher.forward(...) would cause the problem:
SlingRequestDispatcher blindly calls response.flushBuffer(), which
causes logged errors if the response Writer is already closed. So if a
Servlet that's been forwarded to calls
SlingRequestDispatcher.forward(...) I suppose we get this problem.
I could write a test to verify all that of course, but maybe someone
already has a clear idea on this.
Shall we modify that code to check the request status before calling
flushBuffer() ? I don't think there's a direct way to check if the
Writer is closed already, but maybe there's another call on the
request that would check that?
-Bertrand
[1]
https://github.com/apache/sling-org-apache-sling-engine/blob/631a54f45abf5fd6d7c56dac43fd499db543bcd7/src/main/java/org/apache/sling/engine/impl/request/SlingRequestDispatcher.java#L151
--
Carsten Ziegeler
Adobe
[email protected]