Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing use of OOME left over from early days when IME was unavailable #4767

Merged
merged 1 commit into from
Nov 13, 2021
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 @@ -24,6 +24,7 @@ internal class InternalSR
internal static string ArgumentNullOrEmpty(object param0) => $"The argument {param0} is null or empty.";
internal static string AsyncResultCompletedTwice(object param0) => $"The IAsyncResult implementation '{param0}' tried to complete a single operation multiple times. This could be caused by an incorrect application IAsyncResult implementation or other extensibility code, such as an IAsyncResult that returns incorrect CompletedSynchronously values or invokes the AsyncCallback multiple times.";
internal static string BufferedOutputStreamQuotaExceeded(object param0) => $"The size quota for this stream ({param0}) has been exceeded.";
internal static string BufferAllocationFailed(int size) => $"Failed to allocate a managed memory buffer of {size} bytes. The amount of available memory may be low.";
internal static string FailFastMessage(object param0) => $"An unrecoverable error occurred. For diagnostic purposes, this English message is associated with the failure: '{param0}'.";
internal static string InvalidAsyncResultImplementation(object param0) => $"An incorrect implementation of the IAsyncResult interface may be returning incorrect values from the CompletedSynchronously property or calling the AsyncCallback more than once. The type {param0} could be the incorrect implementation.";
internal static string ShipAssertExceptionMessage(object param0) => $"An unexpected failure occurred. Applications should not attempt to handle this error. For diagnostic purposes, this English message is associated with the failure: '{param0}'.";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public static bool IsFatal(Exception exception)
while (exception != null)
{
if (exception is FatalException ||
exception is OutOfMemoryException ||
(exception is OutOfMemoryException && !(exception is InsufficientMemoryException)) ||
exception is FatalInternalException)
{
return true;
Expand Down Expand Up @@ -345,10 +345,9 @@ public static byte[] AllocateByteArray(int size)
}
catch (OutOfMemoryException exception)
{
// Desktop wraps the OOM inside a new InsufficientMemoryException, traces, and then throws it.
// Project N and K trace and throw the original OOM. InsufficientMemoryException does not exist in N and K.
Fx.Exception.AsError(exception);
throw;
// Convert OOM into an exception that can be safely handled by higher layers.
throw Exception.AsError(
new InsufficientMemoryException(InternalSR.BufferAllocationFailed(size), exception));
}
}

Expand All @@ -361,10 +360,9 @@ public static char[] AllocateCharArray(int size)
}
catch (OutOfMemoryException exception)
{
// Desktop wraps the OOM inside a new InsufficientMemoryException, traces, and then throws it.
// Project N and K trace and throw the original OOM. InsufficientMemoryException does not exist in N and K.
Fx.Exception.AsError(exception);
throw;
// Convert OOM into an exception that can be safely handled by higher layers.
throw Fx.Exception.AsError(
new InsufficientMemoryException(InternalSR.BufferAllocationFailed(size * sizeof(char)), exception));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1450,13 +1450,13 @@ public static Exception ConvertConnectException(SocketException socketException,
}
else if ((int)socketException.SocketErrorCode == UnsafeNativeMethods.WSAENOBUFS)
{
return new OutOfMemoryException(SR.TcpConnectNoBufs, innerException);
return new InsufficientMemoryException(SR.TcpConnectNoBufs, innerException);
}
else if ((int)socketException.SocketErrorCode == UnsafeNativeMethods.ERROR_NOT_ENOUGH_MEMORY ||
(int)socketException.SocketErrorCode == UnsafeNativeMethods.ERROR_NO_SYSTEM_RESOURCES ||
(int)socketException.SocketErrorCode == UnsafeNativeMethods.ERROR_OUTOFMEMORY)
{
return new OutOfMemoryException(SR.InsufficentMemory, socketException);
return new InsufficientMemoryException(SR.InsufficentMemory, socketException);
}
else
{
Expand Down