-
Notifications
You must be signed in to change notification settings - Fork 87
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
Clarify under what circumstances onError is called #434
Open
stuartwdouglas
wants to merge
2
commits into
jakartaee:master
Choose a base branch
from
stuartwdouglas:433
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+69
−5
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I think this text has some problems.
Say I am streaming some data from a remote source and call
write()
, I am expecting more data in future, but I don't have any more data ready yet.If the async write files in this case then we have no way of reporting this to the user until they attempt to call
isReady()
. Because they have not callisReady
and it returned false we are not allowed to invoke the listener.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.
I also really don't like the idea of doubling up error handling. The original proposal meant that you only had to implement
onError
, with this change you now need to handle errors thrown from the stream. Should we add a section that ifonWritePossible
throwsIOException
then theonError
method is called? It seems like obvious behavior but I am not sure if it is called out anywhere. This would mean that ifwrite
throws you can just let the exception propagate and the listener will handle it.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.
Stuart, by
onError
in your comment, I'm assuming that you meanAsyncListener.onError
and notWriteListener.onError
.So I do like the "if
OWP
throw then theAL.onError
method is called" as a good way to give control to the application about how write errors are reported toAL.onError
.I agree it there is something strange about not reporting a known error to
WL.onError
untilisReady()
is called. But if we do not, then we do not have an easy way to tell if a previous write has completed or not. Currently the only way we have on knowing a previous write has completed is ifisReady()
has returned true. Perhaps you could also say that ifonWritePossible
has been called, that also indicates completion... but reallyisReady()
should be called from within OWP and checked for a true response to protect from spurious wakeups. IfWL.onError
can be called at any time, then it may be called simultaneously to another thread callingisReady()
and then the app will never know if the call toWL.onError
was the result of the false return fromisReady
or if it just happened anyway and another call is on its way.I'm not sure there is a good solution given the current API. I think the best we can do is be rigorous with the scheduling so we at least avoid races like the one above.
Note that if the app you described really wants to know about an error before the next write is ready, there is nothing stopping it calling
isReady()
immediately after thewrite
and then it will know that the operation has either completed or that either ODA or WL.onError will be called as soon as the operation is complete.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.
Thinking about it some more I agree with your concerns about thread safety. The only way I can think to make this work is to allow this use case via the flush method. We could add something like 'If flush() is called in async mode then isReady must not return true until the data is written out to the client'.
Then if you really care about error notification and are not going to immediately write again you can call
flush + isReady
to see the results.