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)when the network is bad, it shows “Fatal read error on socket transport”. #563

Closed
yjqiang opened this issue Aug 18, 2018 · 36 comments

Comments

@yjqiang
Copy link

yjqiang commented Aug 18, 2018

aio-libs/aiohttp#3202

According to the authors of aiohttp, it is a bug in pythonista.

@cclauss
Copy link
Contributor

cclauss commented Aug 18, 2018

Please change the title of this issue to something more descriptive. There a lot of open issues and the current title does nothing to help those who are trying to find and fix issues.

@yjqiang yjqiang changed the title A bug in pythonista. when the network is bad, it shows fatal read error message when using websocket Aug 18, 2018
@yjqiang yjqiang changed the title when the network is bad, it shows fatal read error message when using websocket (websocket)when the network is bad, it shows fatal read error message Aug 18, 2018
@jsbain
Copy link

jsbain commented Aug 20, 2018

How about some example code which allows someone to reproduce your failure. The aiohttp folks said this was not their code, but didn't absolve your usage either...

@yjqiang
Copy link
Author

yjqiang commented Aug 20, 2018

I used "try" to catch the exceptions. But I can't catch the "fatal error" msg.

@dgelessus
Copy link

Isn't this the same issue that was discussed in #555?

@yjqiang
Copy link
Author

yjqiang commented Aug 20, 2018

Sorry about that, at first I thought it was
aiohttp client's bug, but I wrote only one websocket using aiohttp, and it showed again. And I also tried https://github.com/aaugustin/websockets to use websocket, it showed again and again.

@yjqiang
Copy link
Author

yjqiang commented Oct 31, 2018

I think it should be the bug in pythonista.

@jsbain
Copy link

jsbain commented Oct 31, 2018

So, can you summarize how we reproduce this error? Seems like there should be a very succinct script with a few lines that reproduces the issue. Does this fail when the network is off? Or does it need interaction with the server for this to fail

@yjqiang
Copy link
Author

yjqiang commented Oct 31, 2018

I use the websocket in module “aiohttp” or “websockets” to connect websites. When the network is not stable. It shows this. I used "try except" for all the script, but it did not work.

@jsbain
Copy link

jsbain commented Oct 31, 2018

Did you have a minimal example that someone else could use to reproduce? Your previous example seemed very much linked to your own local network.

Do you get this error if, for example, you turn off WiFi/data? Or only when you have marginally stable connection? Is pythonista in the background when this fails?

@yjqiang yjqiang changed the title (websocket)when the network is bad, it shows fatal read error message (websocket)when the network is bad, it shows “Fatal read error on socket transport”. Oct 31, 2018
@jsbain
Copy link

jsbain commented Oct 31, 2018

Again, we need a minimal example, not hundreds of lines of code.

Have you tested your code with a pc and the same server?

@yjqiang
Copy link
Author

yjqiang commented Oct 31, 2018

bug for pyista.zip
About 150 lines. I just tested it. Is this clear now?
(pythonista 320000, python 3.6.1, aiohttp 3.4.4)

@jsbain
Copy link

jsbain commented Oct 31, 2018

Not a pythonista problem. I reproduced your error on Android, when turning off data while the script ran.

I suspect you could duplicate on PC if you unplugged Ethernet, etc after the connection started.

@yjqiang
Copy link
Author

yjqiang commented Oct 31, 2018

I wrapped almost every network code with 'try'. And aiohttp's author said it is not a bug on aiohttp. Now it is not a bug in pythonista. ...I'm almost crying.

@yjqiang
Copy link
Author

yjqiang commented Oct 31, 2018

Can you help me to debug? I have been suffering from it for a long time.

@jsbain
Copy link

jsbain commented Nov 1, 2018

python/asyncio#135

A search for the error would have resulted in this documented behavior in asyncio.

@jsbain
Copy link

jsbain commented Nov 1, 2018

python/asyncio#80
Solution seems to be a custom error hndler to silence the warning.

@jsbain
Copy link

jsbain commented Nov 1, 2018

Or handle connection_lost, and don't worry about the extra logged warning

@yjqiang
Copy link
Author

yjqiang commented Nov 1, 2018

I wrapped all function using aiohttp with "try". But it kept showing this. And it seems it is a feature in asyncio instead of a bug?

@yjqiang
Copy link
Author

yjqiang commented Nov 1, 2018

I just don't know the reason why it shows this. Because when the connection is broken in low level like tcp, python should resend the msg itself. If the connection is broken for http connection, I used 'try' to catch it. So where is this bug coming from?

@yjqiang
Copy link
Author

yjqiang commented Nov 1, 2018

Or maybe aiohttp used asyncio to make a connection but aiohttp didn't handle this error?

@cclauss
Copy link
Contributor

cclauss commented Nov 1, 2018

Correct. That is why there is the suggestion that install a custom error handler.

Your try / except is not working because it is not your code that is raising. Instead, it is code in the aio event loop that is raising so the custom error handler should be the right path forward.

@yjqiang
Copy link
Author

yjqiang commented Nov 1, 2018

Maybe aiohttp should handle it instead of me? I don't think user should handle timeout error in this way.
And it is so strange since aiohttp also has aiohttp.ServerTimeoutError which is Derived from ServerConnectionError and asyncio.TimeoutError. What is the differnce between aiohttp.ServerTimeoutError and this "timout"?

@jsbain
Copy link

jsbain commented Nov 1, 2018

This error occurs when the server closes the connection unexpectedly or otherwise you are disconnected. The error is logged, but calls connection_lost on the Transport or Protocol. So if you want to handle the actual problem so you can retry, then implement a connection_lost handler. But if you want to turn off logging, you need the custom error_handler.

This is coming from asyncio, not aiohttp or anywhere else.

@yjqiang
Copy link
Author

yjqiang commented Nov 1, 2018

But why it shows? If the network is not good, python can wait until I read the msg from it, and then it raises this error. It just shows in the background and I have to catch it out of the connection.

And before this, I didn't catch the error, it seems just annoying but I didn't find anything, the connection of aiohttp didn't lost. What should I do to this error? Just ignore it?

@yjqiang
Copy link
Author

yjqiang commented Nov 1, 2018

def _fatal_error(self, exc, message='Fatal error on transport'):
        # Should be called from exception handler only.
        if isinstance(exc, base_events._FATAL_ERROR_IGNORE):
            if self._loop.get_debug():
                logger.debug("%r: %s", self, message, exc_info=True)
        else:
            self._loop.call_exception_handler({
                'message': message,
                'exception': exc,
                'transport': self,
                'protocol': self._protocol,
            })
        self._force_close(exc)


_FATAL_ERROR_IGNORE = (BrokenPipeError,
                       ConnectionResetError, ConnectionAbortedError)

@yjqiang
Copy link
Author

yjqiang commented Nov 1, 2018

I read the code of asyncio, timeout doesn't belong to fatal_error_ignore. So I think I should just ignore it. But it is so strange since timeout does not belong to fatal_error_ignore.

@jsbain
Copy link

jsbain commented Nov 1, 2018

try this:

from asyncio import constants
constants.LOG_THRESHOLD_FOR_CONNLOST_WRITES = 1000000  # some big number

The "error" you see is just a logging of an exception that ultimately will result in a different event that your code is handling.

@jsbain
Copy link

jsbain commented Nov 2, 2018

Actually, it looks like if you don't want the exception handler called, you can add to _FATAL_ERROR_IGNORE:
asyncio.base_events._FATAL_ERROR_IGNORE.append(TimeoutError)

Maybe go ahead and close the various issues you have open on this topic?

@yjqiang
Copy link
Author

yjqiang commented Nov 2, 2018

Sorry, but I just dont know why asyncio did not just ignore it as others. So I'm asking the author of aiohttp.

@yjqiang
Copy link
Author

yjqiang commented Nov 2, 2018

And I just keep one issue open here for this problem. Where are the others?

@cclauss
Copy link
Contributor

cclauss commented Nov 2, 2018

@yjqiang
Copy link
Author

yjqiang commented Nov 2, 2018

I still didn't find the answers to these questions. And these are not the same question.

@yjqiang
Copy link
Author

yjqiang commented Nov 2, 2018

By the way, _FALTAL_ERROR_IGNORE is 'tuple' so we can't use append.

@jsbain
Copy link

jsbain commented Nov 2, 2018

Your questions are not related to pythonista. I'd suggest stackoverflow or general aiohttp/asyncio questions.

Re fatal error ignore, you are right about it being a tuple. You would use
asyncio._FATAL_ERROR_IGNORE += (TimeoutError,)
to append to it.

@yjqiang
Copy link
Author

yjqiang commented Nov 2, 2018

Sorry. Thx a lot for this. Sorry to bother you for a long time. Thank you.

@yjqiang yjqiang closed this as completed Nov 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants