Skip to content
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

Publisher#flatMapMergeSingle catch an propagate unexpected errors downstream #1614

Merged
merged 4 commits into from
Jun 11, 2021

Conversation

Scottmitch
Copy link
Member

Motivation:
Publisher#flatMapMergeSingle relies upon the upstream source to catch
unexpected exceptions, cleanup necessary state, and propagate an error
back downstream. However in the event the upstream source is a Single it
will not be able to propagate an error downstream because it has already
sent a terminal signal (multiple terminal signals not allowed by the
RS spec). This means the upstream can at best log/swallow the error and
downstream may not be notified of the failure.

Modifications:

  • Publisher#flatMapMergeSingle exception handling is modified to instead
    of propagating the exception upstream, exceptions are caught, upstream
    is cancelled, and the exception is propagated downstream.

Result:
Publisher#flatMapMergeSingle usages where downstream operators may throw
will cancel upstream and propagate and error downstream.

…nstream

Motivation:
Publisher#flatMapMergeSingle relies upon the upstream source to catch
unexpected exceptions, cleanup necessary state, and propagate an error
back downstream. However in the event the upstream source is a Single it
will not be able to propagate an error downstream because it has already
sent a terminal signal (multiple terminal signals not allowed by the
RS spec). This means the upstream can at best log/swallow the error and
downstream may not be notified of the failure.

Modifications:
- Publisher#flatMapMergeSingle exception handling is modified to instead
  of propagating the exception upstream, exceptions are caught, upstream
  is cancelled, and the exception is propagated downstream.

Result:
Publisher#flatMapMergeSingle usages where downstream operators may throw
will cancel upstream and propagate and error downstream.
@Scottmitch
Copy link
Member Author

Ideally Publisher#flatMapMerge and Publisher#flatMapMergeSingle remain as consistent as possible. However I think there is a case to be made here for a slight variation due propagating exceptions upstream to Single doesn't allow for error propagation. We have cases where flatMapMerge error propagation upstream allows for more contextual cleanup (e.g. in DnsClient rather than just cancel).

return; // Poison emittingUpdater. We prematurely terminated, other signals should be ignored.
}
// Release lock after we handle errors, because error handling needs to poison the lock.
if (!releaseLock(emittingUpdater, this)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is a risk that smth inside onErrorHoldingLock may throw and then lock won't be released

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that is intentional. when onErrorHoldingLock is called the lock is "poisoned" (aka not unlocked) to prevent future signal delivery.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, thanks for clarifying!

Copy link
Member

@idelpivnitskiy idelpivnitskiy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

@Scottmitch
Copy link
Member Author

build failure attributed to #1579

@Scottmitch
Copy link
Member Author

another build failure attributed to #1579

@Scottmitch Scottmitch merged commit 4e9c7e0 into apple:main Jun 11, 2021
@Scottmitch Scottmitch deleted the flat_map_error branch June 11, 2021 14:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants