Repository: oppia/oppia

Issue:
Investigate 137 error in backend tests
Currently we have the following tests that sometimes exits with a 137 error (see stacktrace below). 137 is a stack overflow error that is a result from the following exit codes: 128 (stack overflow) + 9 (SIGKILL). This issue was created to keep track this error and take action if there are enough cases. 

```
======================================================================
ERROR: test_build_with_prod_env (scripts.build_test.BuildTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/circleci/oppia/scripts/build_test.py", line 838, in test_build_with_prod_env
    build.build()
  File "/home/circleci/oppia/scripts/build.py", line 1333, in build
    minify_third_party_libs(THIRD_PARTY_GENERATED_DEV_DIR)
  File "/home/circleci/oppia/scripts/build.py", line 542, in minify_third_party_libs
    _minify(THIRD_PARTY_CSS_FILEPATH, MINIFIED_THIRD_PARTY_CSS_FILEPATH)
  File "/home/circleci/oppia/scripts/build.py", line 183, in _minify
    subprocess.check_call(cmd, shell=True)
  File "/usr/local/lib/python2.7/subprocess.py", line 186, in check_call
    raise CalledProcessError(retcode, cmd)
CalledProcessError: Command 'java -jar ../oppia_tools/yuicompressor-2.4.8/yuicompressor-2.4.8.jar third_party/generated/css/third_party.css -o third_party/generated/css/third_party.min.css' returned non-zero exit status 137

======================================================================
ERROR: test_minify_third_party_libs (scripts.build_test.BuildTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/circleci/oppia/scripts/build_test.py", line 782, in test_minify_third_party_libs
    build.minify_third_party_libs('core/tests/data/third_party')
  File "/home/circleci/oppia/scripts/build.py", line 542, in minify_third_party_libs
    _minify(THIRD_PARTY_CSS_FILEPATH, MINIFIED_THIRD_PARTY_CSS_FILEPATH)
  File "/home/circleci/oppia/scripts/build.py", line 183, in _minify
    subprocess.check_call(cmd, shell=True)
  File "/usr/local/lib/python2.7/subprocess.py", line 186, in check_call
    raise CalledProcessError(retcode, cmd)
CalledProcessError: Command 'java -jar ../oppia_tools/yuicompressor-2.4.8/yuicompressor-2.4.8.jar core/tests/data/third_party/css/third_party.css -o core/tests/data/third_party/css/third_party.min.css' returned non-zero exit status 137

---------------------------------------------------------------------
```

**Resources:**
- https://circleci.com/blog/how-to-handle-java-oom-errors/
Investigate 137 error in backend tests
Currently we have the following tests that sometimes exits with a 137 error (see stacktrace below). 137 is a stack overflow error that is a result from the following exit codes: 128 (stack overflow) + 9 (SIGKILL). This issue was created to keep track this error and take action if there are enough cases. 

```
======================================================================
ERROR: test_build_with_prod_env (scripts.build_test.BuildTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/circleci/oppia/scripts/build_test.py", line 838, in test_build_with_prod_env
    build.build()
  File "/home/circleci/oppia/scripts/build.py", line 1333, in build
    minify_third_party_libs(THIRD_PARTY_GENERATED_DEV_DIR)
  File "/home/circleci/oppia/scripts/build.py", line 542, in minify_third_party_libs
    _minify(THIRD_PARTY_CSS_FILEPATH, MINIFIED_THIRD_PARTY_CSS_FILEPATH)
  File "/home/circleci/oppia/scripts/build.py", line 183, in _minify
    subprocess.check_call(cmd, shell=True)
  File "/usr/local/lib/python2.7/subprocess.py", line 186, in check_call
    raise CalledProcessError(retcode, cmd)
CalledProcessError: Command 'java -jar ../oppia_tools/yuicompressor-2.4.8/yuicompressor-2.4.8.jar third_party/generated/css/third_party.css -o third_party/generated/css/third_party.min.css' returned non-zero exit status 137

======================================================================
ERROR: test_minify_third_party_libs (scripts.build_test.BuildTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/circleci/oppia/scripts/build_test.py", line 782, in test_minify_third_party_libs
    build.minify_third_party_libs('core/tests/data/third_party')
  File "/home/circleci/oppia/scripts/build.py", line 542, in minify_third_party_libs
    _minify(THIRD_PARTY_CSS_FILEPATH, MINIFIED_THIRD_PARTY_CSS_FILEPATH)
  File "/home/circleci/oppia/scripts/build.py", line 183, in _minify
    subprocess.check_call(cmd, shell=True)
  File "/usr/local/lib/python2.7/subprocess.py", line 186, in check_call
    raise CalledProcessError(retcode, cmd)
CalledProcessError: Command 'java -jar ../oppia_tools/yuicompressor-2.4.8/yuicompressor-2.4.8.jar core/tests/data/third_party/css/third_party.css -o core/tests/data/third_party/css/third_party.min.css' returned non-zero exit status 137

---------------------------------------------------------------------
```

**Resources:**
- https://circleci.com/blog/how-to-handle-java-oom-errors/


Discussion:
/cc @sophiewu6 

NB I think we might want to go ahead and take action, since there are already two cases.
/cc @sophiewu6 

NB I think we might want to go ahead and take action, since there are already two cases.

Resolving patch:
diff --git a/scripts/build.py b/scripts/build.py
--- a/scripts/build.py
+++ b/scripts/build.py
@@ -178,8 +178,13 @@ def _minify(source_path, target_path):
         target_path: str. Absolute path to location where to copy
             the minified file.
     """
-    cmd = 'java -jar %s %s -o %s' % (
-        YUICOMPRESSOR_DIR, source_path, target_path)
+    # The -Xmxn argument is an attempt to limit the max memory used when the
+    # minification process is running on CircleCI. Note that, from local
+    # experiments, 18m seems to work, but 12m is too small and results in an
+    # out-of-memory error.
+    # https://circleci.com/blog/how-to-handle-java-oom-errors/
+    cmd = 'java -Xmx24m -jar %s -o %s %s' % (
+        YUICOMPRESSOR_DIR, target_path, source_path)
     subprocess.check_call(cmd, shell=True)
 
 


Test patch: