Skip to content

Attempt to better handle HTTP ReadTimeout/ConnectionError errors#1046

Merged
CastagnaIT merged 4 commits into
masterfrom
req_fixes
Jan 24, 2021
Merged

Attempt to better handle HTTP ReadTimeout/ConnectionError errors#1046
CastagnaIT merged 4 commits into
masterfrom
req_fixes

Conversation

@CastagnaIT

Copy link
Copy Markdown
Owner

Check if this PR fulfills these requirements:

Types of changes

  • New feature (non-breaking change which adds functionality)
  • Feature change (non-breaking change which change behaviour of an existing functionality)
  • Improvement (non-breaking change which improve functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Breaking change (fix or feature that would cause existing functionality to change)

Description

Some users have encountered HTTP errors as:
ConnectionError: ('Connection aborted.', error("(104, 'ECONNRESET')",))
Issue #1004
ReadTimeout: HTTPSConnectionPool(host='www.n*****x.com', port=443): Read timed out. (read timeout=None)
Issue #914

I have no idea if the cause is the network or the Netflix servers, or a bug in Requests/Urlib module
this problem happen only with some users on linux/windows platform and on both Kodi 18/19 (python 2 and 3)

For the "Connection aborted ... ECONNRESET" error case, has been tried every type of solutions provided from:
psf/requests#4937
psf/requests#3845

Solutions tried:

  • Tried to add extra time between HTTP requests (time.sleep(0,5))
  • Tried to use a single Requests session object (on NF session service) instead of two (one on MSL service / one on NF session service)
  • Tried to install (on python 2):
pip install requests[security]
pip install pyopenssl ndg-httpsclient pyasn1
  • Tried to add custom HTTPAdapters with max_retries
from requests.adapters import HTTPAdapter
session.mount('http', HTTPAdapter(max_retries=3))
session.mount('https', HTTPAdapter(max_retries=3))

Nothing works

I don't remember in which Issue message, but i read about a possible Request or Urlib bug that in some situations doesn't close opened persistent connections anymore, therefore on next http request cause the ConnectionError ... ECONNRESET.

Perhaps something similar is true, because if you force to close the connection by add on each HTTP request the header
Connection: close the ConnectionError ... ECONNRESET error not happen anymore,
although i don't understand why it only happens to certain users

but forcing close the connetion on each request does not seem to me to be good practice to do with HTTP1.1 servers.
so as workaround i added a simple retry loop.

In case of Feature change / Breaking change:

Describe the current behavior

Describe the new behavior

Screenshots (if appropriate):

Slower devices are not always fast enough to send the signal in faster way while other operations are carried out,
this cause to ActionController to crash because receive the playback data after Kodi 'Player.OnPlay' event and will no longer manage events
@thrillfall

Copy link
Copy Markdown

i also had issues with timeout errors. i am not sure if the reason only applies to me but i found a solution.
I "debugged" the timeout by running curl www.netflix.com and found it stuck for most of the requests. I found a blog talking about netflix blocking ipv6 tunnels which basically disables ipv6 usage. To prevent this you can "blackhole" the ipv6 address and suddently the connection always works:
https://blog.jmwhite.co.uk/2016/06/12/netflix-starts-blocking-ipv6-tunnels/
sudo ip -6 route add blackhole 2a05:d018:76c::/48

i hope it is of use to someone.

@CastagnaIT

CastagnaIT commented Jan 24, 2021

Copy link
Copy Markdown
Owner Author

interesting i found various articles on the net that talk about this
if it really works, it is not an easy thing to do for non-expert users could cause more problems than solutions if they do something wrong...
i just don't see explained how to undo the changes
PS. this problem affect also Windows system not only linux

@thrillfall

Copy link
Copy Markdown

interesting i found various articles on the net that talk about this
if it really works, it is not an easy thing to do for non-expert users could cause more problems than solutions if they do something wrong...
i just don't see explained how to undo the changes
PS. this problem affect also Windows system not only linux

I just wanted to document this. Maybe we could add this to the FAQ.

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

Successfully merging this pull request may close these issues.

2 participants