Search code examples
angularangular-clibamboobuild-error

Atlasian Elastic Bamboo build error: Too many open files error for Angular CLI build


When I'm building my Angular-CLI project on Bamboo I'm getting the following error:

Error: EMFILE: too many open files, open '<file...>'
EMFILE: too many open files, open '<file...>'

I'm running elastic Bamboo on AWS EC2 linux instances. I've looked at Atlassian's support forum but they only gave general guidelines to solve the problem not how to actually add the fix to an existing bamboo setup that uses AWS EC2 instances.


Solution

  • In your Angular CLI project, under your .angular-cli.json (cli v1.x.x) or angular.json (cli v6.x.x+) under assets you've probably added a folder that contains a lot of files. When angular cli builds the project, the files are copied over to the build folder which is the main culprit for the error since the process hit the limit to the amount of files that can opened and copied over at the system level.

    To solve this you'll just need to update your AWS EC2 image config in the bamboo admin menu to include the fix described in the support forum.

    1. Log into your bamboo website as root/ admin user
    2. Click the gear (settings) icon in the top right menu next
    3. Click Overview
    4. Left hand menu under ELASTIC BAMBOO, click Image configurations
    5. In the list of configurations, find the configuration that is used to create your bamboo worker instance for that particular build, you might need to contact your system admin/ infrastructure guy to figure this out but it's usually the only one that is enabled/ not greyed out. Click edit for that particular configuration row.
    6. Scroll down to the Instance startup script text-field
    7. Add the following lines to the bottom of the script list

      #increase open file limit
      sudo echo "*           soft    nofile          40000" >> /etc/security/limits.conf
      sudo echo "*           hard    nofile          40000" >> /etc/security/limits.conf
      

      Please note * is to indicate any user but to be more specific you can replace it with Bamboo_USER

    8. Click Save

    9. Left hand menu under ELASTIC BAMBOO, click Instances
    10. Top right area, click Terminate all instances to remove any instances with the old script, please make sure you're not building anything at the time of termination as the builds will be interrupted and fail.
    11. Now you should be able to start your build again and the problem should be resolved, you may have to restart your bamboo instance once for scripts to take affect.