Open abitofevrything opened 3 days ago
Summary: Synchronous dart:io
functions don't release the isolate group, causing hangs when many isolates use them concurrently. The issue persists despite Dart_EnterIsolate
/Dart_ExitIsolate
being public.
Maybe the overhead of entering/exiting the isolate isn't worth it for some very quick calls - but I can definitely see it being useful on longer calls (notably Process.runSync, which is where we noticed this issue).
This issue is in spirit a continuation of #51254; I'm just picking up where that issue left off.
I would have assumed that since that issue was closed and
Dart_EnterIsolate
/Dart_ExitIsolate
are now part of the public API,dart:io
's sync functions would have been updated to call these methods themselves. However this doesn't seem to be the case, and calling sync functions in many isolates at once can still cause an isolate group to hang.Example:
I would expect these functions to call
Dart_ExitIsolate
(or some internal equivalent) before running the blocking call (whether it bepoll
in the case ofProcess.runSync
,sleep
in the case ofsleep
or any other blocking native call) in order to allow other isolates in the isolate group to run. Maybe this could also be done when calling into FFIisLeaf: true
calls?I don't know of any other blocking functions in the SDK other than
dart:io
's, but if there are some it goes without saying the same should be done there.Tested on dart version
3.7.0-132.0.dev
and 73adec7b6f6d544b6b58752922f3b5938ad463e9