Skip to content

Commit d6eac0e

Browse files
humitosagjohnson
authored andcommitted
Extra way to check OOM of a command ran inside Docker (readthedocs#3294)
* Extra way to check OOM of a command ran inside Docker Easy way to reproduce this error: 1. Import a project that compiles lxml (Read the Docs, for example) 2. The `pip` command will be killed and Docker won't return a specific status code, it will just return 1 3. In these cases, the `Killed` word will probably appear in the last 15 lines * Check status code and 'Killed' word
1 parent 2e39d5f commit d6eac0e

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

readthedocs/doc_builder/environments.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,9 +224,12 @@ def run(self):
224224
self.exit_code = cmd_ret['ExitCode']
225225

226226
# Docker will exit with a special exit code to signify the command
227-
# was killed due to memory usage, make the error code nicer.
228-
if (self.exit_code == DOCKER_OOM_EXIT_CODE and
229-
self.output == 'Killed\n'):
227+
# was killed due to memory usage, make the error code
228+
# nicer. Sometimes the kernel kills the command and Docker doesn't
229+
# not use the specific exit code, so we check if the word `Killed`
230+
# is in the last 15 lines of the command's output
231+
killed_in_output = 'Killed' in '\n'.join(self.output.splitlines()[-15:])
232+
if self.exit_code == DOCKER_OOM_EXIT_CODE or (self.exit_code == 1 and killed_in_output):
230233
self.output = _('Command killed due to excessive memory '
231234
'consumption\n')
232235
except DockerAPIError:

0 commit comments

Comments
 (0)