-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[Java] Observe error to avoid crash #22016
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
| closeSubject.doOnError((e) -> {}); | ||
| closeSubject.onError(new RuntimeException(t)); | ||
| onClose.invoke(null, t.getMessage()); | ||
| checkStartFailure(); |
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.
Is there a chance that checkStartFailure() ever gets called before the Completable is returned from start() meaning we'd need to do the same ting for startSubject?
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 that is technically possible, but very unlikely in practice.
I'm not sure how the global error handler works in that case, because the startSubject will be observed by someone, they just haven't registered the handler by the time onError is called.
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.
If it's possible, we should handle it.
I'm not sure how the global error handler works in that case, because the startSubject will be observed by someone, they just haven't registered the handler by the time onError is called.
We could test this by intentionally faulting the startSubject before returning. I expect it would also be crashing. How would the runtime even know the startSubject will be observed by someone in the future?
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.
Read the docs for CompletableSubject:
If there were no CompletableObservers subscribed to this CompletableSubject when the onError() was called, the global error handler is not invoked.
This also implies that the "fix" in this PR might not be correct, and the error was happening through some other means. The docs also mention that if onError is called multiple times then it will call the global handler. onError should only ever be called once here, but I'm beginning to think it was somehow triggered multiple times.
halter73
left a comment
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.
Thanks @jaragones!
|
Let's see if it helps :) |
| closeSubject.onComplete(); | ||
| try { | ||
| closeLock.lock(); | ||
| closeSubject.onComplete(); |
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.
Should we check that the closeSubject hasn't already been completed with an error here?
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.
Calling onComplete should noop if the subject is already completed either with an error or without an error.
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.
@halter73 any other feedback?
Fixes #20187
Thanks @jaragones for testing out a fix since I could never repro this.