Skip to content

Observable.FromAsync produces unobserved task exceptions #1256

@lezzi

Description

@lezzi

Context

Recently I discovered an uncertain behavior in Observable.FromAsync method which causes unobserved exceptions to be thrown.

When there is an active subscription and task throws an exception everything works as expected - exception is catched by RX and forwarded to onError handler. The problem happens when subscription is cancelled right before the task failure. Under the hood (inside SlowTaskObservable) RX cancels task continuation, Exception property is not accessed by anyone and when GC is triggered - task unobserved exception is thrown.

My main concerns here are next:

  • This behavior is inconsistent from all other non-task cases. For example if exception is thrown from Select (or anywhere else) and if subscription is cancelled at this point - exception is not forwarded anywhere and is "silently" ignored.
  • RX is responsible for the task creation and by default always accessed Exception property. But when subscription is cancelled behavior changes completely.
  • It basically means there is no 100% reliable way to get rid of TaskScheduler.UnobservedTaskException. Any Observable.FromAsync usage can cause an unobserved exception. This part is critical in my view.

How I expect it to work: if RX creates a task and takes responsibility for error handling, it should do it fully from the beginning to the end. Behavior has to be consistent, no subscription means we are no longer interested in errors and we shouldn't get them anywhere.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions