-
Notifications
You must be signed in to change notification settings - Fork 1.1k
[UNDERTOW-2157] UndertowOutputStream: behaviour discrepancies, clarify contract, fix bug #1372
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
Conversation
servlet/src/main/java/io/undertow/servlet/spec/ServletOutputStreamImpl.java
Show resolved
Hide resolved
0401740 to
54805a6
Compare
|
thanks for your PR @j-baker ! It will be reviewed shortly and, if approved, added to 2.3.0.Beta2 or 2.3.0.Final. |
servlet/src/main/java/io/undertow/servlet/spec/ServletOutputStreamImpl.java
Show resolved
Hide resolved
54805a6 to
4ae76e0
Compare
|
Because we did not get a response in a timely manner, I will be updating this PR to incorporate the feedback so it can be merged. |
|
After somethought, I decided to remove the new method and keep the fixes. The reason for this is that, with this, it can be backported to old branches, and there is no need for a new method. The interface is used internally. If someone raises a need for a new method, then we will of course introduce it. |
2818d5b to
bd6dcce
Compare
592a9e1 to
c9e6c9c
Compare
…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.
Signed-off-by: Flavia Rainone <[email protected]>
…oved Signed-off-by: Flavia Rainone <[email protected]>
c9e6c9c to
3494607
Compare
Jira: https://issues.redhat.com/browse/UNDERTOW-2157
2.2.x PR: #1829
2.3.x PR: #1830
2.4.x PR: #1831
undertow-ee PR: undertow-io/undertow-ee#25
BufferedWriteableOutputStream is currently implemented by:
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:
This PR makes the behaviour be more consistent and adds a new, clearer API, deprecating the old one.
transferFrom(FileChannel source, long startPosition, long count)method to the interface and implement in both implementations. The current 'transferFrom' method has an extremely confusing signature - it's defined to transfer the rest of the file, which seems unnecessarily specific for such a generic interface.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 but obviously this is an API. In my head this is a bugfix but I'd be happy to maintain the present behaviour - I just don't know enough about the 'intended' contract.