-
Notifications
You must be signed in to change notification settings - Fork 182
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ignoring fatal exceptions in InvocationHandler (#2789)
- Loading branch information
Showing
4 changed files
with
72 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
||
using System; | ||
|
||
namespace Microsoft.Azure.Functions.Worker.Core | ||
{ | ||
internal static class ExceptionExtensions | ||
{ | ||
public static bool IsFatal(this Exception? exception) | ||
{ | ||
while (exception is not null) | ||
{ | ||
if (exception | ||
is (OutOfMemoryException and not InsufficientMemoryException) | ||
or AppDomainUnloadedException | ||
or BadImageFormatException | ||
or CannotUnloadAppDomainException | ||
or InvalidProgramException | ||
or AccessViolationException) | ||
{ | ||
return true; | ||
} | ||
|
||
exception = exception.InnerException; | ||
} | ||
|
||
return false; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using Microsoft.Azure.Functions.Worker.Core; | ||
using Xunit; | ||
|
||
namespace Microsoft.Azure.Functions.Worker.Tests | ||
{ | ||
public class ExceptionExtensionTests | ||
{ | ||
[Theory] | ||
[ClassData(typeof(ExceptionTestData))] | ||
public void IsFatal_ReturnsTrueForFatalExceptions(Exception exception, bool isFatal) | ||
{ | ||
var result = exception.IsFatal(); | ||
|
||
Assert.Equal(result, isFatal); | ||
} | ||
|
||
public class ExceptionTestData : TheoryData<Exception, bool> | ||
{ | ||
public ExceptionTestData() | ||
{ | ||
Add(new OutOfMemoryException(), true); | ||
Add(new AppDomainUnloadedException(), true); | ||
Add(new BadImageFormatException(), true); | ||
Add(new CannotUnloadAppDomainException(), true); | ||
Add(new InvalidProgramException(), true); | ||
Add(new AccessViolationException(), true); | ||
Add(new InsufficientMemoryException(), false); | ||
Add(new Exception("test", new OutOfMemoryException()), true); | ||
} | ||
} | ||
} | ||
} |