jetty.project icon indicating copy to clipboard operation
jetty.project copied to clipboard

Customizable error page buffer size

Open dkaukov opened this issue 1 year ago • 11 comments

Ability to increase buffer size past 8k in the custom ErrorHandler

dkaukov avatar Apr 15 '24 23:04 dkaukov

The HttpConfiguration is how you control the output buffer size.

What is the use case for this?

joakime avatar Apr 16 '24 14:04 joakime

True, but

    bufferSize = Math.min(8192, bufferSize); // TODO ?

limiting it to the 8k. We need a way to increase the limit.

dkaukov avatar Apr 16 '24 22:04 dkaukov

limiting it to the 8k. We need a way to increase the limit.

I understand that you want to increase the buffer size limit, but why? What's the use case for a larger buffer size? (I ask, as there's probably several different ways to accomplish your use case without increasing this specific buffer size)

joakime avatar Apr 17 '24 12:04 joakime

Hi, In the

@Override
protected void writeErrorHtml(Request request, Writer writer, Charset charset, int code, String message, Throwable cause, boolean showStacks) throws IOException {
  ....
}

we are generating custom error page using Writer. Something like:

  themeLeafTemplate.execute(writer, errorInfo);

If error page is bigger than buffer size it is just trimmed.

dkaukov avatar Apr 18 '24 07:04 dkaukov

Need to dig into why we are doing this via a static sized buffer.

I would like to see if this need can be accomplished via a Writer created with the Content.Sink features instead. (will try this in a different branch soon)

joakime avatar Apr 18 '24 10:04 joakime

Hi @joakime , maybe we can merge this one in a meantime?

dkaukov avatar May 20 '24 22:05 dkaukov

Need to dig into why we are doing this via a static sized buffer.

I believe the reasoning is that we don't want to get into complex responses when generating error pages, as if we are in an error state, we want simplicity.... otherwise we can get errors within errors within errors.....

I'll review this PR for merging now...

gregw avatar May 21 '24 00:05 gregw

This is OK.... but I think I'd prefer a simple setBufferSize method, with a -1 meaning that a heuristic will be used (e.g. min(8K, httpConfig.bufferSize)). Default value will be -1 and public int getBufferSize() would return -1 (or the set value). Then have a protect int computeBufferSize(Request request) that would check for -1 and do the min(8k, config.bufferSize) thang.

Note the reason I prefer a setter, is that it can be used from XML.

gregw avatar May 21 '24 00:05 gregw

@gregw Could you please take a look now.

dkaukov avatar May 23 '24 03:05 dkaukov

CI failure is a flake. rerunning

gregw avatar May 23 '24 07:05 gregw

Re-running CI test again.

janbartel avatar Jul 31 '24 01:07 janbartel

Known CI flake

gregw avatar Aug 29 '24 22:08 gregw

@dkaukov thanks

gregw avatar Aug 29 '24 22:08 gregw