Django StaticLiveServerTestCase sometimes ends with: An existing connection was forcibly closed by the remote host
In an Django application that I freshly created, where I changed it to use PostgreSQL and I created one app, I have the following test:
from django.contrib.auth.models import User
from django.contrib.staticfiles.testing import StaticLiveServerTestCase
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
class TestWebBrowser(StaticLiveServerTestCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.webdriver = webdriver.Chrome()
cls.webdriver.implicitly_wait(10)
@classmethod
def tearDownClass(cls):
cls.webdriver.close()
cls.webdriver.quit()
super().tearDownClass()
def setUp(self):
self.admin = User.objects.create_superuser(username="username", password="password",
email="example@example.com")
def test_log_in(self):
self.webdriver.get(f"self.live_server_url/admin")
self.webdriver.find_element_by_id("id_username").send_keys("username")
self.webdriver.find_element_by_id("id_password").send_keys("password")
self.webdriver.find_element_by_id("id_password").send_keys(Keys.RETURN)
self.webdriver.find_element_by_link_text("Users").click()
The test always runs, Chrome starts, does what the test say, but at the end, sometimes it throws this error:
Exception happened during processing of request from ('127.0.0.1', 55283)
Traceback (most recent call last):
File "C:Userspupenoscoopappspythoncurrentlibsocketserver.py", line 647, in process_request_thread
self.finish_request(request, client_address)
File "C:Userspupenoscoopappspythoncurrentlibsocketserver.py", line 357, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "C:Userspupenoscoopappspythoncurrentlibsocketserver.py", line 717, in __init__
self.handle()
File "C:UserspupenoTemporaryuntitledvenvlibsite-packagesdjangocoreserversbasehttp.py", line 139, in handle
self.raw_requestline = self.rfile.readline(65537)
File "C:Userspupenoscoopappspythoncurrentlibsocket.py", line 589, in readinto
return self._sock.recv_into(b)
ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host
All tests pass. I just get that to STDERR. Any ideas why? Am I missing some tearing-down?
If I change tearDownClass to:
@classmethod
def tearDownClass(cls):
cls.webdriver.quit()
I get the same error with the same frequency (as far as I can observe, without having measured it).
I'm running:
Django==2.1.2
selenium==3.141.0
and
> chromedriver.exe --version
ChromeDriver 2.43.600210 (68dcf5eebde37173d4027fa8635e332711d2874a)
and
Google Chrome Version 70.0.3538.102 (Official Build) (64-bit)
The full output of running the tests look like this:
Testing started at 15:33 ...
C:UserspupenoTemporaryuntitledvenvScriptspython.exe "C:Program FilesJetBrainsPyCharm 2018.2.4helperspycharmdjango_test_manage.py" test foo.tests.TestImportCRMData C:UserspupenoTemporaryuntitled
Creating test database for alias 'default'...
System check identified no issues (0 silenced).
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 49825)
Traceback (most recent call last):
File "C:Userspupenoscoopappspythoncurrentlibsocketserver.py", line 647, in process_request_thread
self.finish_request(request, client_address)
File "C:Userspupenoscoopappspythoncurrentlibsocketserver.py", line 357, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "C:Userspupenoscoopappspythoncurrentlibsocketserver.py", line 717, in __init__
self.handle()
File "C:UserspupenoTemporaryuntitledvenvlibsite-packagesdjangocoreserversbasehttp.py", line 139, in handle
self.raw_requestline = self.rfile.readline(65537)
File "C:Userspupenoscoopappspythoncurrentlibsocket.py", line 589, in readinto
return self._sock.recv_into(b)
ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host
----------------------------------------
Destroying test database for alias 'default'...
Process finished with exit code 0
python django selenium
|
show 1 more comment
In an Django application that I freshly created, where I changed it to use PostgreSQL and I created one app, I have the following test:
from django.contrib.auth.models import User
from django.contrib.staticfiles.testing import StaticLiveServerTestCase
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
class TestWebBrowser(StaticLiveServerTestCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.webdriver = webdriver.Chrome()
cls.webdriver.implicitly_wait(10)
@classmethod
def tearDownClass(cls):
cls.webdriver.close()
cls.webdriver.quit()
super().tearDownClass()
def setUp(self):
self.admin = User.objects.create_superuser(username="username", password="password",
email="example@example.com")
def test_log_in(self):
self.webdriver.get(f"self.live_server_url/admin")
self.webdriver.find_element_by_id("id_username").send_keys("username")
self.webdriver.find_element_by_id("id_password").send_keys("password")
self.webdriver.find_element_by_id("id_password").send_keys(Keys.RETURN)
self.webdriver.find_element_by_link_text("Users").click()
The test always runs, Chrome starts, does what the test say, but at the end, sometimes it throws this error:
Exception happened during processing of request from ('127.0.0.1', 55283)
Traceback (most recent call last):
File "C:Userspupenoscoopappspythoncurrentlibsocketserver.py", line 647, in process_request_thread
self.finish_request(request, client_address)
File "C:Userspupenoscoopappspythoncurrentlibsocketserver.py", line 357, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "C:Userspupenoscoopappspythoncurrentlibsocketserver.py", line 717, in __init__
self.handle()
File "C:UserspupenoTemporaryuntitledvenvlibsite-packagesdjangocoreserversbasehttp.py", line 139, in handle
self.raw_requestline = self.rfile.readline(65537)
File "C:Userspupenoscoopappspythoncurrentlibsocket.py", line 589, in readinto
return self._sock.recv_into(b)
ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host
All tests pass. I just get that to STDERR. Any ideas why? Am I missing some tearing-down?
If I change tearDownClass to:
@classmethod
def tearDownClass(cls):
cls.webdriver.quit()
I get the same error with the same frequency (as far as I can observe, without having measured it).
I'm running:
Django==2.1.2
selenium==3.141.0
and
> chromedriver.exe --version
ChromeDriver 2.43.600210 (68dcf5eebde37173d4027fa8635e332711d2874a)
and
Google Chrome Version 70.0.3538.102 (Official Build) (64-bit)
The full output of running the tests look like this:
Testing started at 15:33 ...
C:UserspupenoTemporaryuntitledvenvScriptspython.exe "C:Program FilesJetBrainsPyCharm 2018.2.4helperspycharmdjango_test_manage.py" test foo.tests.TestImportCRMData C:UserspupenoTemporaryuntitled
Creating test database for alias 'default'...
System check identified no issues (0 silenced).
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 49825)
Traceback (most recent call last):
File "C:Userspupenoscoopappspythoncurrentlibsocketserver.py", line 647, in process_request_thread
self.finish_request(request, client_address)
File "C:Userspupenoscoopappspythoncurrentlibsocketserver.py", line 357, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "C:Userspupenoscoopappspythoncurrentlibsocketserver.py", line 717, in __init__
self.handle()
File "C:UserspupenoTemporaryuntitledvenvlibsite-packagesdjangocoreserversbasehttp.py", line 139, in handle
self.raw_requestline = self.rfile.readline(65537)
File "C:Userspupenoscoopappspythoncurrentlibsocket.py", line 589, in readinto
return self._sock.recv_into(b)
ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host
----------------------------------------
Destroying test database for alias 'default'...
Process finished with exit code 0
python django selenium
@DebanjanB: I don't think this is a duplicate question. The other one is about not managing to communicate with the chromedriver, while in my case that works. The error happens at the end.
– pupeno
Nov 15 '18 at 15:20
That's all the stack trace I'm getting. It must be happening on a separate thread.
– pupeno
Nov 15 '18 at 15:29
Can you help me to identify exactly at which line you are seeing the error?
– DebanjanB
Nov 15 '18 at 15:31
It doesn't happen on any line of my code. My tests all pass, and I just get that toSTDERRevery now and then.
– pupeno
Nov 15 '18 at 15:32
I'm guessing is something failing during tear down.
– pupeno
Nov 15 '18 at 15:33
|
show 1 more comment
In an Django application that I freshly created, where I changed it to use PostgreSQL and I created one app, I have the following test:
from django.contrib.auth.models import User
from django.contrib.staticfiles.testing import StaticLiveServerTestCase
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
class TestWebBrowser(StaticLiveServerTestCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.webdriver = webdriver.Chrome()
cls.webdriver.implicitly_wait(10)
@classmethod
def tearDownClass(cls):
cls.webdriver.close()
cls.webdriver.quit()
super().tearDownClass()
def setUp(self):
self.admin = User.objects.create_superuser(username="username", password="password",
email="example@example.com")
def test_log_in(self):
self.webdriver.get(f"self.live_server_url/admin")
self.webdriver.find_element_by_id("id_username").send_keys("username")
self.webdriver.find_element_by_id("id_password").send_keys("password")
self.webdriver.find_element_by_id("id_password").send_keys(Keys.RETURN)
self.webdriver.find_element_by_link_text("Users").click()
The test always runs, Chrome starts, does what the test say, but at the end, sometimes it throws this error:
Exception happened during processing of request from ('127.0.0.1', 55283)
Traceback (most recent call last):
File "C:Userspupenoscoopappspythoncurrentlibsocketserver.py", line 647, in process_request_thread
self.finish_request(request, client_address)
File "C:Userspupenoscoopappspythoncurrentlibsocketserver.py", line 357, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "C:Userspupenoscoopappspythoncurrentlibsocketserver.py", line 717, in __init__
self.handle()
File "C:UserspupenoTemporaryuntitledvenvlibsite-packagesdjangocoreserversbasehttp.py", line 139, in handle
self.raw_requestline = self.rfile.readline(65537)
File "C:Userspupenoscoopappspythoncurrentlibsocket.py", line 589, in readinto
return self._sock.recv_into(b)
ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host
All tests pass. I just get that to STDERR. Any ideas why? Am I missing some tearing-down?
If I change tearDownClass to:
@classmethod
def tearDownClass(cls):
cls.webdriver.quit()
I get the same error with the same frequency (as far as I can observe, without having measured it).
I'm running:
Django==2.1.2
selenium==3.141.0
and
> chromedriver.exe --version
ChromeDriver 2.43.600210 (68dcf5eebde37173d4027fa8635e332711d2874a)
and
Google Chrome Version 70.0.3538.102 (Official Build) (64-bit)
The full output of running the tests look like this:
Testing started at 15:33 ...
C:UserspupenoTemporaryuntitledvenvScriptspython.exe "C:Program FilesJetBrainsPyCharm 2018.2.4helperspycharmdjango_test_manage.py" test foo.tests.TestImportCRMData C:UserspupenoTemporaryuntitled
Creating test database for alias 'default'...
System check identified no issues (0 silenced).
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 49825)
Traceback (most recent call last):
File "C:Userspupenoscoopappspythoncurrentlibsocketserver.py", line 647, in process_request_thread
self.finish_request(request, client_address)
File "C:Userspupenoscoopappspythoncurrentlibsocketserver.py", line 357, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "C:Userspupenoscoopappspythoncurrentlibsocketserver.py", line 717, in __init__
self.handle()
File "C:UserspupenoTemporaryuntitledvenvlibsite-packagesdjangocoreserversbasehttp.py", line 139, in handle
self.raw_requestline = self.rfile.readline(65537)
File "C:Userspupenoscoopappspythoncurrentlibsocket.py", line 589, in readinto
return self._sock.recv_into(b)
ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host
----------------------------------------
Destroying test database for alias 'default'...
Process finished with exit code 0
python django selenium
In an Django application that I freshly created, where I changed it to use PostgreSQL and I created one app, I have the following test:
from django.contrib.auth.models import User
from django.contrib.staticfiles.testing import StaticLiveServerTestCase
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
class TestWebBrowser(StaticLiveServerTestCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.webdriver = webdriver.Chrome()
cls.webdriver.implicitly_wait(10)
@classmethod
def tearDownClass(cls):
cls.webdriver.close()
cls.webdriver.quit()
super().tearDownClass()
def setUp(self):
self.admin = User.objects.create_superuser(username="username", password="password",
email="example@example.com")
def test_log_in(self):
self.webdriver.get(f"self.live_server_url/admin")
self.webdriver.find_element_by_id("id_username").send_keys("username")
self.webdriver.find_element_by_id("id_password").send_keys("password")
self.webdriver.find_element_by_id("id_password").send_keys(Keys.RETURN)
self.webdriver.find_element_by_link_text("Users").click()
The test always runs, Chrome starts, does what the test say, but at the end, sometimes it throws this error:
Exception happened during processing of request from ('127.0.0.1', 55283)
Traceback (most recent call last):
File "C:Userspupenoscoopappspythoncurrentlibsocketserver.py", line 647, in process_request_thread
self.finish_request(request, client_address)
File "C:Userspupenoscoopappspythoncurrentlibsocketserver.py", line 357, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "C:Userspupenoscoopappspythoncurrentlibsocketserver.py", line 717, in __init__
self.handle()
File "C:UserspupenoTemporaryuntitledvenvlibsite-packagesdjangocoreserversbasehttp.py", line 139, in handle
self.raw_requestline = self.rfile.readline(65537)
File "C:Userspupenoscoopappspythoncurrentlibsocket.py", line 589, in readinto
return self._sock.recv_into(b)
ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host
All tests pass. I just get that to STDERR. Any ideas why? Am I missing some tearing-down?
If I change tearDownClass to:
@classmethod
def tearDownClass(cls):
cls.webdriver.quit()
I get the same error with the same frequency (as far as I can observe, without having measured it).
I'm running:
Django==2.1.2
selenium==3.141.0
and
> chromedriver.exe --version
ChromeDriver 2.43.600210 (68dcf5eebde37173d4027fa8635e332711d2874a)
and
Google Chrome Version 70.0.3538.102 (Official Build) (64-bit)
The full output of running the tests look like this:
Testing started at 15:33 ...
C:UserspupenoTemporaryuntitledvenvScriptspython.exe "C:Program FilesJetBrainsPyCharm 2018.2.4helperspycharmdjango_test_manage.py" test foo.tests.TestImportCRMData C:UserspupenoTemporaryuntitled
Creating test database for alias 'default'...
System check identified no issues (0 silenced).
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 49825)
Traceback (most recent call last):
File "C:Userspupenoscoopappspythoncurrentlibsocketserver.py", line 647, in process_request_thread
self.finish_request(request, client_address)
File "C:Userspupenoscoopappspythoncurrentlibsocketserver.py", line 357, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "C:Userspupenoscoopappspythoncurrentlibsocketserver.py", line 717, in __init__
self.handle()
File "C:UserspupenoTemporaryuntitledvenvlibsite-packagesdjangocoreserversbasehttp.py", line 139, in handle
self.raw_requestline = self.rfile.readline(65537)
File "C:Userspupenoscoopappspythoncurrentlibsocket.py", line 589, in readinto
return self._sock.recv_into(b)
ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host
----------------------------------------
Destroying test database for alias 'default'...
Process finished with exit code 0
python django selenium
python django selenium
edited Nov 15 '18 at 16:52
pupeno
asked Nov 15 '18 at 14:09
pupenopupeno
107k99274445
107k99274445
@DebanjanB: I don't think this is a duplicate question. The other one is about not managing to communicate with the chromedriver, while in my case that works. The error happens at the end.
– pupeno
Nov 15 '18 at 15:20
That's all the stack trace I'm getting. It must be happening on a separate thread.
– pupeno
Nov 15 '18 at 15:29
Can you help me to identify exactly at which line you are seeing the error?
– DebanjanB
Nov 15 '18 at 15:31
It doesn't happen on any line of my code. My tests all pass, and I just get that toSTDERRevery now and then.
– pupeno
Nov 15 '18 at 15:32
I'm guessing is something failing during tear down.
– pupeno
Nov 15 '18 at 15:33
|
show 1 more comment
@DebanjanB: I don't think this is a duplicate question. The other one is about not managing to communicate with the chromedriver, while in my case that works. The error happens at the end.
– pupeno
Nov 15 '18 at 15:20
That's all the stack trace I'm getting. It must be happening on a separate thread.
– pupeno
Nov 15 '18 at 15:29
Can you help me to identify exactly at which line you are seeing the error?
– DebanjanB
Nov 15 '18 at 15:31
It doesn't happen on any line of my code. My tests all pass, and I just get that toSTDERRevery now and then.
– pupeno
Nov 15 '18 at 15:32
I'm guessing is something failing during tear down.
– pupeno
Nov 15 '18 at 15:33
@DebanjanB: I don't think this is a duplicate question. The other one is about not managing to communicate with the chromedriver, while in my case that works. The error happens at the end.
– pupeno
Nov 15 '18 at 15:20
@DebanjanB: I don't think this is a duplicate question. The other one is about not managing to communicate with the chromedriver, while in my case that works. The error happens at the end.
– pupeno
Nov 15 '18 at 15:20
That's all the stack trace I'm getting. It must be happening on a separate thread.
– pupeno
Nov 15 '18 at 15:29
That's all the stack trace I'm getting. It must be happening on a separate thread.
– pupeno
Nov 15 '18 at 15:29
Can you help me to identify exactly at which line you are seeing the error?
– DebanjanB
Nov 15 '18 at 15:31
Can you help me to identify exactly at which line you are seeing the error?
– DebanjanB
Nov 15 '18 at 15:31
It doesn't happen on any line of my code. My tests all pass, and I just get that to
STDERR every now and then.– pupeno
Nov 15 '18 at 15:32
It doesn't happen on any line of my code. My tests all pass, and I just get that to
STDERR every now and then.– pupeno
Nov 15 '18 at 15:32
I'm guessing is something failing during tear down.
– pupeno
Nov 15 '18 at 15:33
I'm guessing is something failing during tear down.
– pupeno
Nov 15 '18 at 15:33
|
show 1 more comment
1 Answer
1
active
oldest
votes
This error message...
ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host
...implies that the ChromeDriver was unable to communicate with the WebBrowsing Session i.e. Chrome Browser session as it was forcibly closed by the remote host.
Your main issue is the multiple calls in the form of webdriver.close() and webdriver.quit()
While automating through Selenium as per the best practices to terminate a connection you should always invoke driver.quit() within tearDown() method to close & destroy the WebDriver and Web Client instances gracefully. Invoking quit() method DELETEs the current browsing session through sending "quit" command with "flags":["eForceQuit"] and finally sends the GET request on /shutdown EndPoint. Here is an example below :
1503397488598 webdriver::server DEBUG -> DELETE /session/8e457516-3335-4d3b-9140-53fb52aa8b74
1503397488607 geckodriver::marionette TRACE -> 37:[0,4,"quit","flags":["eForceQuit"]]
1503397488821 webdriver::server DEBUG -> GET /shutdown
So on invoking quit() method the Web Browser session and the WebDriver instance gets killed completely. Hence you don't have to incorporate any additional steps (invoking close()) which will be an overhead by the prevailing standards.
Solution
First of all you remove the following line:
cls.webdriver.close()
The very next line:
cls.webdriver.quit()
Is bound to terminate the connection in the best possible way.
Here you can find a detailed discussion on Selenium : How to stop geckodriver process impacting PC memory, without calling driver.quit()?
Update A
As per the liveservertestcase the tearDownClass() @classmethod isdefined as:
@classmethod
def tearDownClass(cls):
cls.selenium.quit()
super().tearDownClass()
As per django/django/test/testcases.py this is called:
@classmethod
def tearDownClass(cls):
cls._tearDownClassInternal()
cls._live_server_modified_settings.disable()
super().tearDownClass()
Having justquit()and noclose()results in the same error. I tried all the permutations of these two methods and none worked without an error.
– pupeno
Nov 15 '18 at 16:27
@pupeno I missed your stepsuper().tearDownClass(). Is that necessary?
– DebanjanB
Nov 15 '18 at 16:29
I added it because of the documentation here: docs.djangoproject.com/en/2.1/topics/testing/tools/…. This is the code that's being called: github.com/django/django/blob/…
– pupeno
Nov 15 '18 at 16:35
As per the reference discussion you need to callquit()only once which gracefully clears up the webdriver and web browser. Any additional step will raise an exception.
– DebanjanB
Nov 15 '18 at 16:36
I updated the question with this information. Just callingquit()throws the same error. Looking at the backtrace, I think the error is in django's server, not in selenium.
– pupeno
Nov 15 '18 at 16:42
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53321303%2fdjango-staticliveservertestcase-sometimes-ends-with-an-existing-connection-was%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
This error message...
ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host
...implies that the ChromeDriver was unable to communicate with the WebBrowsing Session i.e. Chrome Browser session as it was forcibly closed by the remote host.
Your main issue is the multiple calls in the form of webdriver.close() and webdriver.quit()
While automating through Selenium as per the best practices to terminate a connection you should always invoke driver.quit() within tearDown() method to close & destroy the WebDriver and Web Client instances gracefully. Invoking quit() method DELETEs the current browsing session through sending "quit" command with "flags":["eForceQuit"] and finally sends the GET request on /shutdown EndPoint. Here is an example below :
1503397488598 webdriver::server DEBUG -> DELETE /session/8e457516-3335-4d3b-9140-53fb52aa8b74
1503397488607 geckodriver::marionette TRACE -> 37:[0,4,"quit","flags":["eForceQuit"]]
1503397488821 webdriver::server DEBUG -> GET /shutdown
So on invoking quit() method the Web Browser session and the WebDriver instance gets killed completely. Hence you don't have to incorporate any additional steps (invoking close()) which will be an overhead by the prevailing standards.
Solution
First of all you remove the following line:
cls.webdriver.close()
The very next line:
cls.webdriver.quit()
Is bound to terminate the connection in the best possible way.
Here you can find a detailed discussion on Selenium : How to stop geckodriver process impacting PC memory, without calling driver.quit()?
Update A
As per the liveservertestcase the tearDownClass() @classmethod isdefined as:
@classmethod
def tearDownClass(cls):
cls.selenium.quit()
super().tearDownClass()
As per django/django/test/testcases.py this is called:
@classmethod
def tearDownClass(cls):
cls._tearDownClassInternal()
cls._live_server_modified_settings.disable()
super().tearDownClass()
Having justquit()and noclose()results in the same error. I tried all the permutations of these two methods and none worked without an error.
– pupeno
Nov 15 '18 at 16:27
@pupeno I missed your stepsuper().tearDownClass(). Is that necessary?
– DebanjanB
Nov 15 '18 at 16:29
I added it because of the documentation here: docs.djangoproject.com/en/2.1/topics/testing/tools/…. This is the code that's being called: github.com/django/django/blob/…
– pupeno
Nov 15 '18 at 16:35
As per the reference discussion you need to callquit()only once which gracefully clears up the webdriver and web browser. Any additional step will raise an exception.
– DebanjanB
Nov 15 '18 at 16:36
I updated the question with this information. Just callingquit()throws the same error. Looking at the backtrace, I think the error is in django's server, not in selenium.
– pupeno
Nov 15 '18 at 16:42
add a comment |
This error message...
ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host
...implies that the ChromeDriver was unable to communicate with the WebBrowsing Session i.e. Chrome Browser session as it was forcibly closed by the remote host.
Your main issue is the multiple calls in the form of webdriver.close() and webdriver.quit()
While automating through Selenium as per the best practices to terminate a connection you should always invoke driver.quit() within tearDown() method to close & destroy the WebDriver and Web Client instances gracefully. Invoking quit() method DELETEs the current browsing session through sending "quit" command with "flags":["eForceQuit"] and finally sends the GET request on /shutdown EndPoint. Here is an example below :
1503397488598 webdriver::server DEBUG -> DELETE /session/8e457516-3335-4d3b-9140-53fb52aa8b74
1503397488607 geckodriver::marionette TRACE -> 37:[0,4,"quit","flags":["eForceQuit"]]
1503397488821 webdriver::server DEBUG -> GET /shutdown
So on invoking quit() method the Web Browser session and the WebDriver instance gets killed completely. Hence you don't have to incorporate any additional steps (invoking close()) which will be an overhead by the prevailing standards.
Solution
First of all you remove the following line:
cls.webdriver.close()
The very next line:
cls.webdriver.quit()
Is bound to terminate the connection in the best possible way.
Here you can find a detailed discussion on Selenium : How to stop geckodriver process impacting PC memory, without calling driver.quit()?
Update A
As per the liveservertestcase the tearDownClass() @classmethod isdefined as:
@classmethod
def tearDownClass(cls):
cls.selenium.quit()
super().tearDownClass()
As per django/django/test/testcases.py this is called:
@classmethod
def tearDownClass(cls):
cls._tearDownClassInternal()
cls._live_server_modified_settings.disable()
super().tearDownClass()
Having justquit()and noclose()results in the same error. I tried all the permutations of these two methods and none worked without an error.
– pupeno
Nov 15 '18 at 16:27
@pupeno I missed your stepsuper().tearDownClass(). Is that necessary?
– DebanjanB
Nov 15 '18 at 16:29
I added it because of the documentation here: docs.djangoproject.com/en/2.1/topics/testing/tools/…. This is the code that's being called: github.com/django/django/blob/…
– pupeno
Nov 15 '18 at 16:35
As per the reference discussion you need to callquit()only once which gracefully clears up the webdriver and web browser. Any additional step will raise an exception.
– DebanjanB
Nov 15 '18 at 16:36
I updated the question with this information. Just callingquit()throws the same error. Looking at the backtrace, I think the error is in django's server, not in selenium.
– pupeno
Nov 15 '18 at 16:42
add a comment |
This error message...
ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host
...implies that the ChromeDriver was unable to communicate with the WebBrowsing Session i.e. Chrome Browser session as it was forcibly closed by the remote host.
Your main issue is the multiple calls in the form of webdriver.close() and webdriver.quit()
While automating through Selenium as per the best practices to terminate a connection you should always invoke driver.quit() within tearDown() method to close & destroy the WebDriver and Web Client instances gracefully. Invoking quit() method DELETEs the current browsing session through sending "quit" command with "flags":["eForceQuit"] and finally sends the GET request on /shutdown EndPoint. Here is an example below :
1503397488598 webdriver::server DEBUG -> DELETE /session/8e457516-3335-4d3b-9140-53fb52aa8b74
1503397488607 geckodriver::marionette TRACE -> 37:[0,4,"quit","flags":["eForceQuit"]]
1503397488821 webdriver::server DEBUG -> GET /shutdown
So on invoking quit() method the Web Browser session and the WebDriver instance gets killed completely. Hence you don't have to incorporate any additional steps (invoking close()) which will be an overhead by the prevailing standards.
Solution
First of all you remove the following line:
cls.webdriver.close()
The very next line:
cls.webdriver.quit()
Is bound to terminate the connection in the best possible way.
Here you can find a detailed discussion on Selenium : How to stop geckodriver process impacting PC memory, without calling driver.quit()?
Update A
As per the liveservertestcase the tearDownClass() @classmethod isdefined as:
@classmethod
def tearDownClass(cls):
cls.selenium.quit()
super().tearDownClass()
As per django/django/test/testcases.py this is called:
@classmethod
def tearDownClass(cls):
cls._tearDownClassInternal()
cls._live_server_modified_settings.disable()
super().tearDownClass()
This error message...
ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host
...implies that the ChromeDriver was unable to communicate with the WebBrowsing Session i.e. Chrome Browser session as it was forcibly closed by the remote host.
Your main issue is the multiple calls in the form of webdriver.close() and webdriver.quit()
While automating through Selenium as per the best practices to terminate a connection you should always invoke driver.quit() within tearDown() method to close & destroy the WebDriver and Web Client instances gracefully. Invoking quit() method DELETEs the current browsing session through sending "quit" command with "flags":["eForceQuit"] and finally sends the GET request on /shutdown EndPoint. Here is an example below :
1503397488598 webdriver::server DEBUG -> DELETE /session/8e457516-3335-4d3b-9140-53fb52aa8b74
1503397488607 geckodriver::marionette TRACE -> 37:[0,4,"quit","flags":["eForceQuit"]]
1503397488821 webdriver::server DEBUG -> GET /shutdown
So on invoking quit() method the Web Browser session and the WebDriver instance gets killed completely. Hence you don't have to incorporate any additional steps (invoking close()) which will be an overhead by the prevailing standards.
Solution
First of all you remove the following line:
cls.webdriver.close()
The very next line:
cls.webdriver.quit()
Is bound to terminate the connection in the best possible way.
Here you can find a detailed discussion on Selenium : How to stop geckodriver process impacting PC memory, without calling driver.quit()?
Update A
As per the liveservertestcase the tearDownClass() @classmethod isdefined as:
@classmethod
def tearDownClass(cls):
cls.selenium.quit()
super().tearDownClass()
As per django/django/test/testcases.py this is called:
@classmethod
def tearDownClass(cls):
cls._tearDownClassInternal()
cls._live_server_modified_settings.disable()
super().tearDownClass()
edited Nov 15 '18 at 19:25
answered Nov 15 '18 at 16:19
DebanjanBDebanjanB
45.8k134688
45.8k134688
Having justquit()and noclose()results in the same error. I tried all the permutations of these two methods and none worked without an error.
– pupeno
Nov 15 '18 at 16:27
@pupeno I missed your stepsuper().tearDownClass(). Is that necessary?
– DebanjanB
Nov 15 '18 at 16:29
I added it because of the documentation here: docs.djangoproject.com/en/2.1/topics/testing/tools/…. This is the code that's being called: github.com/django/django/blob/…
– pupeno
Nov 15 '18 at 16:35
As per the reference discussion you need to callquit()only once which gracefully clears up the webdriver and web browser. Any additional step will raise an exception.
– DebanjanB
Nov 15 '18 at 16:36
I updated the question with this information. Just callingquit()throws the same error. Looking at the backtrace, I think the error is in django's server, not in selenium.
– pupeno
Nov 15 '18 at 16:42
add a comment |
Having justquit()and noclose()results in the same error. I tried all the permutations of these two methods and none worked without an error.
– pupeno
Nov 15 '18 at 16:27
@pupeno I missed your stepsuper().tearDownClass(). Is that necessary?
– DebanjanB
Nov 15 '18 at 16:29
I added it because of the documentation here: docs.djangoproject.com/en/2.1/topics/testing/tools/…. This is the code that's being called: github.com/django/django/blob/…
– pupeno
Nov 15 '18 at 16:35
As per the reference discussion you need to callquit()only once which gracefully clears up the webdriver and web browser. Any additional step will raise an exception.
– DebanjanB
Nov 15 '18 at 16:36
I updated the question with this information. Just callingquit()throws the same error. Looking at the backtrace, I think the error is in django's server, not in selenium.
– pupeno
Nov 15 '18 at 16:42
Having just
quit() and no close() results in the same error. I tried all the permutations of these two methods and none worked without an error.– pupeno
Nov 15 '18 at 16:27
Having just
quit() and no close() results in the same error. I tried all the permutations of these two methods and none worked without an error.– pupeno
Nov 15 '18 at 16:27
@pupeno I missed your step
super().tearDownClass(). Is that necessary?– DebanjanB
Nov 15 '18 at 16:29
@pupeno I missed your step
super().tearDownClass(). Is that necessary?– DebanjanB
Nov 15 '18 at 16:29
I added it because of the documentation here: docs.djangoproject.com/en/2.1/topics/testing/tools/…. This is the code that's being called: github.com/django/django/blob/…
– pupeno
Nov 15 '18 at 16:35
I added it because of the documentation here: docs.djangoproject.com/en/2.1/topics/testing/tools/…. This is the code that's being called: github.com/django/django/blob/…
– pupeno
Nov 15 '18 at 16:35
As per the reference discussion you need to call
quit() only once which gracefully clears up the webdriver and web browser. Any additional step will raise an exception.– DebanjanB
Nov 15 '18 at 16:36
As per the reference discussion you need to call
quit() only once which gracefully clears up the webdriver and web browser. Any additional step will raise an exception.– DebanjanB
Nov 15 '18 at 16:36
I updated the question with this information. Just calling
quit() throws the same error. Looking at the backtrace, I think the error is in django's server, not in selenium.– pupeno
Nov 15 '18 at 16:42
I updated the question with this information. Just calling
quit() throws the same error. Looking at the backtrace, I think the error is in django's server, not in selenium.– pupeno
Nov 15 '18 at 16:42
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53321303%2fdjango-staticliveservertestcase-sometimes-ends-with-an-existing-connection-was%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
@DebanjanB: I don't think this is a duplicate question. The other one is about not managing to communicate with the chromedriver, while in my case that works. The error happens at the end.
– pupeno
Nov 15 '18 at 15:20
That's all the stack trace I'm getting. It must be happening on a separate thread.
– pupeno
Nov 15 '18 at 15:29
Can you help me to identify exactly at which line you are seeing the error?
– DebanjanB
Nov 15 '18 at 15:31
It doesn't happen on any line of my code. My tests all pass, and I just get that to
STDERRevery now and then.– pupeno
Nov 15 '18 at 15:32
I'm guessing is something failing during tear down.
– pupeno
Nov 15 '18 at 15:33