﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
28968	LiveServerTestCase prematurely closing HttpResponse with Django 2.0	Alexander Todorov	nobody	"I'm trying to migrate an existing project to Django 2.0 and I'm hitting a problem with some of our tests, all of the problematic tests are very similar in nature:

1) They are all LiveServerTestCase based
2) All of them have a XML-RPC client which issues requests to the Django app
3) Using django-modern-rpc the application under test is able to execute a function and return a result
3) All error out on the first request (most of the times) with traceback from the xmlrpc client module in Python telling me that that connection has been closed without a response. 

Here are the few data points I was able to collect:

* Locally happens on both MySQL and SQLite but on SQLite less frequently, looks like a race condition. In Travis CI happens on SQLite but not on MySQL so go figure!
* with a local MySQL instance I'm able to reproduce all the times
* the root-cause seems to be in wsgiref.handlers.py::BaseHandler.run() which calls finish_response() which executes HttpResponse.close(). In run() there's also a comment about async servers and that they should not call .close() inside .finish_response()

* if I modify Django's basehttp.py::ServerHandler.http_version to '1.0' all tests seem to pass regardless if we use a multi-threaded or single-threaded LiveServer!

* This is on Python 3.5, RHEL 7 system.


So it looks like the problem is with ServerHandler (presumably tests) wanting to use HTTP 1.1 but I can't narrow it down firther ATM.


To reproduce you may checkout the code at https://github.com/kiwitcms/Kiwi;
pip install -r requirements/devel.txt; pip install --upgrade Django and 

./manage.py test --noinput  --settings=tcms.settings.test.mysql tcms.xmlrpc.tests.test_logging.TestXMLRPCLogging.test_logging_with_authenticated_user


"	Bug	closed	HTTP handling	2.0	Normal	invalid		Tom Forbes	Unreviewed	0	0	0	0	0	0
