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:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user