Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sanitize output and chunk it at DATA_UPLOAD_MAX_MEMORY_SIZE #4982

Merged
merged 2 commits into from
Dec 11, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions readthedocs/doc_builder/environments.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
absolute_import, division, print_function, unicode_literals)

import logging
import json
import os
import re
import socket
Expand Down Expand Up @@ -186,6 +187,9 @@ def sanitize_output(self, output):
avoid PostgreSQL db to fail:
https://code.djangoproject.com/ticket/28201

3. Chunk at around ``DATA_UPLOAD_MAX_MEMORY_SIZE`` bytes to be sent
over the API call request

:param output: stdout/stderr to be sanitized
:type output: bytes

Expand All @@ -198,6 +202,25 @@ def sanitize_output(self, output):
sanitized = sanitized.replace('\x00', '')
except (TypeError, AttributeError):
sanitized = None

# Chunk the output data to be less than ``DATA_UPLOAD_MAX_MEMORY_SIZE``
output_length = len(output) if output else 0
# Left some extra space for the rest of the request data
threshold = 512 * 1024 # 512Kb
allowed_length = settings.DATA_UPLOAD_MAX_MEMORY_SIZE - threshold
if output_length > allowed_length:
log.info(
'Command output is too big: project=[%s] version=[%s] build=[%s] command=[%s]', # noqa
self.build_env.project.slug,
self.build_env.version.slug,
self.build_env.build.get('id'),
self.get_command(),
)
sanitized = sanitized[:allowed_length]
sanitized += '\n\n\nOutput is too big. Chunked at {} bytes'.format(
allowed_length,
)

return sanitized

def get_command(self):
Expand Down