Repository navigation
Conversation
|
011431f to
516ee0d
Compare
| | `logbook.client.predicate.exclude` | Exclude certain paths and methods for outgoing requests (overrides `logbook.client.predicate.include`) | `[]` | | ||
| | `logbook.filter.enabled` | Enable the [`LogbookFilter`](#servlet) | `true` | | ||
| | `logbook.filter.form-request-mode` | Determines how [form requests](#form-requests) are handled | `body` | | ||
| | `logbook.filter.max-buffer-size` | Maximum amount of request/response body data to buffer in memory before discarding capture and streaming directly | `-1` (disabled) | |
There was a problem hiding this comment.
Do I get it right that this is the only change to README the rest is just formatting? Could you revert it? I can't even spot what's changed in the formatting. Or help me understand the reason.
There was a problem hiding this comment.
You're right, my bad on the noise there. When resolving the TOC check locally, the line endings in that block got touched. I've reverted the formatting churn completely so now only the single table row for logbook.filter.max-buffer-size is modified.
| if (property == null) { | ||
| return -1L; | ||
| } | ||
| return Long.parseLong(property); |
There was a problem hiding this comment.
A property.trim() here might be safer to prevent NumberFormatException in case of accidental leading/trailing whitespace in the system property.
There was a problem hiding this comment.
Good catch. Added .trim() before parsing, and added a test case in MaxBufferSizeTest to cover accidental whitespace.
| original.write(b, off, len); | ||
| branch.write(b, off, len); | ||
| if (!exceeded) { | ||
| if (maxBufferSize >= 0 && branch.size() + len > maxBufferSize) { |
There was a problem hiding this comment.
Since both branch.size() and len are int, this addition can overflow to negative if large chunks are written, bypassing the check. Should we cast to (long) branch.size() + len?
There was a problem hiding this comment.
definitely don't want an integer overflow bypassing the bound on large writes. Cast to (long) branch.size() + len > maxBufferSize.
| private final ByteArrayOutputStream branch; | ||
| private final long maxBufferSize; | ||
| @Getter | ||
| private boolean exceeded; |
There was a problem hiding this comment.
Should this be volatile? With async servlets or listener threads, writes might happen on a worker thread while completion or logging is handled on another.
There was a problem hiding this comment.
Makes total sense for async dispatches where worker writes and completion logging happen across threads. Made exceeded volatile.
|
|
||
| @Override | ||
| public void setReadListener(final ReadListener readListener) { | ||
| second.setReadListener(readListener); |
There was a problem hiding this comment.
I wonder if delegating to second here works in practice. Once synchronous reads have taken place (which happened during doBuffer), servlet containers usually throw IllegalStateException if setReadListener is invoked. Also, second wouldn't know about prefix bytes in first.
In ServletInputStreamAdapter we throw UnsupportedOperationException for setReadListener. Shouldn't we do the same here?
There was a problem hiding this comment.
Good point. Since we've already read synchronously during buffering and second doesn't know about prefix bytes anyway, non-blocking I/O isn't viable here. Switched it to throw UnsupportedOperationException, matching ServletInputStreamAdapter.
| public static class Filter { | ||
| private FormRequestMode formRequestMode = FormRequestMode.fromProperties(); | ||
| @Nullable | ||
| private DataSize maxBufferSize; |
There was a problem hiding this comment.
Could you also add logbook.filter.max-buffer-size to src/main/resources/META-INF/spring-configuration-metadata.json so IDEs pick it up for autocompletion?
There was a problem hiding this comment.
Added logbook.filter.max-buffer-size under properties in spring-configuration-metadata.json with DataSize type and description.
516ee0d to
413763a
Compare
|
Thanks @kasmarian for the review. Everything you raised is addressed in the earlier commit. I've pushed one small follow-up: the new README row is now aligned with its neighbours, and I removed a withFormRequestMode helper I had added to SecureLogbookFilter that isn't needed for this change. Could a maintainer also add the bugfix label so the COMPR/pr-labels check can pass? Thanks! |
Fixes #2441
Description
Prevents unbounded in-memory buffering of request and response bodies in
logbook-servletandlogbook-spring-boot-autoconfigure.ByteStreams.toByteArray(InputStream, long).SequenceServletInputStreamto replay buffered prefix data while streaming the remaining stream without holding excess bytes in heap.RemoteRequeststate machine withExceededstate: whenmaxBufferSizeis exceeded (viaContent-Lengthor chunked stream), the body is not buffered in memory, but downstream servlets still receive the full body without disruption.LocalResponse.Teecopying to discard buffered response bytes and reset the buffer ifmaxBufferSizeis exceeded while allowing the response to complete normally.maxBufferSize(-1Ldefault / unbounded for backward compatibility) inLogbookFilterandSecureLogbookFilterconfigurable via system propertieslogbook.servlet.max-buffer-size/logbook.filter.max-buffer-size.logbook.filter.max-buffer-size(DataSize).Validation
./mvnw verify -pl logbook-servlet,logbook-spring-boot-autoconfigure -am -Bon JDK 17.