closed remote connection on windows.
tshirtman opened this issue · 1 comments
Describe the bug
running tests on windows now fails, specifically, test test_server_different_port
in test_server.py
.
To reproduce
(.env) C:\Users\gqb\dev\oscpy>pytest -k test_server_different_port
Test session starts (platform: win32, Python 3.6.1, pytest 4.2.0, pytest-sugar 0.9.2)
rootdir: C:\Users\gqb\dev\oscpy, inifile:
plugins: sugar-0.9.2, cov-2.6.1
collecting ...
―――――――――――――――――――――――――――――――――――――――――――― test_server_different_port ――――――――――――――――――――――――――――――――――――――――――――
def test_server_different_port():
# used for storing values received by callback_3000
checklist = []
def callback_3000(*values):
checklist.append(values[0])
# server, will be tested:
server_3000 = OSCThreadServer(encoding='utf8')
sock_3000 = server_3000.listen( address='0.0.0.0', port=3000, default=True)
server_3000.bind(b'/callback_3000', callback_3000)
# clients sending to different ports, used to test the server:
client_3000 = OSCClient(address='localhost', port=3000, encoding='utf8')
# server sends message to himself, should work:
server_3000.send_message(
b'/callback_3000',
["a"],
ip_address='localhost',
port=3000
)
sleep(0.05)
# client sends message to server, will be received properly:
client_3000.send_message(b'/callback_3000', ["b"])
sleep(0.05)
# sever sends message on different port, might crash the server on windows:
server_3000.send_message(
b'/callback_3000',
["nobody is going to receive this"],
ip_address='localhost',
port=3001
)
sleep(0.05)
# client sends message to server again. if server is dead, message
# will not be received:
client_3000.send_message(b'/callback_3000', ["c"])
sleep(0.1)
# if 'c' is missing in the received checklist, the server thread
# crashed and could not recieve the last message from the client:
> assert checklist == ['a', 'b', 'c']
E AssertionError: assert ['a', 'b'] == ['a', 'b', 'c']
E Right contains more items, first extra item: 'c'
E Use -v to get the full diff
tests\test_server.py:927: AssertionError
----------------------------------------------- Captured stderr call -----------------------------------------------
Exception in thread Thread-1:
Traceback (most recent call last):
File "C:\Users\gqb\AppData\Local\Programs\Python\Python36\lib\threading.py", line 916, in _bootstrap_inner
self.run()
File "C:\Users\gqb\AppData\Local\Programs\Python\Python36\lib\threading.py", line 864, in run
self._target(*self._args, **self._kwargs)
File "c:\users\gqb\dev\oscpy\oscpy\server.py", line 336, in _listen
data, sender = sender_socket.recvfrom(65535)
ConnectionResetError: [WinError 10054] Une connexion existante a dû être fermée par l’hôte distant
tests/test_server.py ⨯ 100% ██████████
Results (0.56s):
1 failed
- tests/test_server.py:883 test_server_different_port
80 deselected
(.env) C:\Users\gqb\dev\oscpy>
Expected behavior
Test should pass, there is no reason that sending from client should crash the server.
Platform (please complete the following information):
- OS: windows 10
- Python version. 3.6.1
- release or git branch/commit: master
Additional context
doesn't reproduce in CI, only on a real windows, it seems…
https://stackoverflow.com/questions/29841257/why-am-i-getting-a-connectionreseterror-here
hinted by this, i added another server to the test, to listen on port 3001, and now the test passes, so windows seems to actually care if someone is listening for udp messages, and causing a crash of the process if it has unread data, having another process listening on the target port, like
oscli dump -H localhost -P 3001
also allows the test to pass.