diff --git a/readthedocs/doc_builder/environments.py b/readthedocs/doc_builder/environments.py index d453c895448..e6833e881f4 100644 --- a/readthedocs/doc_builder/environments.py +++ b/readthedocs/doc_builder/environments.py @@ -224,9 +224,12 @@ def run(self): self.exit_code = cmd_ret['ExitCode'] # Docker will exit with a special exit code to signify the command - # was killed due to memory usage, make the error code nicer. - if (self.exit_code == DOCKER_OOM_EXIT_CODE and - self.output == 'Killed\n'): + # was killed due to memory usage, make the error code + # nicer. Sometimes the kernel kills the command and Docker doesn't + # not use the specific exit code, so we check if the word `Killed` + # is in the last 15 lines of the command's output + killed_in_output = 'Killed' in '\n'.join(self.output.splitlines()[-15:]) + if self.exit_code == DOCKER_OOM_EXIT_CODE or (self.exit_code == 1 and killed_in_output): self.output = _('Command killed due to excessive memory ' 'consumption\n') except DockerAPIError: