Skip to content

Conversation

@fl4via
Copy link
Member

@fl4via fl4via commented Oct 27, 2025

j-baker and others added 3 commits October 27, 2025 06:52
…y contract, fix bug

BufferedWriteableOutputStream is currently implemented by:

1. UndertowOutputStream
2. ServletOutputStreamImpl

These have two different behaviours. In UndertowOutputStream, I
_believe_ that if the input FileChannel's position is 0, it transfers
the whole channel, and if it's non-zero, it crashes.

In ServletOutputStreamImpl, I think the behaviour is something more
like:
1. If there is no listener set, transfer the bytes between the current
   position and end of file.
2. If there is a listener set, transfer the bytes between the current
   position and end of file, setting the input channel's position as
well.

This PR makes the behaviour be more consistent and adds a new, clearer
API, deprecating the old one.

1. Clarify the contract of BufferedWriteableOutputStream.transferTo as
   being the ServletOutputStreamImpl's behaviour, since it has a
   superset of the UndertowOutputStream's functionality.
2. Never set the position of the input channel in
   ServletOutputStreamImpl, since it leads to inconsistent behaviour
   depending on whether the listener is set and seems incongruent with
   the contract of the underlying FileChannel apis.
3. Add an explicit `transferFrom(FileChannel source, long startPosition,
   long count)` method to the interface and implement in both
   implementations.

In theory there is a breaking behaviour change for the user who is
relying on their FileChannel's position being set to EOF as a
side-effect of the change. Internally to Undertow there is no problem
here.
@fl4via fl4via added bug fix Contains bug fix(es) waiting CI check Ready to be merged but waiting for CI check labels Oct 27, 2025
@fl4via fl4via added next release This PR will be merged before next release or has already been merged (for payload double check) and removed waiting CI check Ready to be merged but waiting for CI check labels Oct 28, 2025
@fl4via fl4via merged commit 5588ac5 into undertow-io:main Oct 28, 2025
41 of 42 checks passed
@fl4via fl4via deleted the UNDERTOW-2157 branch October 28, 2025 21:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug fix Contains bug fix(es) next release This PR will be merged before next release or has already been merged (for payload double check)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants