Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

websocket client: when the network is bad, it shows fatal read error message #3202

Closed
yjqiang opened this issue Aug 18, 2018 · 17 comments
Closed
Labels

Comments

@yjqiang
Copy link

yjqiang commented Aug 18, 2018

This is a msg in PYTHONISTA on ios (python 3.6.1). So maybe it is a bug in pythonista.

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

@kxepal
Copy link
Member

kxepal commented Aug 18, 2018

Definitely, not a bug of aiohttp nor Pythonista, but remote server which couldn't respond within specified timeout interval. There is nothing to do from aiohttp side.

@kxepal kxepal closed this as completed Aug 18, 2018
@yjqiang
Copy link
Author

yjqiang commented Aug 18, 2018

@kxepal "remote server which couldn't respond within specified timeout interval"? I wrap timeout with the receive function like https://github.com/yjqiang/bilibili-live-tools/blob/master/bilibiliCilent.py#L92 .

@asvetlov
Copy link
Member

I cannot understand how did you get TimeoutError (not asyncio.TimeoutError)?
The former is never used by asyncio nor aiohttp.
Bare TimeoutError with errno 60 is for synchronous sockets only.

@yjqiang
Copy link
Author

yjqiang commented Aug 18, 2018

The server said we must send a special heartbeat package 1 time per 30 seconds, and it would send a confirm msg to client after receiving the msg. So I wrote that to make sure that when the server closes the connection but without talking to client, after 35s, the client will find that fact.

@yjqiang
Copy link
Author

yjqiang commented Aug 18, 2018

Can I handle the error "TimeoutError: [Errno 60] Operation timed out" by myself? I used try and exception, but it did not work at all.

@yjqiang
Copy link
Author

yjqiang commented Aug 18, 2018

Sorry my English is not good so I think maybe I misunderstood your words. You mean why the msg is TimeoutError instead of asyncio.TimeoutError? I can't get it too. Maybe it is a bug in pythonista?

@asvetlov
Copy link
Member

@yjqiang yes. I mean that TimeoutError is never raised by asyncio/aiohttp in normal usage.
It could be raised if a blocking socket was passed into event loop but this case is definitely an error.

I know nothing about pythonista thogh

@yjqiang
Copy link
Author

yjqiang commented Nov 1, 2018

omz/Pythonista-Issues#563
Looks like it is not a bug in pythonista, asyncio raises timeout error. Maybe aiohttp should catch and handle it?

@yjqiang
Copy link
Author

yjqiang commented Nov 2, 2018

@asvetlov

@yjqiang
Copy link
Author

yjqiang commented Nov 17, 2018

The reason why it raises TimeoutError is that the code in omz/Pythonista-Issues#563 (comment)
And 3 years ago, people discussed about that in python/asyncio#135

@asvetlov
Copy link
Member

TimeoutError builtin is raised when a syscall returns ETIMEDOUT status code.
man errno says that this error code is for "Connection timed out (POSIX.1-2001)".

From my understanding, the error should be never raised for a nonblocking socket, only EAGAIN and EWOULDBLOCK are possible values if the socket is not ready.

UPD.
Looks like TCP keepalive facility can return ETIMEDOUT: https://stackoverflow.com/questions/16772519/socket-recv-on-selected-socket-failing-with-etimedout

I need to investigate more.

@yjqiang
Copy link
Author

yjqiang commented Nov 17, 2018

TimeoutError builtin is raised when a syscall returns ETIMEDOUT status code.
man errno says that this error code is for "Connection timed out (POSIX.1-2001)".

From my understanding, the error should be never raised for a nonblocking socket, only EAGAIN and EWOULDBLOCK are possible values if the socket is not ready.

UPD.
Looks like TCP keepalive facility can return ETIMEDOUT: https://stackoverflow.com/questions/16772519/socket-recv-on-selected-socket-failing-with-etimedout

I need to investigate more.

"a NAT gateway could time out after some minutes of not doing anything" So the server does not work well or the network is not normal, after I setup the connection. If it is that reason, maybe aiohttp/asyncio should raise this exception when I use recv() and let us handle it? But maybe they would hold the exception for a long time if I did not use recv() immediately.

@asvetlov
Copy link
Member

The current behavior is:

  1. TimeoutError is received on socket operation.
  2. asyncio closes transport and logs the error by loop.call_exception_handler().

The logging can be suppressed in next Python release (as we do it for ConnectionError and several other exceptions).
But I see no reason to change the main reaction: close the socket and call protocol.connection_lost(exc) with exception info.

@yjqiang
Copy link
Author

yjqiang commented Nov 17, 2018

Thanks.

@yjqiang
Copy link
Author

yjqiang commented Dec 26, 2018

@asvetlov https://bugs.python.org/issue34148 I think it should be fixed by just add TimeoutError to base_events._FATAL_ERROR_IGNORE. But I didn't find the api about this issue in aiohttp.

@asvetlov
Copy link
Member

Move discussion to Python bug tracker

@yjqiang
Copy link
Author

yjqiang commented Mar 14, 2019

Move discussion to Python bug tracker

No response yet for 2 months.
python/cpython#11576

@lock lock bot added the outdated label Mar 17, 2020
@lock lock bot locked as resolved and limited conversation to collaborators Mar 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants