Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,10 @@ private IDisposable DrainShortRunning(IScheduler recursiveScheduler)

if (Interlocked.Decrement(ref _wip) != 0)
{
return recursiveScheduler.Schedule(this, DRAIN_SHORT_RUNNING);
// Don't return the disposable of Schedule() because that may chain together
// a long string of ScheduledItems causing StackOverflowException upon Dispose()
var d = recursiveScheduler.Schedule(this, DRAIN_SHORT_RUNNING);
Disposable.TrySetMultiple(ref _task, d);
}
return Disposable.Empty;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shouldn't it at least return this here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That would recurse upon calling Dispose() for no practical purpose. The public void Dispose() takes care of the cleanup when the downstream disposes, including the outstanding tasks.

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,19 @@ public void ObserveOn_SynchronizationContext_Simple()
);
}

[Fact]
public void ObserveOn_EventLoop_Long()
{
var _scheduler1 = new EventLoopScheduler();
var N = 1_000_000;

var cde = new CountdownEvent(1);

Observable.Range(1, N).ObserveOn(_scheduler1)
.Subscribe(v => { }, () => cde.Signal());

Assert.True(cde.Wait(5000), "Timeout!");
}
}

internal class MyCtx : SynchronizationContext
Expand Down