python-websockets / websockets

Library for building WebSocket servers and clients in Python
https://websockets.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
5.19k stars 514 forks source link

when the network is bad, it shows fatal read error message #448

Closed yjqiang closed 6 years ago

yjqiang commented 6 years ago

Fatal read error on socket transport protocol: <asyncio.sslproto.SSLProtocol object at 0x1177ce940> transport: <_SelectorSocketTransport fd=47 read=polling write=<idle, bufsize=0>> Traceback (most recent call last): File "/var/containers/Bundle/Application/9F565D30-C54B-4210-902B-874D7A5AB814/Pythonista3.app/Frameworks/Py3Kit.framework/pylib/asyncio/selector_events.py", line 725, in _read_ready data = self._sock.recv(self.max_size) TimeoutError: [Errno 60] Operation timed out

aaugustin commented 6 years ago

I'm not sure what changes you're suggesting here. Do you mean that websockets should do something specific to handle this situation?

yjqiang commented 6 years ago

Yes. As a user, I can't handle this even though I use 'try'. So I think maybe websockets should handle it.

yjqiang commented 6 years ago

But I'm still not sure whether it is the bug in my code or websockets or asyncio.

aaugustin commented 6 years ago

It's not obvious that there's a bug here. If your network connection is poor, then connections can break. In that case, an exception is raised, and the exception you showed seems clear to me.

yjqiang commented 6 years ago

Can websockets handle this exception? I think maybe you can just drop it and retry the connection. For me the exception is very uncomfortable.

aaugustin commented 6 years ago

OK, so that's a duplicate of #414.

yjqiang commented 6 years ago

No, it is strange that it just shows the message but "recv()" doesn't raise exceptions which means I can receive messages without reconnection.

aaugustin commented 6 years ago

It's really hard for me to say something meaningful with zero context about what code produces this traceback under what circumstances.

yjqiang commented 6 years ago

https://github.com/yjqiang/bilibili-live-tools/blob/master/bilibiliCilent.py https://github.com/yjqiang/bilibili-live-tools/blob/master/connect.py

yjqiang commented 6 years ago

1."danmuji.connectServer" set up a connection
2."HeartbeatLoop" and "ReceiveMessageLoop" receive the msg and heartbeat

  1. if something is wrong, then I close the connection
yjqiang commented 6 years ago

So, do you find where the problem is?

aaugustin commented 6 years ago

I'm not going to debug the 300 lines of code you linked to. If you can produce a minimal reproduction example that exhibits an issue in websockets, perhaps I will take a look.

yjqiang commented 6 years ago

Ok, I'll write a minimal program. Then I will tell you. By the way, I think you should reopen this issue.

yjqiang commented 6 years ago

gobilibili-master.zip

yjqiang commented 6 years ago

I tested it last night, and I saw the msg again. And I wish the code is short enough for you to read.

yjqiang commented 6 years ago

Fatal read error on socket transport protocol: <asyncio.sslproto.SSLProtocol object at 0x111208ef0> transport: <_SelectorSocketTransport fd=12 read=polling write=<idle, bufsize=0>> Traceback (most recent call last): File "/var/containers/Bundle/Application/9F565D30-C54B-4210-902B-874D7A5AB814/Pythonista3.app/Frameworks/Py3Kit.framework/pylib/asyncio/selector_events.py", line 725, in _read_ready data = self._sock.recv(self.max_size) TimeoutError: [Errno 60] Operation timed out Error in data transfer Traceback (most recent call last): File "/private/var/mobile/Containers/Shared/AppGroup/DD7F02C7-CB2E-4501-8454-4160BFD1B7B2/Pythonista3/Documents/site-packages-3/websockets/protocol.py", line 530, in transfer_data msg = yield from self.read_message() File "/private/var/mobile/Containers/Shared/AppGroup/DD7F02C7-CB2E-4501-8454-4160BFD1B7B2/Pythonista3/Documents/site-packages-3/websockets/protocol.py", line 582, in read_message frame = yield from self.read_data_frame(max_size=self.max_size) File "/private/var/mobile/Containers/Shared/AppGroup/DD7F02C7-CB2E-4501-8454-4160BFD1B7B2/Pythonista3/Documents/site-packages-3/websockets/protocol.py", line 647, in read_data_frame frame = yield from self.read_frame(max_size) File "/private/var/mobile/Containers/Shared/AppGroup/DD7F02C7-CB2E-4501-8454-4160BFD1B7B2/Pythonista3/Documents/site-packages-3/websockets/protocol.py", line 712, in read_frame extensions=self.extensions, File "/private/var/mobile/Containers/Shared/AppGroup/DD7F02C7-CB2E-4501-8454-4160BFD1B7B2/Pythonista3/Documents/site-packages-3/websockets/framing.py", line 100, in read data = yield from reader(2) File "/var/containers/Bundle/Application/9F565D30-C54B-4210-902B-874D7A5AB814/Pythonista3.app/Frameworks/Py3Kit.framework/pylib/asyncio/streams.py", line 669, in readexactly yield from self._wait_for_data('readexactly') File "/var/containers/Bundle/Application/9F565D30-C54B-4210-902B-874D7A5AB814/Pythonista3.app/Frameworks/Py3Kit.framework/pylib/asyncio/streams.py", line 459, in _wait_for_data yield from self._waiter File "/var/containers/Bundle/Application/9F565D30-C54B-4210-902B-874D7A5AB814/Pythonista3.app/Frameworks/Py3Kit.framework/pylib/asyncio/futures.py", line 332, in iter yield self # This tells Task to wait for completion. File "/var/containers/Bundle/Application/9F565D30-C54B-4210-902B-874D7A5AB814/Pythonista3.app/Frameworks/Py3Kit.framework/pylib/asyncio/tasks.py", line 245, in _wakeup future.result() File "/var/containers/Bundle/Application/9F565D30-C54B-4210-902B-874D7A5AB814/Pythonista3.app/Frameworks/Py3Kit.framework/pylib/asyncio/futures.py", line 245, in result raise self._exception File "/var/containers/Bundle/Application/9F565D30-C54B-4210-902B-874D7A5AB814/Pythonista3.app/Frameworks/Py3Kit.framework/pylib/asyncio/selector_events.py", line 725, in _read_ready data = self._sock.recv(self.max_size) TimeoutError: [Errno 60] Operation timed out

yjqiang commented 6 years ago

Is there anything else I can do for you? Maybe my code and the message are not clearly enough, but I hope it can help you.

yjqiang commented 6 years ago

It occurred frequently recently, it is very confusing.

yjqiang commented 6 years ago

yjqiang commented 6 years ago

Keep showing the msg...

aaugustin commented 6 years ago

I'm sorry but I really can't help with what you've provided.

In the context of a bug report, a "minimal program" is something about as large as https://github.com/aaugustin/websockets/blob/master/example/client.py.

I suppose I could install go, compile the 638 lines of Go and run a server, connect a client with the 379 lines of Python, and see that stack trace... and I'd be left with "well I guess Go server times out somewhere".

Unfortunately I don't have the motivation to do this.

yjqiang commented 6 years ago

Sorry to bother u but it looks like it is a bug on Pythonista(ios). I'm so sorry about this.

aaugustin commented 6 years ago

No problem. Feel free to open a new issue if you end up suspecting something in websockets.

yjqiang commented 5 years ago

I’m so sorry. Sorry I just found I sent the wrong test file. But I think it’s unnecessary to resend since it’s not a bug in websockets. I wrote it just to apologize. Sorry.