From 3a745860c2ced8f7c0af034f30a0e2c2e458ceb2 Mon Sep 17 00:00:00 2001 From: Nurhan Turgut Date: Fri, 17 Apr 2020 17:55:52 -0700 Subject: [PATCH] [web] fix ulimit issues on Mac (flutter/engine#17767) * check the max user limit before changing the limits * more detailed changes in the file/user limit increase * addressing pr reviews --- engine/src/flutter/lib/web_ui/dev/felt | 40 ++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/engine/src/flutter/lib/web_ui/dev/felt b/engine/src/flutter/lib/web_ui/dev/felt index 56b031ce0b..46d75c3a99 100755 --- a/engine/src/flutter/lib/web_ui/dev/felt +++ b/engine/src/flutter/lib/web_ui/dev/felt @@ -56,9 +56,43 @@ install_deps() { KERNEL_NAME=`uname` if [[ $KERNEL_NAME == *"Darwin"* ]] then - echo "Running on MacOS. Increase the user limits" - ulimit -n 50000 - ulimit -u 4096 + echo "Running on MacOS. Will check the file and user limits." + # Disable exit if the commands fails. We want to give more actionable + # error message. + set +e + ULIMIT_FILES=`ulimit -n` + # Increase the file limit if it is low. Note that these limits are changed + # only for this script (for this shell). After felt execution is completed + # no change is required to reset the original shell. + if [[ $ULIMIT_FILES < 50000 ]] + then + echo "File limits too low increasing the file limits" + # Get the max file limit. + MAX_ULIMIT_FILES=`launchctl limit maxfiles | sed -e 's/^[[:space:]]*//' | sed 's/ \{1,\}/ /g' | cut -d' ' -f2` + if [[ $MAX_ULIMIT_FILES < 50000 ]] + then + # Increase the maximum file limit. + sudo launchctl limit maxfiles 50000 200000 + fi + ERROR=$(ulimit -n 50000 2>&1 >/dev/null) + if [[ ! -z $ERROR ]] + then + echo "Problem changing the file limit. Please try to reboot to use the higher limits. error: \n$ERROR" 1>&2 + fi + fi + ULIMIT_USER=`ulimit -u` + # Increase the hard user limit if it is lower than 2048. + if [[ $ULIMIT_USER < 4096 ]] + then + echo "User limits too low increasing the user limits" + ERROR2=$(ulimit -u 4096 2>&1 >/dev/null) + if [[ ! -z $ERROR2 ]] + then + echo "Problem changing the user limit. Please try to reboot to use the higher limits. error: \n$ERROR2" 1>&2 + fi + fi + # Set the value back to exit on non zero results. + set -e fi if [[ "$FELT_USE_SNAPSHOT" == "false" || "$FELT_USE_SNAPSHOT" == "0" ]]; then