vibora
vibora copied to clipboard
Error starting test client
Describe the bug
When calling app.test_client()
the following error is raised.
Traceback (most recent call last):
File "tests/mytests.py", line 12, in setUp
self.client = app.test_client()
File "/Users/ordanis/miniconda3/envs/dl-lab/lib/python3.6/site-packages/vibora/server.py", line 213, in test_client
self.run(host=address, port=port, block=False, verbose=False, necromancer=False, workers=1, debug=True)
File "/Users/ordanis/miniconda3/envs/dl-lab/lib/python3.6/site-packages/vibora/server.py", line 266, in run
wait_server_available(host, port)
File "/Users/ordanis/miniconda3/envs/dl-lab/lib/python3.6/site-packages/vibora/utils.py", line 134, in wait_server_available
sock.connect((host, port))
OSError: [Errno 22] Invalid argument
Additional context Vibora version is 0.0.6, Python 3.6.5 on macOS Sierra 10.12.6
I encountered this same weird error with test_client using Viroba 0.0.6 on OSX (v10.13.5) and Python 3.6.
I found a solution that seemed to resolve it for me.
As indicated at: https://stackoverflow.com/questions/43643876/python-socket-invalid-argument
If connect() fails, consider the state of the socket as unspecified. Portable applications
should close the socket and create a new one for reconnecting.
Based on this, the invalid argument error message refers to the given file descriptor that
corresponds to a socket that not in usable state.
So instead of attempting to reuse the socket after a connect failure the modified function creates a new socket. With this change in place the error was no longer observed.
def wait_server_available(host, port, timeout: int=10):
"""
Wait until the server is available by trying to connect to the same.
:param timeout:
:param host:
:param port:
:return:
"""
while timeout > 0:
start_time = time.time()
sock = socket.socket()
sock.settimeout(timeout)
try:
sock.connect((host, port))
sock.close()
return
except (ConnectionRefusedError, ConnectionAbortedError, ConnectionResetError):
sock.close()
time.sleep(0.001)
timeout -= time.time() - start_time
raise SystemError(f'Server is taking too long to get online.')
@frnkvieira I encountered this error while debugging the sample code from Vibora.io homepage.
The debugger hangs on Connected to pydev debugger (build 182.3684.100)
and then errors out with Server is taking too long to get online.
message.
I am currently using the master branch of Vibora on Python 3.7
The above workaround fixes the issue for now.