handle EAGAIN (macOS) in ErrorHandlingProcessManager (#154306)

~~Fixes~~ Discovered in https://github.com/flutter/flutter/issues/153776.

To my knowledge, `Resource temporarily unavailable` when trying to run a process means that some required resource is at capacity. There may be too many processes active, not enough available ports, or some sort of blocking cache is full, etc. Feel free to independently research and see if you come to the same conclusion.

Then, it seems safe to catch and handle this within the tool's `ErrorHandlingProcessManager` abstraction, as Flutter cannot realistically do anything to prevent this issue.
This commit is contained in:
Andrew Kolos
2024-09-10 15:24:56 -07:00
committed by GitHub
parent 93d06ebd6c
commit 30835d7dac
2 changed files with 31 additions and 0 deletions

View File

@@ -777,6 +777,7 @@ void _handlePosixException(Exception e, String? message, int errorCode, String?
void _handleMacOSException(Exception e, String? message, int errorCode, String? posixPermissionSuggestion) {
// https://github.com/apple/darwin-xnu/blob/main/bsd/dev/dtrace/scripts/errno.d
const int ebadarch = 86;
const int eagain = 35;
if (errorCode == ebadarch) {
final StringBuffer errorBuffer = StringBuffer();
if (message != null) {
@@ -787,6 +788,17 @@ void _handleMacOSException(Exception e, String? message, int errorCode, String?
errorBuffer.writeln(' sudo softwareupdate --install-rosetta --agree-to-license');
_throwFileSystemException(errorBuffer.toString());
}
if (errorCode == eagain) {
final StringBuffer errorBuffer = StringBuffer();
if (message != null) {
errorBuffer.writeln('$message.');
}
errorBuffer.writeln(
'Your system may be running into its process limits. '
'Consider quitting unused apps and trying again.',
);
throwToolExit(errorBuffer.toString());
}
_handlePosixException(e, message, errorCode, posixPermissionSuggestion);
}

View File

@@ -1108,6 +1108,7 @@ Please ensure that the SDK and/or project is installed in a location that has re
const int enospc = 28;
const int eacces = 13;
const int ebadarch = 86;
const int eagain = 35;
testWithoutContext('when writing to a full device', () {
final FakeProcessManager fakeProcessManager = FakeProcessManager.list(<FakeCommand>[
@@ -1190,6 +1191,24 @@ Please ensure that the SDK and/or project is installed in a location that has re
expect(() => processManager.runSync(<String>['foo', '--bar']),
throwsToolExit(message: expectedMessage));
});
testWithoutContext('when up against resource limits (EAGAIN)', () async {
final FakeProcessManager fakeProcessManager = FakeProcessManager.list(<FakeCommand>[
const FakeCommand(command: <String>['foo', '--bar'], exception: ProcessException('', <String>[], '', eagain)),
]);
final ProcessManager processManager = ErrorHandlingProcessManager(
delegate: fakeProcessManager,
platform: macOSPlatform,
);
const String expectedMessage = 'Flutter failed to run "foo --bar".\n'
'Your system may be running into its process limits. '
'Consider quitting unused apps and trying again.';
expect(() async => processManager.start(<String>['foo', '--bar']),
throwsToolExit(message: expectedMessage));
});
});
testWithoutContext('ErrorHandlingProcessManager delegates killPid correctly', () async {