Skip to content

Multiple await on source returning the same exception reports multiple stack traces #2187

@adamjones2

Description

@adamjones2

I'm finding something very strange: when I repeatedly subscribe to a failed sequence the exception that's returned gets the call stack of each subscription appended to it for future callers. This is using Rx v6.0.1. Repro:

var src = Observable.Throw<int>(new Exception("test")).Replay(1);
src.Connect();

async Task GetValue()
{
    try { await src.FirstAsync(); }
    catch (Exception ex) { Console.WriteLine(ex); }
}

for (int i = 1; i <= 3; i++)
{
    Console.WriteLine($"\r\n===> {i}");
    await GetValue();
}

Output:

===> 1
System.Exception: test
   at System.Reactive.PlatformServices.ExceptionServicesImpl.Rethrow(Exception exception)
   at System.Reactive.ExceptionHelpers.Throw(Exception exception)
   at System.Reactive.Subjects.AsyncSubject`1.GetResult()
   at Program.<>c__DisplayClass0_0.<<<Main>$>g__GetValue|0>d.MoveNext() in C:\Source\Test\Program.cs:line 8

===> 2
System.Exception: test
   at System.Reactive.PlatformServices.ExceptionServicesImpl.Rethrow(Exception exception)
   at System.Reactive.ExceptionHelpers.Throw(Exception exception)
   at System.Reactive.Subjects.AsyncSubject`1.GetResult()
   at Program.<>c__DisplayClass0_0.<<<Main>$>g__GetValue|0>d.MoveNext() in C:\Source\Test\Program.cs:line 8
--- End of stack trace from previous location ---
   at System.Reactive.PlatformServices.ExceptionServicesImpl.Rethrow(Exception exception)
   at System.Reactive.ExceptionHelpers.Throw(Exception exception)
   at System.Reactive.Subjects.AsyncSubject`1.GetResult()
   at Program.<>c__DisplayClass0_0.<<<Main>$>g__GetValue|0>d.MoveNext() in C:\Source\Test\Program.cs:line 8

===> 3
System.Exception: test
   at System.Reactive.PlatformServices.ExceptionServicesImpl.Rethrow(Exception exception)
   at System.Reactive.ExceptionHelpers.Throw(Exception exception)
   at System.Reactive.Subjects.AsyncSubject`1.GetResult()
   at Program.<>c__DisplayClass0_0.<<<Main>$>g__GetValue|0>d.MoveNext() in C:\Source\Test\Program.cs:line 8
--- End of stack trace from previous location ---
   at System.Reactive.PlatformServices.ExceptionServicesImpl.Rethrow(Exception exception)
   at System.Reactive.ExceptionHelpers.Throw(Exception exception)
   at System.Reactive.Subjects.AsyncSubject`1.GetResult()
   at Program.<>c__DisplayClass0_0.<<<Main>$>g__GetValue|0>d.MoveNext() in C:\Source\Test\Program.cs:line 8
--- End of stack trace from previous location ---
   at System.Reactive.PlatformServices.ExceptionServicesImpl.Rethrow(Exception exception)
   at System.Reactive.ExceptionHelpers.Throw(Exception exception)
   at System.Reactive.Subjects.AsyncSubject`1.GetResult()
   at Program.<>c__DisplayClass0_0.<<<Main>$>g__GetValue|0>d.MoveNext() in C:\Source\Test\Program.cs:line 8

Expected:

===> 1
System.Exception: test
   at System.Reactive.PlatformServices.ExceptionServicesImpl.Rethrow(Exception exception)
   at System.Reactive.ExceptionHelpers.Throw(Exception exception)
   at System.Reactive.Subjects.AsyncSubject`1.GetResult()
   at Program.<>c__DisplayClass0_0.<<<Main>$>g__GetValue|0>d.MoveNext() in C:\Source\Test\Program.cs:line 8

===> 2
System.Exception: test
   at System.Reactive.PlatformServices.ExceptionServicesImpl.Rethrow(Exception exception)
   at System.Reactive.ExceptionHelpers.Throw(Exception exception)
   at System.Reactive.Subjects.AsyncSubject`1.GetResult()
   at Program.<>c__DisplayClass0_0.<<<Main>$>g__GetValue|0>d.MoveNext() in C:\Source\Test\Program.cs:line 8

===> 3
System.Exception: test
   at System.Reactive.PlatformServices.ExceptionServicesImpl.Rethrow(Exception exception)
   at System.Reactive.ExceptionHelpers.Throw(Exception exception)
   at System.Reactive.Subjects.AsyncSubject`1.GetResult()
   at Program.<>c__DisplayClass0_0.<<<Main>$>g__GetValue|0>d.MoveNext() in C:\Source\Test\Program.cs:line 8

We have code that frequently checks the first value of a long-lived Replay'd stream and when it errored out we were surprised an hour later in our logs to find some very long stack traces indeed!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions