[MAGNOLIA-2623] RenderingFilter logs a "Unable to redirect to 404 page, response is already committed" any time there is an error while streaming back a resource Created: 15/Feb/09  Updated: 23/Jan/13  Resolved: 15/Feb/09

Status: Closed
Project: Magnolia
Component/s: core
Affects Version/s: 4.0
Fix Version/s: 4.0

Type: Bug Priority: Trivial
Reporter: Fabrizio Giustina Assignee: Fabrizio Giustina
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Template:
Patch included:
Yes
Acceptance criteria:
Empty
Task DoD:
[ ]* Doc/release notes changes? Comment present?
[ ]* Downstream builds green?
[ ]* Solution information and context easily available?
[ ]* Tests
[ ]* FixVersion filled and not yet released
[ ]  Architecture Decision Record (ADR)
Bug DoR:
[ ]* Steps to reproduce, expected, and actual results filled
[ ]* Affected version filled

 Description   

This is really trivial, the problem is just a spurious log.info().
In RenderingFilter there is a catch for IOExceptions while streaming back resources. The exception is swallowed since it's typically a ClientAbortException (can happen). But after the catch there is no "return" and the flow continues just like the resource was not found.
The filter tries to forward to the 404 page, than it catches another exception due to the closed stream and log another info.

            catch (IOException e) {
                // don't log at error level since tomcat tipically throws a
                // org.apache.catalina.connector.ClientAbortException if the user stops loading the page
                log.debug("Exception while dispatching resource " + e.getClass().getName() + ": " + e.getMessage(), e); //$NON-NLS-1$ //$NON-NLS-2$
            }
            catch (Exception e) {
                log.error("Exception while dispatching resource  " + e.getClass().getName() + ": " + e.getMessage(), e); //$NON-NLS-1$ //$NON-NLS-2$
            }
            finally {
                IOUtils.closeQuietly(is);
            }

         // missing return here

        }

        log.debug("Resource not found, redirecting request for [{}] to 404 URI", request.getRequestURI()); //$NON-NLS-1$

        if (!response.isCommitted()) {
            response.sendError(HttpServletResponse.SC_NOT_FOUND);
        }
        else {
            log.info("Unable to redirect to 404 page, response is already committed"); //$NON-NLS-1$
        }



 Comments   
Comment by Fabrizio Giustina [ 15/Feb/09 ]

fixed by adding a return statement in the catch blocks

Generated at Mon Feb 12 03:38:30 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.