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

[MRG+1] Change DOWNLOAD_MAXSIZE logger level from Error to Warning #3886

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
21 changes: 11 additions & 10 deletions scrapy/core/downloader/handlers/http11.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,13 +379,14 @@ def _cb_bodyready(self, txresponse, request):
fail_on_dataloss = request.meta.get('download_fail_on_dataloss', self._fail_on_dataloss)

if maxsize and expected_size > maxsize:
error_msg = ("Cancelling download of %(url)s: expected response "
"size (%(size)s) larger than download max size (%(maxsize)s).")
error_args = {'url': request.url, 'size': expected_size, 'maxsize': maxsize}
warning_msg = ("Expected response size (%(size)s) larger than "
Copy link
Member

@kmike kmike Jan 23, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think previous error message made more sense, because now we're getting two almost identical messages for warnsize and maxsize - there is no indication that response is dropped here.

"download max size (%(maxsize)s) in request %(request)s.")
warning_args = {'request': request, 'size': expected_size, 'maxsize': maxsize}

logger.warning(warning_msg, warning_args)

logger.error(error_msg, error_args)
txresponse._transport._producer.loseConnection()
raise defer.CancelledError(error_msg % error_args)
Gallaecio marked this conversation as resolved.
Show resolved Hide resolved
raise defer.CancelledError(warning_msg % warning_args)

if warnsize and expected_size > warnsize:
logger.warning("Expected response size (%(size)s) larger than "
Expand Down Expand Up @@ -455,11 +456,11 @@ def dataReceived(self, bodyBytes):
self._bytes_received += len(bodyBytes)

if self._maxsize and self._bytes_received > self._maxsize:
logger.error("Received (%(bytes)s) bytes larger than download "
"max size (%(maxsize)s) in request %(request)s.",
{'bytes': self._bytes_received,
'maxsize': self._maxsize,
'request': self._request})
logger.warning("Received (%(bytes)s) bytes larger than download "
"max size (%(maxsize)s) in request %(request)s.",
{'bytes': self._bytes_received,
'maxsize': self._maxsize,
'request': self._request})
# Clear buffer earlier to avoid keeping data in memory for a long time.
self._bodybuf.truncate(0)
self._finished.cancel()
Expand Down
2 changes: 1 addition & 1 deletion tests/test_downloader_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ def test_download_with_maxsize_very_large_file(self):
request = Request(self.getURL('largechunkedfile'))

def check(logger):
logger.error.assert_called_once_with(mock.ANY, mock.ANY)
logger.warning.assert_called_once_with(mock.ANY, mock.ANY)

d = self.download_request(request, Spider('foo', download_maxsize=1500))
yield self.assertFailure(d, defer.CancelledError, error.ConnectionAborted)
Expand Down