-
Notifications
You must be signed in to change notification settings - Fork 566
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
#5685 - Add ServerResponse.reset() to support ErrorHandlers #5694
#5685 - Add ServerResponse.reset() to support ErrorHandlers #5694
Conversation
Thank you for your pull request and welcome to our community! To contribute, please sign the Oracle Contributor Agreement (OCA).
To sign the OCA, please create an Oracle account and sign the OCA in Oracle's Contributor Agreement Application. When signing the OCA, please provide your GitHub username. After signing the OCA and getting an OCA approval from Oracle, this PR will be automatically updated. If you are an Oracle employee, please make sure that you are a member of the main Oracle GitHub organization, and your membership in this organization is public. |
BTW: I have actually signed the OCA earlier this evening so not sure why that OCA Required is still showing up. Maybe it takes a while to sync that information. |
Seems to me the following could happen:
The state is now very bad - we have already sent status and headers and a part of entity, yet now error handler thinks it can write response status, headers and entity. To work around this, we would need to keep track of the information if anything was written at all, and only allow Also this would need a test to validate such edge cases... |
A call to
Just to say it does not actually send for the first call to os.write() [which is instead stored as firstBuffer] so if there has been only 1 call to os.write() it doesn't actually send anything yet. The second and subsequent calls to os.write() do though. That is, the ServerResponse isSent() is false until ... a second call to os.write() or os.flush() or os.close() - until then it is isSent false and able to be reset (which means firstBuffer can be set back to null). |
Yes. As I see it that exists now as
Yes. I get the test below to pass when @Override
public boolean isSent() {
return isSent || outputStream != null && outputStream.totalBytesWritten() > 0;
} The test as I have it is - https://github.com/rbygrave/nima-error-handler/blob/main/src/test/java/org/example/MainTest.java#L59-L67 Edit: Add the outputStream != null |
Ah, I found the integration tests in |
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.
Needs a few adjustments here
...rc/test/java/io/helidon/nima/tests/integration/server/ErrorHandlingWithOutputStreamTest.java
Outdated
Show resolved
Hide resolved
...rc/test/java/io/helidon/nima/tests/integration/server/ErrorHandlingWithOutputStreamTest.java
Outdated
Show resolved
Hide resolved
nima/http2/webserver/src/main/java/io/helidon/nima/http2/webserver/Http2ServerResponse.java
Outdated
Show resolved
Hide resolved
...rc/test/java/io/helidon/nima/tests/integration/server/ErrorHandlingWithOutputStreamTest.java
Show resolved
Hide resolved
I think there should be a difference between I can see two options how to solve this:
I would prefer option 1 in this case, as it keeps the check internal to each specific implementation of response (HTTP/1 and HTTP/2) and does not expose information that is more of an implementation detail. Please let me know if you want to continue on this feature yourself, or if you would prefer some other arrangement. If you want, you can contact me over our public slack channel to take care of the details Thank you very much for your efforts on this! |
That makes good sense to me.
I can make that change for option 1. I'm not sure about the http2 tests and implementation and maybe someone needs to take that over. I have no issue if someone wants to take over this PR or completely redo it. All good either way. I'll look to make the change to option 1 but all fine it someone wants to start again fresh on this. |
I have pushed the change for "Option 1" to revert
I've probably hit my knowledge limit here. In ErrorHandlers the code in this PR throws I'm happy if someone wants to start afresh with a new PR or take this PR forward or suggest changes. Cheers, Rob. |
Before I take over your code, could you kindly squash your commits into a single one (as I want to keep your commit in the history of Helidon)? Thanks! |
4863aef
to
f69393f
Compare
Done.
That would be awesome. Cheers, Rob. |
43adc2a
to
3a113aa
Compare
@rbygrave I have rebased on latest |
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 good. As a side comment, I prefer AssertJ :)
Introduce commit to RoutingResponse Correctly terminate HTTP/2 streams when an error is thrown Update tests with try with resources
3a113aa
to
2d25ff2
Compare
Thank you for your contribution! |
Fixes the test at: https://github.com/rbygrave/nima-error-handler/blob/main/src/test/java/org/example/MainTest.java