also raise 400 errors when we can't read the client upload stream

This commit is contained in:
Mike McLean 2022-03-01 17:57:07 -05:00 committed by Tomas Kopecek
parent 37b108bf24
commit f89794ce07
3 changed files with 21 additions and 10 deletions

View file

@ -62,6 +62,7 @@ from koji.tasks import parse_task_params
import koji.xmlrpcplus
from koji.context import context
from koji.daemon import SCM
from koji.server import BadRequest, RequestTimeout
from koji.util import (
base64encode,
decode_bytes,
@ -15361,7 +15362,17 @@ def handle_upload(environ):
os.ftruncate(fd, offset)
os.lseek(fd, offset, 0)
while True:
chunk = inf.read(65536)
try:
chunk = inf.read(65536)
except OSError as e:
str_e = str(e)
logger.error(f"Error reading upload. Offset {offset}+{size}, path {fn}")
if 'timeout' in str_e:
logger.exception("Timed out reading input stream")
raise RequestTimeout(str_e)
else:
logger.exception("Error reading input stream")
raise BadRequest(str_e)
if not chunk:
break
size += len(chunk)

View file

@ -38,18 +38,10 @@ import koji.policy
import koji.util
from koji.context import context
# import xmlrpclib functions from koji to use tweaked Marshaller
from koji.server import ServerError
from koji.server import ServerError, BadRequest, RequestTimeout
from koji.xmlrpcplus import ExtendedMarshaller, Fault, dumps, getparser
class BadRequest(ServerError):
"""Used to trigger an http 400 error"""
class RequestTimeout(ServerError):
"""Used to trigger an http 408 error"""
class Marshaller(ExtendedMarshaller):
dispatch = ExtendedMarshaller.dispatch.copy()

View file

@ -26,3 +26,11 @@ class ServerError(Exception):
class ServerRedirect(ServerError):
"""Used to handle redirects"""
class BadRequest(ServerError):
"""Used to trigger an http 400 error"""
class RequestTimeout(ServerError):
"""Used to trigger an http 408 error"""