-
-
Notifications
You must be signed in to change notification settings - Fork 8.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[JENKINS-21695] - The CompressionFilter.uncaughtExceptionHandler must not attempt to write to a committed response #2834
[JENKINS-21695] - The CompressionFilter.uncaughtExceptionHandler must not attempt to write to a committed response #2834
Conversation
…ite to a committed response.
This pull request originates from a CloudBees employee. At CloudBees, we require that all pull requests be reviewed by other CloudBees employees before we seek to have the change accepted. If you want to learn more about our process please see this explanation. |
Build failure is from nodejs.org. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the changelog is required here, maybe even backporting since it is potentially reproducible in Jenkins without debugging.
If we consider this fix as a backporting-candidate, there should be a JIRA issue.
@Initializer | ||
public static void init(final Jenkins j) throws IOException { | ||
CompressionFilter.setUncaughtExceptionHandler(j.servletContext, new UncaughtExceptionHandler() { | ||
@Override | ||
public void reportException(Throwable e, ServletContext context, HttpServletRequest req, HttpServletResponse rsp) throws ServletException, IOException { | ||
if (rsp.isCommitted()) { | ||
LOGGER.log(Level.WARNING, null, e); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe makes sense to explicitly say that the response is already committed in the log message
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really informative. The default expectation is for errors on the server to be logged as such on the server. Arguably it is a bug that errors are ever sent to the client using something like oops.jelly
.
@@ -20,11 +20,18 @@ | |||
* @author Kohsuke Kawaguchi | |||
*/ | |||
public class InstallUncaughtExceptionHandler { | |||
|
|||
private static final Logger LOGGER = Logger.getLogger(InstallUncaughtExceptionHandler.class.getName()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The class name does not change, so it's perfectly fine
🐛 till we discuss the approach. And I think we should not integrate any bugfixes without changelogs and JIRA issues. And "Jetty explodes" use-case seems to be a valid bug independently of reproduction steps |
I am not proposing a backport or a changelog entry, because I am not aware of a specific user-visible symptom. It is just something I saw while testing some changes (which I later modified anyway) and which seemed incorrect. |
Dug up an old issue JENKINS-21695 with a roughly similar stack trace (Jetty has since been updated). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not an expert on handling uncaught exceptions. As far as I can tell, this code is correct.
The change adds a private constructor to the class so the constructor can't be called from a child class. I assume that is more about correctness and protection against future mistakes than it is about this specific fix.
This change needs logging within the class so it moves the logger declaration from its previous location in an inner class into the class itself.
Yes, it is a utility class so the private constructor prevents accidental subclassing/instantiation.
Correct. |
FTR what errors look like without this patch:
As you can see, there is no information about the original exception. |
@oleg-nenashev ping, I would like to get this merged already. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks fine to me now. 🐝
Though I think the SEVERE error for being unable to add the logging is perhaps a bit harsh since it's logging and not a full on "Jenkins is completely hosed" error. But that's a matter of preference I guess.
I would tend to agree, but I did not write that code and am not intending to modify it. I was just moving the |
Predates issue linking and further discussion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🐝 and @reviewbybees done. Will merge towards the next weekly
JENKINS-21695
Description
While debugging problems servicing a POST to
/cli
in #2795, I saw a bizarre stack trace from Jetty: it was complaining that someone was trying to write to a committed servlet response. But the error talked aboutrequest.getSession()
in JEXL (that would belayout.jelly
) being a problem, even though this is not a GUI page being served! Turns out thatInstallUncaughtExceptionHandler
was trying to redirect tooops.jelly
, which is certainly not going to work for a non-HTML client. (In my case the exception was in fact thrown near the end of the response handling cycle.)Switched to just logging the error in case we are already serving content, which prevented Jetty from exploding.
This might also fix a problem I have seen whereby a page gets partially rendered and then an
oops
appears halfway down, but in totally garbled HTML. (Not to be confused with cases where a separate HTTP response is rendered in aniframe
or injected into theinnerHTML
of something.)Changelog entries
Desired reviewers
@reviewbybees, @jenkinsci/code-reviewers