From 8d5604960b66287d391d5ff2aa093b2118466bd1 Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Mon, 5 Oct 2020 15:06:01 -0400 Subject: [corlib] ThreadAbortException protection for ArraySortHelper The ArraySortHelper catches all exceptions in the comparer. If the sorting thread is aborted while it is running the comparer, the ArraySortHelper will catch the TAE and propagate an InvalidOperationException instead. As a workaround, catch and rethrow TAEs separately. Related to https://github.com/mono/mono/issues/15418 --- .../System/Collections/Generic/ArraySortHelper.cs | 29 ++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'src/System.Private.CoreLib/shared') diff --git a/src/System.Private.CoreLib/shared/System/Collections/Generic/ArraySortHelper.cs b/src/System.Private.CoreLib/shared/System/Collections/Generic/ArraySortHelper.cs index 03b986504..e1c232e84 100644 --- a/src/System.Private.CoreLib/shared/System/Collections/Generic/ArraySortHelper.cs +++ b/src/System.Private.CoreLib/shared/System/Collections/Generic/ArraySortHelper.cs @@ -14,6 +14,7 @@ ===========================================================*/ using System.Diagnostics; +using System.Threading; using System.Runtime.CompilerServices; namespace System.Collections.Generic @@ -68,6 +69,10 @@ namespace System.Collections.Generic { IntrospectiveSortUtilities.ThrowOrIgnoreBadComparer(comparer); } + catch (ThreadAbortException) + { + throw; + } catch (Exception e) { throw new InvalidOperationException(SR.InvalidOperation_IComparerFailed, e); @@ -85,6 +90,10 @@ namespace System.Collections.Generic return InternalBinarySearch(array, index, length, value, comparer); } + catch (ThreadAbortException) + { + throw; + } catch (Exception e) { throw new InvalidOperationException(SR.InvalidOperation_IComparerFailed, e); @@ -108,6 +117,10 @@ namespace System.Collections.Generic { IntrospectiveSortUtilities.ThrowOrIgnoreBadComparer(comparer); } + catch (ThreadAbortException) + { + throw; + } catch (Exception e) { throw new InvalidOperationException(SR.InvalidOperation_IComparerFailed, e); @@ -355,6 +368,10 @@ namespace System.Collections.Generic { IntrospectiveSortUtilities.ThrowOrIgnoreBadComparer(comparer); } + catch (ThreadAbortException) + { + throw; + } catch (Exception e) { throw new InvalidOperationException(SR.InvalidOperation_IComparerFailed, e); @@ -377,6 +394,10 @@ namespace System.Collections.Generic return ArraySortHelper.InternalBinarySearch(array, index, length, value, comparer); } } + catch (ThreadAbortException) + { + throw; + } catch (Exception e) { throw new InvalidOperationException(SR.InvalidOperation_IComparerFailed, e); @@ -645,6 +666,10 @@ namespace System.Collections.Generic { IntrospectiveSortUtilities.ThrowOrIgnoreBadComparer(comparer); } + catch (ThreadAbortException) + { + throw; + } catch (Exception e) { throw new InvalidOperationException(SR.InvalidOperation_IComparerFailed, e); @@ -893,6 +918,10 @@ namespace System.Collections.Generic { IntrospectiveSortUtilities.ThrowOrIgnoreBadComparer(comparer); } + catch (ThreadAbortException) + { + throw; + } catch (Exception e) { throw new InvalidOperationException(SR.InvalidOperation_IComparerFailed, e); -- cgit v1.2.3