Open
Description
#46774 has shown, that there are some Fire&Forget tasks that can throw an unnoticed exception when we introduce a bug in BCL (see #46807 (comment) for details)
This is of course very rare as we try to avoid Fire&Forget tasks, but anyway it is possible (at least for the MemoryCache
tests).
I wonder whether there is anything that we have done in the past to detect such issues?
If not, should we do something about it? Like for example extending xunit test runner to report a failure on TaskScheduler.UnobservedTaskException
event? (I don't know if it's currently possible, it's just a hypothetical example to start a discussion)
[Fact]
public void ThrowingFireAndForgetThatPasses()
{
Schedule(new object());
static void Schedule(object obj)
{
Task.Factory.StartNew(state =>
{
string text = (string)state; // fails
Console.WriteLine(text);
}, obj, CancellationToken.None, TaskCreationOptions.DenyChildAttach, TaskScheduler.Default);
}
}