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

Failed to deserialize the passed arguments to the new isolate. #50082

Closed
Cat-sushi opened this issue Sep 29, 2022 · 33 comments
Closed

Failed to deserialize the passed arguments to the new isolate. #50082

Cat-sushi opened this issue Sep 29, 2022 · 33 comments
Assignees
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. P2 A bug or feature request we're likely to work on

Comments

@Cat-sushi
Copy link

Cat-sushi commented Sep 29, 2022

This tracker is for issues related to:
Dart SDK version: 2.18.2 (stable) (Unknown timestamp) on "linux_x64"

My application spawning isolates fails.
In debug mode without breakpoint of uncaught exceptions, it shows:

Unhandled exception:
IsolateSpawnException: Unable to spawn isolate: Failed to deserialize the passed arguments to the new isolate.
Exited (255)

In debug mode with breakpoint of uncaught exceptions, it breaks at line 51 of errors_patch.dart with exeption:

_AssertionError ('dart:collection-patch/compact_hash.dart': Failed assertion: line 441 pos 12: '<optimized out>': is not true.)

with call stack

_AssertionError._doThrowNew (dart:core-patch/errors_patch.dart:51)
_AssertionError._throwNew (dart:core-patch/errors_patch.dart:40)
_LinkedHashMapMixin._regenerateIndex (dart:collection-patch/compact_hash.dart:441)
_rehashObjects (dart:collection-patch/compact_hash.dart:15)

In non-debug mode the app crashes with some different messages such as,

===== CRASH =====
si_signo=Segmentation fault(11), si_code=1, si_addr=0x7f97c03e6491
version=2.18.2 (stable) (Unknown timestamp) on "linux_x64"
pid=1040583, thread=1040671, isolate_group=main(0x55b9ef5ac000), isolate=Client.serverMain(0x55b9efa79000)
isolate_instructions=55b9ed8301c0, vm_instructions=55b9ed8301c0
  pc 0x00007f97c03e6491 fp 0x00007f97b8e7da28 Unknown symbol
  pc 0x00007f97c081434a fp 0x00007f97b8e7da90 Unknown symbol
  pc 0x00007f97bf3f9b93 fp 0x00007f97b8e7dad0 Unknown symbol
  pc 0x00007f97c5879dbf fp 0x00007f97b8e7db30 Unknown symbol
  pc 0x00007f97bfae97b6 fp 0x00007f97b8e7db70 Unknown symbol
  pc 0x00007f97bfae970e fp 0x00007f97b8e7dba8 Unknown symbol
  pc 0x00007f97bfae94d4 fp 0x00007f97b8e7dc08 Unknown symbol
  pc 0x00007f97bfae92e6 fp 0x00007f97b8e7dc70 Unknown symbol
  pc 0x00007f97bfae8f45 fp 0x00007f97b8e7dcc8 Unknown symbol
  pc 0x00007f97c0866586 fp 0x00007f97b8e7dd50 Unknown symbol
  pc 0x00007f97bea82a24 fp 0x00007f97b8e7de48 Unknown symbol
  pc 0x00007f97bf3e3de0 fp 0x00007f97b8e7dee8 Unknown symbol
  pc 0x00007f97c5ef37fd fp 0x00007f97b8e7df38 Unknown symbol
  pc 0x00007f97c5ee4f6c fp 0x00007f97b8e7df90 Unknown symbol
  pc 0x00007f97c5ee4c6e fp 0x00007f97b8e7dfe0 Unknown symbol
  pc 0x00007f97c5ee498e fp 0x00007f97b8e7e040 Unknown symbol
  pc 0x00007f97c0845eb9 fp 0x00007f97b8e7e0a8 Unknown symbol
  pc 0x00007f97c5ef35e1 fp 0x00007f97b8e7e0f0 Unknown symbol
  pc 0x00007f97c5ef3001 fp 0x00007f97b8e7e148 Unknown symbol
  pc 0x00007f97c085705b fp 0x00007f97b8e7e180 Unknown symbol
  pc 0x00007f97c5eeddf1 fp 0x00007f97b8e7e200 Unknown symbol
  pc 0x00007f97c084295e fp 0x00007f97b8e7e250 Unknown symbol
  pc 0x00007f97c5eed693 fp 0x00007f97b8e7e290 Unknown symbol
  pc 0x00007f97c5eed438 fp 0x00007f97b8e7e2d0 Unknown symbol
  pc 0x00007f97c5eed18e fp 0x00007f97b8e7e310 Unknown symbol
  pc 0x00007f97c5eece8f fp 0x00007f97b8e7e350 Unknown symbol
  pc 0x00007f97bf3f5a1d fp 0x00007f97b8e7e390 Unknown symbol
  pc 0x00007f97c5ea492f fp 0x00007f97b8e7e3f8 Unknown symbol
  pc 0x00007f97c5ea41a3 fp 0x00007f97b8e7e448 Unknown symbol
  pc 0x00007f97cc182a0c fp 0x00007f97b8e7e4c0 Unknown symbol
  pc 0x000055b9ed9a837d fp 0x00007f97b8e7e560 dart::DartEntry::InvokeCode(dart::Code const&, unsigned long, dart::Array const&, dart::Array const&, dart::Thread*)+0x14d
  pc 0x000055b9ed9a81bc fp 0x00007f97b8e7e5c0 dart::DartEntry::InvokeFunction(dart::Function const&, dart::Array const&, dart::Array const&, unsigned long)+0x14c

  pc 0x000055b9ed9aa5ec fp 0x00007f97b8e7e610 dart::DartLibraryCalls::HandleMessage(long, dart::Instance const&)+0x14c
  pc 0x000055b9ed9d1c60 fp 0x00007f97b8e7eba0 dart::IsolateMessageHandler::HandleMessage(std::__2::unique_ptr<dart::Message, std::__2::default_delete<dart::Message> >)+0x350
  pc 0x000055b9ed9fb18d fp 0x00007f97b8e7ec10 dart::MessageHandler::HandleMessages(dart::MonitorLocker*, bool, bool)+0x14d
  pc 0x000055b9ed9fb86f fp 0x00007f97b8e7ec60 dart::MessageHandler::TaskCallback()+0x1df

  pc 0x000055b9edb1e728 fp 0x00007f97b8e7ece0 dart::ThreadPool::WorkerLoop(dart::ThreadPool::Worker*)+0x148
  pc 0x000055b9edb1eb7d fp 0x00007f97b8e7ed10 dart::ThreadPool::Worker::Main(unsigned long)+0x6d
  pc 0x000055b9eda91348 fp 0x00007f97b8e7edd0 /usr/lib/dart/bin/dart+0x2163348
-- End of DumpStackTrace
Aborted (core dumped)
Exited (134)

or

../../runtime/vm/object.cc: 23945: error: Fatal error in OneByteString::New: invalid len -1

version=2.18.2 (stable) (Unknown timestamp) on "linux_x64"
pid=1076082, thread=1076169, isolate_group=main(0x5578fbc83000), isolate=Client.serverMain(0x5578fbc80800)
isolate_instructions=5578fa8e11c0, vm_instructions=5578fa8e11c0
  pc 0x00005578fab4616c fp 0x00007f0c8f87d2f0 dart::Profiler::DumpStackTrace(void*)+0x7c
  pc 0x00005578fa8e1374 fp 0x00007f0c8f87d3d0 dart::Assert::Fail(char const*, ...) const+0x84

  pc 0x00005578fab145e2 fp 0x00007f0c8f87d430 dart::String::SubString(dart::Thread*, dart::String const&, long, long, dart::Heap::Space)+0x1e2
  pc 0x00005578faabc62d fp 0x00007f0c8f87d960 dart::NativeEntry::BootstrapNativeCallWrapper(_Dart_NativeArguments*, void (*)(_Dart_NativeArguments*))+0xbd
  pc 0x00007f0c9f1026a4 fp 0x00007f0c8f87d9a8 Unknown symbol
  pc 0x00007f0c96b124d9 fp 0x00007f0c8f87d9f8 Unknown symbol
  pc 0x00007f0c96b42523 fp 0x00007f0c8f87da30 Unknown symbol
  pc 0x00007f0c98f7e299 fp 0x00007f0c8f87da90 Unknown symbol
  pc 0x00007f0c92be9a27 fp 0x00007f0c8f87dad8 Unknown symbol
  pc 0x00007f0c927f9c30 fp 0x00007f0c8f87db20 Unknown symbol
  pc 0x00007f0c988f9ee0 fp 0x00007f0c8f87db80 Unknown symbol
  pc 0x00007f0c92be97b6 fp 0x00007f0c8f87dbc0 Unknown symbol
  pc 0x00007f0c92be970e fp 0x00007f0c8f87dbf8 Unknown symbol
  pc 0x00007f0c92be94d4 fp 0x00007f0c8f87dc58 Unknown symbol
  pc 0x00007f0c92be92e6 fp 0x00007f0c8f87dcc0 Unknown symbol
  pc 0x00007f0c92be8f45 fp 0x00007f0c8f87dd18 Unknown symbol
  pc 0x00007f0c96b65526 fp 0x00007f0c8f87dda0 Unknown symbol
  pc 0x00007f0c8fb01a24 fp 0x00007f0c8f87de98 Unknown symbol
  pc 0x00007f0c927e3de0 fp 0x00007f0c8f87df38 Unknown symbol
  pc 0x00007f0c98f737fd fp 0x00007f0c8f87df88 Unknown symbol
  pc 0x00007f0c84d17eca fp 0x00007f0c8f87dfe0 Unknown symbol
  pc 0x00007f0c98f6498e fp 0x00007f0c8f87e040 Unknown symbol
  pc 0x00007f0c96b47ce9 fp 0x00007f0c8f87e0a8 Unknown symbol
  pc 0x00007f0c98f735e1 fp 0x00007f0c8f87e0f0 Unknown symbol
  pc 0x00007f0c98f73001 fp 0x00007f0c8f87e148 Unknown symbol
  pc 0x00007f0c96b584fb fp 0x00007f0c8f87e180 Unknown symbol
  pc 0x00007f0c98f6ddf1 fp 0x00007f0c8f87e200 Unknown symbol
  pc 0x00007f0c96b4295e fp 0x00007f0c8f87e250 Unknown symbol
  pc 0x00007f0c98f6d693 fp 0x00007f0c8f87e290 Unknown symbol
  pc 0x00007f0c98f6d438 fp 0x00007f0c8f87e2d0 Unknown symbol
  pc 0x00007f0c98f6d18e fp 0x00007f0c8f87e310 Unknown symbol
  pc 0x00007f0c98f6ce8f fp 0x00007f0c8f87e350 Unknown symbol
  pc 0x00007f0c927f58dd fp 0x00007f0c8f87e390 Unknown symbol
  pc 0x00007f0c98f2492f fp 0x00007f0c8f87e3f8 Unknown symbol
  pc 0x00007f0c98f241a3 fp 0x00007f0c8f87e448 Unknown symbol
  pc 0x00007f0c9f102a0c fp 0x00007f0c8f87e4c0 Unknown symbol
  pc 0x00005578faa5937d fp 0x00007f0c8f87e560 dart::DartEntry::InvokeCode(dart::Code const&, unsigned long, dart::Array const&, dart::Array const&, dart::Thread*)+0x14d
  pc 0x00005578faa591bc fp 0x00007f0c8f87e5c0 dart::DartEntry::InvokeFunction(dart::Function const&, dart::Array const&, dart::Array const&, unsigned long)+0x14c

  pc 0x00005578faa5b5ec fp 0x00007f0c8f87e610 dart::DartLibraryCalls::HandleMessage(long, dart::Instance const&)+0x14c
  pc 0x00005578faa82c60 fp 0x00007f0c8f87eba0 dart::IsolateMessageHandler::HandleMessage(std::__2::unique_ptr<dart::Message, std::__2::default_delete<dart::Message> >)+0x350
  pc 0x00005578faaac18d fp 0x00007f0c8f87ec10 dart::MessageHandler::HandleMessages(dart::MonitorLocker*, bool, bool)+0x14d
  pc 0x00005578faaac86f fp 0x00007f0c8f87ec60 dart::MessageHandler::TaskCallback()+0x1df
  pc 0x00005578fabcf728 fp 0x00007f0c8f87ece0 dart::ThreadPool::WorkerLoop(dart::ThreadPool::Worker*)+0x148
  pc 0x00005578fabcfb7d fp 0x00007f0c8f87ed10 dart::ThreadPool::Worker::Main(unsigned long)+0x6d
  pc 0x00005578fab42348 fp 0x00007f0c8f87edd0 /usr/lib/dart/bin/dart+0x2163348
-- End of DumpStackTrace
  pc 0x0000000000000000 fp 0x00007f0c8f87d9a8 sp 0x0000000000000000 [Stub] CallBootstrapNative
  pc 0x00007f0c96b124d9 fp 0x00007f0c8f87d9f8 sp 0x00007f0c8f87d9b8 [Unoptimized] _StringBase@0150898._substringUncheckedNative@0150898
  pc 0x00007f0c96b42523 fp 0x00007f0c8f87da30 sp 0x00007f0c8f87da08 [Optimized] _StringBase@0150898._substringUnchecked@0150898
  pc 0x00007f0c98f7e299 fp 0x00007f0c8f87da90 sp 0x00007f0c8f87da40 [Unoptimized] _RegExpMatch@0150898.group
  pc 0x00007f0c92be9a27 fp 0x00007f0c8f87dad8 sp 0x00007f0c8f87daa0 [Unoptimized] Preprocessor.wordize.<anonymous closure>
  pc 0x00007f0c927f9c30 fp 0x00007f0c8f87db20 sp 0x00007f0c8f87dae8 [Optimized] MappedIterator.moveNext
  pc 0x00007f0c988f9ee0 fp 0x00007f0c8f87db80 sp 0x00007f0c8f87db30 [Optimized] new _GrowableList@0150898._ofOther@0150898
  pc 0x00007f0c92be97b6 fp 0x00007f0c8f87dbc0 sp 0x00007f0c8f87db90 [Unoptimized] new _List@0150898._ofOther@0150898
  pc 0x00007f0c92be970e fp 0x00007f0c8f87dbf8 sp 0x00007f0c8f87dbd0 [Unoptimized] new _List@0150898.of
  pc 0x00007f0c92be94d4 fp 0x00007f0c8f87dc58 sp 0x00007f0c8f87dc08 [Unoptimized] new List.of
  pc 0x00007f0c92be92e6 fp 0x00007f0c8f87dcc0 sp 0x00007f0c8f87dc68 [Unoptimized] Iterable.toList
  pc 0x00007f0c92be8f45 fp 0x00007f0c8f87dd18 sp 0x00007f0c8f87dcd0 [Unoptimized] Preprocessor.wordize
  pc 0x00007f0c96b65526 fp 0x00007f0c8f87dda0 sp 0x00007f0c8f87dd28 [Unoptimized] Preprocessor.preprocess
  pc 0x00007f0c8fb01a24 fp 0x00007f0c8f87de98 sp 0x00007f0c8f87ddb0 [Unoptimized] FMatcher.fmatch
  pc 0x00007f0c927e3de0 fp 0x00007f0c8f87df38 sp 0x00007f0c8f87dea8 [Unoptimized] Client.serverMain
  pc 0x00007f0c98f737fd fp 0x00007f0c8f87df88 sp 0x00007f0c8f87df48 [Unoptimized] _SuspendState@4048458._createAsyncCallbacks@4048458.thenCallback
  pc 0x00007f0c84d17eca fp 0x00007f0c8f87dfe0 sp 0x00007f0c8f87df98 [Optimized] _FutureListener@4048458.handleValue
  pc 0x00007f0c98f6498e fp 0x00007f0c8f87e040 sp 0x00007f0c8f87dff0 [Unoptimized] _Future@4048458._propagateToListeners@4048458.handleValueCallback
  pc 0x00007f0c96b47ce9 fp 0x00007f0c8f87e0a8 sp 0x00007f0c8f87e050 [Optimized] _Future@4048458._propagateToListeners@4048458
  pc 0x00007f0c98f735e1 fp 0x00007f0c8f87e0f0 sp 0x00007f0c8f87e0b8 [Unoptimized] _Future@4048458._complete@4048458
  pc 0x00007f0c98f73001 fp 0x00007f0c8f87e148 sp 0x00007f0c8f87e100 [Unoptimized] _StreamIterator@4048458._onData@4048458
  pc 0x00007f0c96b584fb fp 0x00007f0c8f87e180 sp 0x00007f0c8f87e158 [Optimized] _StreamIterator@4048458._onData@4048458
  pc 0x00007f0c98f6ddf1 fp 0x00007f0c8f87e200 sp 0x00007f0c8f87e190 [Unoptimized] _RootZone@4048458.runUnaryGuarded
  pc 0x00007f0c96b4295e fp 0x00007f0c8f87e250 sp 0x00007f0c8f87e210 [Optimized] _BufferingStreamSubscription@4048458._sendData@4048458
  pc 0x00007f0c98f6d693 fp 0x00007f0c8f87e290 sp 0x00007f0c8f87e260 [Unoptimized] _BufferingStreamSubscription@4048458._add@4048458
  pc 0x00007f0c98f6d438 fp 0x00007f0c8f87e2d0 sp 0x00007f0c8f87e2a0 [Unoptimized] _SyncStreamController@4048458._sendData@4048458
  pc 0x00007f0c98f6d18e fp 0x00007f0c8f87e310 sp 0x00007f0c8f87e2e0 [Unoptimized] _StreamController@4048458._add@4048458
  pc 0x00007f0c98f6ce8f fp 0x00007f0c8f87e350 sp 0x00007f0c8f87e320 [Unoptimized] _StreamController@4048458.add
  pc 0x00007f0c927f58dd fp 0x00007f0c8f87e390 sp 0x00007f0c8f87e360 [Unoptimized] _StreamController@4048458.add
  pc 0x00007f0c98f2492f fp 0x00007f0c8f87e3f8 sp 0x00007f0c8f87e3a0 [Unoptimized] _Closure@0150898.dyn:call
  pc 0x00007f0c98f241a3 fp 0x00007f0c8f87e448 sp 0x00007f0c8f87e408 [Unoptimized] _RawReceivePortImpl@1026248._handleMessage@1026248
  pc 0x00007f0c9f102a0c fp 0x00007f0c8f87e4c0 sp 0x00007f0c8f87e458 [Stub] InvokeDartCode

Aborted (core dumped)
Exited (134)

In AOT compiled mode, it is stable.

@lrhn lrhn added the area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. label Sep 29, 2022
@mraleph
Copy link
Member

mraleph commented Sep 30, 2022

/cc @aam @mkustermann

@mkustermann
Copy link
Member

When starting isolates with Isolate.spawn() one provides an entrypoint and an argument. It seems one of those is transitively hanging on to a Map with keys that are not primitives and therefore needs re-hashing when copying those maps.

The assertion that is hit

 assert(_hashMask == _HashBase._UNINITIALIZED_HASH_MASK);

is a red flag.

The transitive copy code is setting this to 0 if the map needs to be rehashed. So if we hit the assert, it may indicate there's a memory corruption (also due to the fact that there's segfaults in non-debug mode).

@Cat-sushi Is there any way you could provide us with more context of how the Isolate.spawn() code looks like and what data it gets as entrypoint and argument? Does this also happen when using the latest dev channel?

@Cat-sushi
Copy link
Author

Cat-sushi commented Sep 30, 2022

Edited: add implementation of hashCode, operator ==, and compreTo()

When starting isolates with Isolate.spawn() one provides an entrypoint and an argument. It seems one of those is transitively hanging on to a Map with keys that are not primitives and therefore needs re-hashing when copying those maps.

Yes.

Does this also happen when using the latest dev channel?

I haven't try yet.
It happens at least from 2.18.0 to 2.18.2.

spawning code snippet is,

    await Isolate.spawn<List<dynamic>>(
        serverMain, <dynamic>[crp.sendPort, matcher, cacheServer]); // cacheServer is SendPort as well

matcher contains non-primitive-key maps as shown below,

class Db {
  final Map<Entry, Preprocessed> _map = {};
  ...
}
class Entry implements Comparable<Entry> {
  static final _canonicalized = <String, Entry>{};
  final String string;
  @override
  int compareTo(dynamic other) => string.compareTo((other as Entry).string);
  @override
  int get hashCode => string.hashCode;
  @override
  operator ==(Object other) => string == (other as Entry).string;
  ...
}
class Preprocessed {
  final LetType letType; // enum
  final List<Term> terms;
  ...
}
class Term implements Comparable<Term> {
  static final _canonicalized = <String, Term>{};
  final String string; // redundant for performance optimization
  final Int32List runes;
  @override
  int compareTo(dynamic other) => string.compareTo((other as Term).string);
  @override
  int get hashCode => string.hashCode;
  @override
  operator ==(Object other) => string == (other as Term).string;
  ...
}

class IDb {
  final _map = <IDbEntryKey, IDbEntryValue>{};
  late final int maxTermLength;
  late final List<List<MapEntry<IDbEntryKey, IDbEntryValue>>?>
      listsByTermLength;
  ...
}
class IDbEntryKey implements Comparable<IDbEntryKey> {
  final Term term;
  final bool isLet;
  @override
  final int hashCode;
  @override
  int compareTo(IDbEntryKey other) {
    var tc = term.compareTo(other.term);
    if (tc != 0) {
      return tc;
    }
    if (isLet == other.isLet) {
      return 0;
    }
    if (isLet == false) {
      return -1;
    }
    return 1;
  }
  @override
  bool operator ==(Object other) =>
      identical(this, other) ||
      other is IDbEntryKey && term == other.term && isLet == other.isLet;
  IDbEntryKey(this.term, this.isLet) : hashCode = Object.hash(term, isLet);
  ...
}
class IDbEntryValue {
  final int df;
  final List<IDbTermOccurrence> occurrences;
  ...
}
class IDbTermOccurrence {
  final Entry entry;
  final int position;
  ...
}

@a-siva a-siva added P2 A bug or feature request we're likely to work on vm-triaged labels Nov 4, 2022
@a-siva
Copy link
Contributor

a-siva commented Nov 4, 2022

//cc @aam

@Cat-sushi
Copy link
Author

I think this is not necessarily related to LinkedHashMap with non-primitive kyes, because Preprocessor.wordize which is invoked in successfully spawned isolates is not related to the LinkedHashMap.
Exceptions are thrown from several different point.

version=2.18.4 (stable) (Unknown timestamp) on "linux_x64"
non-debug mode

IDb.read : 664
Db.fromIDb : 120
Unhandled exception:
'dart:core-patch/string_patch.dart': Failed assertion: line 408 pos 12: '<optimized out>': is not true.
#0      _AssertionError._doThrowNew (dart:core-patch/errors_patch.dart:51:61)
#1      _AssertionError._throwNew (dart:core-patch/errors_patch.dart:40:5)
#2      _StringBase._substringUnchecked (dart:core-patch/string_patch.dart:408:12)
#3      _RegExpMatch.group (dart:core-patch/regexp_patch.dart:174:18)
#4      Preprocessor.wordize.<anonymous closure>
#5      MappedIterator.moveNext (dart:_internal/iterable.dart:391:20)
#6      new _GrowableList._ofOther (dart:core-patch/growable_array.dart:202:26)
#7      new _List._ofOther (dart:core-patch/array.dart:174:43)
#8      new _List.of (dart:core-patch/array.dart:128:18)
#9      new List.of (dart:core-patch/array_patch.dart:53:20)
#10     Iterable.toList (dart:core/iterable.dart:470:12)
#11     Preprocessor.wordize
#12     Preprocessor.preprocess
#13     FMatcher.fmatch
#14     Client.serverMain
<asynchronous suspension>

Unhandled exception:
RangeError (index): Invalid value: Only valid value is 0: -3
#0      String.codeUnitAt (dart:core-patch/string_patch.dart:1001:37)
#1      _AllMatchesIterator.moveNext (dart:core-patch/regexp_patch.dart:414:37)
#2      _StringBase.replaceAllMapped (dart:core-patch/string_patch.dart:737:33)
#3      Preprocessor.replaceWords
#4      Preprocessor.preprocess
#5      FMatcher.fmatch
#6      Client.serverMain
<asynchronous suspension>


===== CRASH =====
si_signo=Segmentation fault(11), si_code=2, si_addr=0x7fbabe98b191
version=2.18.4 (stable) (Unknown timestamp) on "linux_x64"
pid=1088936, thread=1089032, isolate_group=main(0x56498ff3b000), isolate=Client.serverMain(0x56499339a000)
isolate_instructions=56498db3f280, vm_instructions=56498db3f280
  pc 0x00007fbabe98b191 fp 0x00007fbab5ffda10 Unknown symbol
  pc 0x00007fbabe988041 fp 0x00007fbab5ffdaa0 Unknown symbol
  pc 0x00007fbaab58e927 fp 0x00007fbab5ffdaf8 Unknown symbol
  pc 0x00007fbab4d880f3 fp 0x00007fbab5ffdb38 Unknown symbol
  pc 0x00007fbab64787ed fp 0x00007fbab5ffdb98 Unknown symbol
  pc 0x00007fbab95f5e25 fp 0x00007fbab5ffdbc8 Unknown symbol
  pc 0x00007fbab6cfd274 fp 0x00007fbab5ffdc28 Unknown symbol
  pc 0x00007fbab6cfd086 fp 0x00007fbab5ffdc90 Unknown symbol
  pc 0x00007fbab6cfcce5 fp 0x00007fbab5ffdce8 Unknown symbol
  pc 0x00007fbab7a81536 fp 0x00007fbab5ffdd70 Unknown symbol
  pc 0x00007fbab4d871d7 fp 0x00007fbab5ffde48 Unknown symbol
  pc 0x00007fbab6476fb7 fp 0x00007fbab5ffdf00 Unknown symbol
  pc 0x00007fbab95dac0d fp 0x00007fbab5ffdf50 Unknown symbol
  pc 0x00007fbab4dffc46 fp 0x00007fbab5ffdfb8 Unknown symbol
  pc 0x00007fbaa8f957b6 fp 0x00007fbab5ffe030 Unknown symbol
  pc 0x00007fbab8bde9b1 fp 0x00007fbab5ffe098 Unknown symbol
  pc 0x00007fbaa8f9a65d fp 0x00007fbab5ffe0e8 Unknown symbol
  pc 0x00007fbab8b8cb11 fp 0x00007fbab5ffe140 Unknown symbol
  pc 0x00007fbab8be7ddb fp 0x00007fbab5ffe178 Unknown symbol
  pc 0x00007fbab95cff91 fp 0x00007fbab5ffe1f8 Unknown symbol
  pc 0x00007fbab8bdc6d3 fp 0x00007fbab5ffe250 Unknown symbol
  pc 0x00007fbab8bdf624 fp 0x00007fbab5ffe298 Unknown symbol
  pc 0x00007fbab95cedb8 fp 0x00007fbab5ffe2d8 Unknown symbol
  pc 0x00007fbab95ce9fe fp 0x00007fbab5ffe318 Unknown symbol
  pc 0x00007fbab18302b8 fp 0x00007fbab5ffe350 Unknown symbol
  pc 0x00007fbab95d012d fp 0x00007fbab5ffe390 Unknown symbol
  pc 0x00007fbab95a37ef fp 0x00007fbab5ffe3f8 Unknown symbol
  pc 0x00007fbab95a3063 fp 0x00007fbab5ffe448 Unknown symbol
  pc 0x00007fbabe882a0c fp 0x00007fbab5ffe4c0 Unknown symbol
  pc 0x000056498dcb743d fp 0x00007fbab5ffe560 dart::DartEntry::InvokeCode(dart::Code const&, unsigned long, dart::Array const&, dart::Array const&, dart::Thread*)+0x14d
  pc 0x000056498dcb727c fp 0x00007fbab5ffe5c0 dart::DartEntry::InvokeFunction(dart::Function const&, dart::Array const&, dart::Array const&, unsigned long)+0x14c

  pc 0x000056498dcb96ac fp 0x00007fbab5ffe610 dart::DartLibraryCalls::HandleMessage(long, dart::Instance const&)+0x14c
  pc 0x000056498dce0d70 fp 0x00007fbab5ffeba0 dart::IsolateMessageHandler::HandleMessage(std::__2::unique_ptr<dart::Message, std::__2::default_delete<dart::Message> >)+0x350

  pc 0x000056498dd0a29d fp 0x00007fbab5ffec10 dart::MessageHandler::HandleMessages(dart::MonitorLocker*, bool, bool)+0x14d
  pc 0x000056498dd0a97f fp 0x00007fbab5ffec60 dart::MessageHandler::TaskCallback()+0x1df
  pc 0x000056498de2d3b8 fp 0x00007fbab5ffece0 dart::ThreadPool::WorkerLoop(dart::ThreadPool::Worker*)+0x148

  pc 0x000056498de2d80d fp 0x00007fbab5ffed10 dart::ThreadPool::Worker::Main(unsigned long)+0x6d
  pc 0x000056498dda0458 fp 0x00007fbab5ffedd0 /usr/lib/dart/bin/dart+0x2163458
-- End of DumpStackTrace

Aborted (core dumped)
Exited (134)
IDb.read : 1005
Db.fromIDb : 115
100	12647	12647		3	3
200	17930	5283		2	5
300	18886	955		0	5
400	21597	2711		2	7
500	33043	11445		1	8
Unhandled exception:
'dart:core-patch/string_patch.dart': Failed assertion: line 406 pos 12: '<optimized out>': is not true.
#0      _AssertionError._doThrowNew (dart:core-patch/errors_patch.dart:51:61)
#1      _AssertionError._throwNew (dart:core-patch/errors_patch.dart:40:5)
#2      _StringBase._substringUnchecked (dart:core-patch/string_patch.dart:406:12)
#3      _RegExpMatch.group (dart:core-patch/regexp_patch.dart:174:18)
#4      Preprocessor.wordize.<anonymous closure>
#5      MappedIterator.moveNext (dart:_internal/iterable.dart:391:20)
#6      new _GrowableList._ofOther (dart:core-patch/growable_array.dart:202:26)
#7      new _List._ofOther (dart:core-patch/array.dart:174:43)
#8      new _List.of (dart:core-patch/array.dart:128:18)
#9      new List.of (dart:core-patch/array_patch.dart:53:20)
#10     Iterable.toList (dart:core/iterable.dart:470:12)
#11     Preprocessor.wordize
#12     Preprocessor.preprocess
#13     FMatcher.fmatch
#14     Client.serverMain
<asynchronous suspension>

600	33526	483		1	9
700	33551	25		3	12
Unhandled exception:
'dart:core-patch/regexp_patch.dart': Failed assertion: line 171 pos 14: '<optimized out>': is not true.
#0      _AssertionError._doThrowNew (dart:core-patch/errors_patch.dart:51:61)
#1      _AssertionError._throwNew (dart:core-patch/errors_patch.dart:40:5)
#2      _RegExpMatch.group (dart:core-patch/regexp_patch.dart:171:14)
#3      Preprocessor.wordize.<anonymous closure>
#4      MappedIterator.moveNext (dart:_internal/iterable.dart:391:20)
#5      new _GrowableList._ofOther (dart:core-patch/growable_array.dart:202:26)
#6      new _List._ofOther (dart:core-patch/array.dart:174:43)
#7      new _List.of (dart:core-patch/array.dart:128:18)
#8      new List.of (dart:core-patch/array_patch.dart:53:20)
#9      Iterable.toList (dart:core/iterable.dart:470:12)
#10     Preprocessor.wordize
#11     Preprocessor.preprocess
#12     FMatcher.fmatch
#13     Client.serverMain
<asynchronous suspension>


===== CRASH =====
si_signo=Segmentation fault(11), si_code=2, si_addr=0x7f25bb68b191
version=2.18.4 (stable) (Unknown timestamp) on "linux_x64"
pid=1095412, thread=1095897, isolate_group=main(0x5585d1c05800), isolate=Client.serverMain(0x5585d5138000)
isolate_instructions=5585cff8d280, vm_instructions=5585cff8d280
  pc 0x00007f25bb68b191 fp 0x00007f25b90fda40 Unknown symbol
  pc 0x00007f25bb688041 fp 0x00007f25b90fdad0 Unknown symbol
  pc 0x00007f25aca1d713 fp 0x00007f25b90fdb20 Unknown symbol
  pc 0x00007f25b32f6523 fp 0x00007f25b90fdb60 Unknown symbol
  pc 0x00007f25b32ecd91 fp 0x00007f25b90fdbb8 Unknown symbol
  pc 0x00007f25a5ae13f5 fp 0x00007f25b90fdbe8 Unknown symbol
  pc 0x00007f25a5ae366c fp 0x00007f25b90fdc28 Unknown symbol
  pc 0x00007f25b3afd086 fp 0x00007f25b90fdc90 Unknown symbol
  pc 0x00007f25b3afcce5 fp 0x00007f25b90fdce8 Unknown symbol
  pc 0x00007f25b49013d6 fp 0x00007f25b90fdd70 Unknown symbol
  pc 0x00007f25b2207d07 fp 0x00007f25b90fde48 Unknown symbol
  pc 0x00007f25b32fc397 fp 0x00007f25b90fdf00 Unknown symbol
  pc 0x00007f25b69dac0d fp 0x00007f25b90fdf50 Unknown symbol
  pc 0x00007f25a5aab7b6 fp 0x00007f25b90fdfb8 Unknown symbol
  pc 0x00007f25a5ad7f06 fp 0x00007f25b90fe030 Unknown symbol
  pc 0x00007f25b5ade9b1 fp 0x00007f25b90fe098 Unknown symbol
  pc 0x00007f25a5adee8d fp 0x00007f25b90fe0e8 Unknown symbol
  pc 0x00007f25b5a8cb11 fp 0x00007f25b90fe140 Unknown symbol
  pc 0x00007f25b5ae880b fp 0x00007f25b90fe178 Unknown symbol
  pc 0x00007f25b69cff91 fp 0x00007f25b90fe1f8 Unknown symbol
  pc 0x00007f25b5adc6d3 fp 0x00007f25b90fe250 Unknown symbol
  pc 0x00007f25b5adf624 fp 0x00007f25b90fe298 Unknown symbol
  pc 0x00007f25b69cedb8 fp 0x00007f25b90fe2d8 Unknown symbol
  pc 0x00007f25b69ce9fe fp 0x00007f25b90fe318 Unknown symbol
  pc 0x00007f25a5ae0e68 fp 0x00007f25b90fe350 Unknown symbol
  pc 0x00007f25b69d012d fp 0x00007f25b90fe390 Unknown symbol
  pc 0x00007f25b69a37ef fp 0x00007f25b90fe3f8 Unknown symbol
  pc 0x00007f25b69a3063 fp 0x00007f25b90fe448 Unknown symbol
  pc 0x00007f25bb582a0c fp 0x00007f25b90fe4c0 Unknown symbol
  pc 0x00005585d010543d fp 0x00007f25b90fe560 dart::DartEntry::InvokeCode(dart::Code const&, unsigned long, dart::Array const&, dart::Array const&, dart::Thread*)+0x14d
  pc 0x00005585d010527c fp 0x00007f25b90fe5c0 dart::DartEntry::InvokeFunction(dart::Function const&, dart::Array const&, dart::Array const&, unsigned long)+0x14c
  pc 0x00005585d01076ac fp 0x00007f25b90fe610 dart::DartLibraryCalls::HandleMessage(long, dart::Instance const&)+0x14c
  pc 0x00005585d012ed70 fp 0x00007f25b90feba0 dart::IsolateMessageHandler::HandleMessage(std::__2::unique_ptr<dart::Message, std::__2::default_delete<dart::Message> >)+0x350
  pc 0x00005585d015829d fp 0x00007f25b90fec10 dart::MessageHandler::HandleMessages(dart::MonitorLocker*, bool, bool)+0x14d

  pc 0x00005585d015897f fp 0x00007f25b90fec60 dart::MessageHandler::TaskCallback()+0x1df
  pc 0x00005585d027b3b8 fp 0x00007f25b90fece0 dart::ThreadPool::WorkerLoop(dart::ThreadPool::Worker*)+0x148
  pc 0x00005585d027b80d fp 0x00007f25b90fed10 dart::ThreadPool::Worker::Main(unsigned long)+0x6d

  pc 0x00005585d01ee458 fp 0x00007f25b90fedd0 /usr/lib/dart/bin/dart+0x2163458
-- End of DumpStackTrace
Aborted (core dumped)
Exited (134)

@Cat-sushi
Copy link
Author

Cat-sushi commented Nov 12, 2022

I publish my repository for reproduction.
https://github.com/Cat-sushi/fmatch

Run the sample stand alone batch with input database/list.csv instead of batch/queries.csv

dart bin/batchp.dart -i database/list.csv

@mraleph
Copy link
Member

mraleph commented Nov 14, 2022

@Cat-sushi could you change the license from AGPL to something else (e.g. GPL, MIT, BSD are all fine)? There are under some restrictions around AGPL which means we can't run your code. Thanks.

@Cat-sushi
Copy link
Author

You can use https://github.com/Cat-sushi/fmatch freely for reproduce this issue.
This message is the another license.

@Cat-sushi
Copy link
Author

By the way, AGPL is not restrictive unless you want to redistribute or serve it.

@mraleph
Copy link
Member

mraleph commented Nov 14, 2022

By the way, AGPL is not restrictive unless you want to redistribute or serve it.

This might be true. The only thing I am saying is that we have internal rules which limit what kind of code we can look at. I did not invent these rules, but we just have to follow them. tldr version of these rules is: if somebody shares with us the reproduction it needs to be licensed under one of the allowed open-source licenses, if that's the case we can just go ahead and look at the code. Everything else is more complicated, and requires us to mail somebody and ask if its okay or not.

@Cat-sushi
Copy link
Author

I think the rule doesn't mention internal use at Google.

@Cat-sushi
Copy link
Author

Anyway, #50082 (comment) is the second license.

@Cat-sushi
Copy link
Author

Do I have something to do?

@aam
Copy link
Contributor

aam commented Nov 29, 2022

We seem to be confused with large regexs that are used by the app, so that (for example) code_reg register(r12 on x64) is being end up used for generated irregexp internal use, causes crashes when it is attempted to use as code_reg on function entry(for invocation count check) after being jumped there via indirect goto from inside of that function. Potentially this points to broken indirect goto target calculation as we seem to be jumping to zero offset.

Running repro with --interpret_irregexp: dart --interpret_irregexp bin/batchp.dart -i database/list.csv no longer crashes.

@Cat-sushi
Copy link
Author

With --interpret_irregexp, it works in non-debugging mode, but fails in debugging mode.

Connecting to VM Service at http://127.0.0.1:42351/0XLC286r2wc=/
Start Parallel Batch
IDb.read : 3305
Db.fromIDb : 421
Unhandled exception:
IsolateSpawnException: Unable to spawn isolate: Failed to deserialize the passed arguments to the new isolate.
Exited (255)

@Cat-sushi
Copy link
Author

_AssertionError._doThrowNew (dart:core-patch/errors_patch.dart:51)
_AssertionError._throwNew (dart:core-patch/errors_patch.dart:40)
_LinkedHashMapMixin._regenerateIndex (dart:collection-patch/compact_hash.dart:441)
_rehashObjects (dart:collection-patch/compact_hash.dart:15)

@aam
Copy link
Contributor

aam commented Nov 30, 2022

With --interpret_irregexp, it works in non-debugging mode, but fails in debugging mode.

Are you still using dart --interpret_irregexp bin/batchp.dart -i database/list.csv from https://github.com/Cat-sushi/fmatch to repro the failure? When you say non-debugging mode vs debugging mode do you mean addition of --observe flag or something else? Command lines that you use would help.

Connecting to VM Service at http://127.0.0.1:42351/0XLC286r2wc=/
Start Parallel Batch
IDb.read : 3305
Db.fromIDb : 421
Unhandled exception:
IsolateSpawnException: Unable to spawn isolate: Failed to deserialize the passed arguments to the new isolate.
Exited (255)

Can you get on latest dev build of dart sdk https://dart.dev/get-dart/archive to simplify troubleshooting?

--interpret_irregexp only affects JIT configurations(default configuration for command-line dart, flutter "debug" configuration), doesn't affect AOT configuration(https://dart.dev/tools/dart-compile, flutter "release"/"profile" configuration) as it is the only supported mode of regex evaluation.

Also experiments with --interpret_irregexp here are just to pinpoint potential root cause of the failures, not to make you run your app in JIT configuration with that flag.

@aam
Copy link
Contributor

aam commented Nov 30, 2022

smaller repro for "the RegExp used by many isolates" dart vm crash

import 'dart:isolate';

worker(List<dynamic> args) {
  final re = args[0] as RegExp;
  final i = args[1] as int;
  print('worker $i');
  final sendPort = args[2] as SendPort;
  sendPort.send(re.firstMatch('h' * i * 1000));
}

main() {
  int nWorkers = 1000;
  final r = RegExp(r'(?<=\W|\b|^)(a.? b c.?) ?(\(.*\))?$');
  final rps = List<ReceivePort>.generate(nWorkers, (_) => ReceivePort());

  for (int i = 0; i < nWorkers; i++) {
    Isolate.spawn(worker, <dynamic>[r, i, rps[i].sendPort]);
  }

  Future.wait(List<Future<dynamic>>.generate(nWorkers, (i) => rps[i].first))
      .whenComplete(() { rps.forEach((rp) => rp.close()); });
}

@Cat-sushi
Copy link
Author

Are you still using dart --interpret_irregexp bin/batchp.dart -i database/list.csv from https://github.com/Cat-sushi/fmatch to repro the failure?

yes

When you say non-debugging mode vs debugging mode do you mean addition of --observe flag or something else?

I'm not sure, but I use VSCode.

Can you get on latest dev build of dart sdk https://dart.dev/get-dart/archive to simplify troubleshooting?

I already use newest version.

2.18.5 (stable) (Unknown timestamp) on "linux_x64"

@aam
Copy link
Contributor

aam commented Dec 2, 2022

https://dart-review.googlesource.com/c/sdk/+/273480 solves the crash by copying rather than sharing RegExp between isolates, forcing new irregexp code generated for every isolate. There seem to be different approach possible where backtracking stack and register stack would be static fields on the RegExp class, rather that entries in generated code object pool.

cc @mkustermann @rmacnak-google

copybara-service bot pushed a commit that referenced this issue Dec 2, 2022
RegExp code objects keep backtracking and registers stacks in object pools, can't be shared between isolates.

BUG=#50082
TEST=one_regexp_many_workers

Change-Id: Ic7db8d7a75a0951178b2f4800f96224d52506545
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/273480
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Alexander Aprelev <aam@google.com>
@mkustermann
Copy link
Member

@aam Thanks for the fix!

There seem to be different approach possible where backtracking stack and register stack would be static fields on the
RegExp class, rather that entries in generated code object pool.

I think that would be highly preferred. It is strongly desirable to share all JITed code, since this can make newly spawned isolates slow to start (if they have to re-compile same RegExp over and over again).

@aam Would this something you want to tackle?

@Cat-sushi
Copy link
Author

I prefere 2 steps modification.
Step 1: Fix the bug with the current commit.
Step 2: Optimize it.

@aam
Copy link
Contributor

aam commented Dec 6, 2022

I created follow-up issue to improve performance of RegExp passing. Closing this one as commit 4275d59 should fix the crash.

@aam aam closed this as completed Dec 6, 2022
@Cat-sushi
Copy link
Author

Thank you very much.

By the way, when can I have the fixed SDK?

@Cat-sushi
Copy link
Author

With 2.19.0 an unhandled exception is thrown.

Dart SDK version: 2.19.0 (stable) (Unknown timestamp) on "linux_x64"

Unhandled exception:
IsolateSpawnException: Unable to spawn isolate: Failed to deserialize the passed arguments to the new isolate.

@aam
Copy link
Contributor

aam commented Jan 25, 2023

Given when it landed, the fix is only available on the main flutter channel. It has not been cherry-picked to neither stable or beta flutter channels.

@Cat-sushi
Copy link
Author

I reported this issue for 2.18.2 (stable), and now I use 2.19.0 (stable).
So, I think this is not cherry-picking thing.

@aam
Copy link
Contributor

aam commented Jan 25, 2023

I reported this issue for 2.18.2 (stable), and now I use 2.19.0 (stable).

The fix landed into the dev/main branches after beta and stable were branched out from there, so it was not included there.

@Cat-sushi
Copy link
Author

This bug is 1+ year old, and this reported issue is almost 4 month old.

@aam
Copy link
Contributor

aam commented Jan 25, 2023

This bug is 1+ year old, and this reported issue is almost 4 month old.

I'm sorry it took that long to get to the bottom of the issue, I will see what options there might be regarding cherry-picking this as a hotfix for released versions.

copybara-service bot pushed a commit that referenced this issue Jan 30, 2023
…isolates.

There are two commits being picked up as one cherry-pick:
 - first one disables sharing to fix a crash dartbug.com/50082, regressing performance of sending regexs between isolates.
 - second one reenables sharing, restores performance of sending regexs, fixes dartbug.com/50639.

Bug: #50082
Bug: #50639
Change-Id: I8aacebef5da66957c85c57748b7dcbd4e6f0f750
TEST=ci
Cherry-pick: https://dart-review.googlesource.com/c/sdk/+/276240
Cherry-pick: https://dart-review.googlesource.com/c/sdk/+/273480
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/279747
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Siva Annamalai <asiva@google.com>
Commit-Queue: Alexander Aprelev <aam@google.com>
@Cat-sushi
Copy link
Author

Is this another issue to be posted?

Dart SDK version: 3.0.0-179.0.dev (dev) (Unknown timestamp) on "linux_x64"

Connecting to VM Service at http://127.0.0.1:33823/qkrWrcyjLfs=/
IDb.read : 3781
Db.fromIDb : 373
Unhandled exception:
IsolateSpawnException: Unable to spawn isolate: Failed to deserialize the passed arguments to the new isolate.
Exited (255)
_AssertionError._doThrowNew (dart:core-patch/errors_patch.dart:51)
_AssertionError._throwNew (dart:core-patch/errors_patch.dart:40)
_LinkedHashMapMixin._regenerateIndex (dart:collection-patch/compact_hash.dart:449)
_rehashObjects (dart:collection-patch/compact_hash.dart:21)

@mkustermann
Copy link
Member

@Cat-sushi This is a different issue. When sending maps/sets across isolates, they get copied and may require re-hashing. This is assertion assumes that the copied maps have't been already re-hashed (which they shouldn't, since they are new copies). Thanks for filing #51226

@Cat-sushi
Copy link
Author

I confirmed the RegExp issue fixed at 2.19.1.
Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. P2 A bug or feature request we're likely to work on
Projects
None yet
Development

No branches or pull requests

6 participants