Skip to content

util.make_aiohttp_session: wrap aiohttp-socks 0.11+ excs to ClientError#10733

Merged
ecdsa merged 1 commit into
spesmilo:masterfrom
SomberNight:202607_aiohttp_proxyerror
Jul 2, 2026
Merged

util.make_aiohttp_session: wrap aiohttp-socks 0.11+ excs to ClientError#10733
ecdsa merged 1 commit into
spesmilo:masterfrom
SomberNight:202607_aiohttp_proxyerror

Conversation

@SomberNight

Copy link
Copy Markdown
Member

older versions of aiohttp-socks and python-socks used to raise

  • ProxyConnectionError(OSError)
  • ProxyTimeoutError(TimeoutError)
  • ProxyError(Exception)

now they raise:

  • ProxyConnectionError(Exception)
  • ProxyTimeoutError(Exception)
  • ProxyError(Exception)

In many call sites, we currently handle OSError and TimeoutError, usually by simply logging the error or showing it to the user. Another exceptions our call sites handle similarly is aiohttp.ClientError, which is the aiohttp base class for any client connection error.

A simple "fix" for us to restore the old behaviour is converting the new aiohttp_socks exception types to aiohttp.ClientError.

ref romis2012/aiohttp-socks@db4235c
ref romis2012/python-socks@50a3024


related:
#10727 (comment) (LLM output:)

Worth passing upstream (correctness, not security): aiohttp-socks 0.11.0's ProxyConnectionError is no o Electrum call sites like electrum/exchange_rate.py:90 that catch (aiohttp.ClientError, TimeoutError,OSError) now fall through to their generic except Exception when a SOCKS/Tor proxy is unreachable — functional but noisier; catching the aiohttp_socks exceptions explicitly would restore clean handling.

@f321x

f321x commented Jul 2, 2026

Copy link
Copy Markdown
Member

Tested with exchange rate fetching logic. Works and seems reasonable:

 28.11 | I | exchange_rate.BitFinex | failed fx quotes: ClientError('proxy error: ProxyConnectionError("[Errno 111] Couldn\'t connect to proxy 127.0.0.1:9053 [Connect call failed (\'127.0.0.1\', 9053)]")')

Comment thread electrum/util.py Outdated
Comment on lines +66 to +71
try:
from aiohttp_socks import ProxyConnectionError, ProxyTimeoutError, ProxyError
except ImportError: # above requires aiohttp_socks>=0.11
class _FakeProxyError(Exception):
pass
ProxyConnectionError = ProxyTimeoutError = ProxyError = _FakeProxyError

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: actually older aiohttp_socks just imports and re-exports the same names from python_socks:
https://github.com/romis2012/aiohttp-socks/blob/v0.9.2/aiohttp_socks/__init__.py#L4-L8

@SomberNight SomberNight force-pushed the 202607_aiohttp_proxyerror branch from acb3efd to 5ef3d22 Compare July 2, 2026 14:43
older versions of aiohttp-socks and python-socks used to raise
- ProxyConnectionError(OSError)
- ProxyTimeoutError(TimeoutError)
- ProxyError(Exception)

now they raise:
- ProxyConnectionError(Exception)
- ProxyTimeoutError(Exception)
- ProxyError(Exception)

In many call sites, we currently handle OSError and TimeoutError,
usually by simply logging the error or showing it to the user.
Another exceptions our call sites handle similarly is aiohttp.ClientError,
which is the aiohttp base class for any client connection error.

A simple "fix" for us to restore the old behaviour is converting the new aiohttp_socks
exception types to aiohttp.ClientError.

ref romis2012/aiohttp-socks@db4235c
ref romis2012/python-socks@50a3024
@SomberNight SomberNight force-pushed the 202607_aiohttp_proxyerror branch from 5ef3d22 to cd68b41 Compare July 2, 2026 14:48
@ecdsa ecdsa merged commit 0df37ee into spesmilo:master Jul 2, 2026
11 checks passed
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.

3 participants