From 4c0387461c41cb66d26a43e3104879f7a83922a5 Mon Sep 17 00:00:00 2001 From: Slava Egorov Date: Fri, 1 Apr 2022 10:14:37 +0000 Subject: [PATCH] Revert "[VM / IO] - Reland : Assert when an OSError exception is reported with no error" This reverts commit dc8002cc429ffbeccac3d7be9f497739ae551e7b. Reason for revert: crashes internally (b/227727791) and externally (dartbug.com/48721) Original change's description: > [VM / IO] - Reland : Assert when an OSError exception is reported with no error > > 1. Add a Fatal assert when an OSError is reported with no error code (0). > This is to ensure we get a coredum pwhen this happens so we can analyze > it. (Please see https://github.com/flutter/flutter/issues/90921 for more > details) > > TEST=ci > > Change-Id: I7146ac69ef8b1833f28bed8a23f0c27a2ece4bbf > Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/239726 > Reviewed-by: Alexander Aprelev > Commit-Queue: Siva Annamalai TBR=aam@google.com,asiva@google.com Change-Id: Ic9302e7922b0ce2ea5ab81357804c3cd822a8052 No-Presubmit: true No-Tree-Checks: true No-Try: true Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/239664 Reviewed-by: Slava Egorov Bot-Commit: Rubber Stamper Commit-Queue: Slava Egorov --- runtime/bin/dartutils.cc | 3 --- runtime/bin/socket.cc | 13 +------------ sdk/lib/_internal/vm/bin/socket_patch.dart | 16 +++++----------- 3 files changed, 6 insertions(+), 26 deletions(-) diff --git a/runtime/bin/dartutils.cc b/runtime/bin/dartutils.cc index d73c065c397..5f2e056473d 100644 --- a/runtime/bin/dartutils.cc +++ b/runtime/bin/dartutils.cc @@ -680,9 +680,6 @@ Dart_Handle DartUtils::NewDartOSError(OSError* os_error) { Dart_Handle type = GetDartType(kIOLibURL, "OSError"); ASSERT(!Dart_IsError(type)); Dart_Handle args[2]; - if (os_error->code() == 0) { - FATAL("Fatal error OSError (code : 0) DartUtils::NewDartOSError"); - } args[0] = NewString(os_error->message()); args[1] = Dart_NewInteger(os_error->code()); return Dart_New(type, Dart_Null(), 2, args); diff --git a/runtime/bin/socket.cc b/runtime/bin/socket.cc index 708bda49461..21bfadf3cff 100644 --- a/runtime/bin/socket.cc +++ b/runtime/bin/socket.cc @@ -914,18 +914,7 @@ void FUNCTION_NAME(Socket_GetError)(Dart_NativeArguments args) { Socket::GetSocketIdNativeField(Dart_GetNativeArgument(args, 0)); OSError os_error; SocketBase::GetError(socket->fd(), &os_error); - if (os_error.code() != 0) { - Dart_SetReturnValue(args, DartUtils::NewDartOSError(&os_error)); - } else { - Dart_SetReturnValue(args, Dart_Null()); - } -} - -void FUNCTION_NAME(Socket_Fatal)(Dart_NativeArguments args) { - Dart_Handle msg = Dart_GetNativeArgument(args, 0); - const char* msgStr = - (!Dart_IsNull(msg)) ? DartUtils::GetStringValue(msg) : nullptr; - FATAL("Fatal error in dart:io (socket): %s", msgStr); + Dart_SetReturnValue(args, DartUtils::NewDartOSError(&os_error)); } void FUNCTION_NAME(Socket_GetFD)(Dart_NativeArguments args) { diff --git a/sdk/lib/_internal/vm/bin/socket_patch.dart b/sdk/lib/_internal/vm/bin/socket_patch.dart index d0bddf85fbf..7c9925a83c2 100644 --- a/sdk/lib/_internal/vm/bin/socket_patch.dart +++ b/sdk/lib/_internal/vm/bin/socket_patch.dart @@ -877,8 +877,8 @@ class _NativeSocket extends _NativeSocketNativeWrapper with _ServiceObject { // the SO_ERROR option at level SOL_SOCKET to determine whether // connect() completed successfully (SO_ERROR is zero) or // unsuccessfully. - final osError = socket.nativeGetError(); - if (osError != null) { + final OSError osError = socket.nativeGetError(); + if (osError.errorCode != 0) { socket.close(); error ??= osError; connectNext(); @@ -1404,12 +1404,8 @@ class _NativeSocket extends _NativeSocketNativeWrapper with _ServiceObject { if (i == errorEvent) { if (!isClosing) { - final osError = nativeGetError(); - if (osError == null) { - _nativeFatal("Reporting error with OSError code of 0"); - } else { - reportError(osError, null, osError.message); - } + final err = nativeGetError(); + reportError(err, null, err.message); } } else if (!isClosed) { // If the connection is closed right after it's accepted, there's a @@ -1692,7 +1688,7 @@ class _NativeSocket extends _NativeSocketNativeWrapper with _ServiceObject { @pragma("vm:external-name", "Socket_GetFD") external int get fd; @pragma("vm:external-name", "Socket_GetError") - external OSError? nativeGetError(); + external OSError nativeGetError(); @pragma("vm:external-name", "Socket_GetOption") external nativeGetOption(int option, int protocol); @pragma("vm:external-name", "Socket_GetRawOption") @@ -1707,8 +1703,6 @@ class _NativeSocket extends _NativeSocketNativeWrapper with _ServiceObject { @pragma("vm:external-name", "Socket_LeaveMulticast") external void nativeLeaveMulticast( Uint8List addr, Uint8List? interfaceAddr, int interfaceIndex); - @pragma("vm:external-name", "Socket_Fatal") - external static void _nativeFatal(msg); } class _RawServerSocket extends Stream implements RawServerSocket {