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

Fix a bug where a socket connection to "bsv.aftrek.org" is successful… #1132

Merged

Conversation

AustEcon
Copy link
Collaborator

…ly established but on protocol negotiation, the result is "None"

  • This crashes the entire asyncio event loop with "TypeError: cannot unpack non-iterable NoneType object"

Context:

This is the relevant traceback:

2023-08-10 12:43:42,021:ERROR:async:async task raised an unhandled exception
Traceback (most recent call last):
  File ".../electrumsv/electrumsv/async_.py", line 94, in _collect
    future.result()
  File ".../.pyenv/versions/3.9.16/lib/python3.9/concurrent/futures/_base.py", line 439, in result
    return self.__get_result()
  File ".../.pyenv/versions/3.9.16/lib/python3.9/concurrent/futures/_base.py", line 391, in __get_result
    raise self._exception
  File ".../electrumsv/electrumsv/network.py", line 944, in _main_task
    await group.spawn(self._monitor_wallets, group)
  File ".../electrumsv/lib/python3.9/site-packages/aiorpcx/curio.py", line 255, in aexit
    await self.join()
  File ".../electrumsv/lib/python3.9/site-packages/aiorpcx/curio.py", line 213, in join
    raise task.exception()
  File ".../electrumsv/electrumsv/network.py", line 973, in _maintain_connections
    await group.spawn(self._maintain_connection, n)
  File ".../electrumsv/lib/python3.9/site-packages/aiorpcx/curio.py", line 255, in aexit
    await self.join()
  File ".../electrumsv/lib/python3.9/site-packages/aiorpcx/curio.py", line 213, in join
    raise task.exception()
  File ".../electrumsv/electrumsv/network.py", line 987, in _maintain_connection
    await server.connect(self, n)
  File "...electrumsv/electrumsv/network.py", line 266, in connect
    await session.run()
  File ".../electrumsv/electrumsv/network.py", line 763, in run
    await self._negotiate_protocol()
  File ".../electrumsv/electrumsv/network.py", line 463, in _negotiate_protocol
    server_string, protocol_string = await self.send_request(method, args)
TypeError: cannot unpack non-iterable NoneType object

This only occurs for the "bsv.aftrek.org" server and is strange because we've never encountered this behaviour from any ElectrumX server in the past.

To reproduce this in isolation sheds some light:

import asyncio
import aiorpcx
import ssl

async def main(host, port):
    async with aiorpcx.connect_rs(host, port, ssl=ssl.SSLContext(ssl.PROTOCOL_TLS)) as session:
        print("Connected!")
        result = await session.send_request('server.version', ("1.3.16", ["1.4", "1.4.2"]))
        print(result)

asyncio.run(main('sv3.satoshi.io', 50002))
asyncio.run(main('bsv.aftrek.org', 50002))

Console output:

Connected!
['ElectrumX 1.20.2', '1.4.2']
Connected!
None

So a connection is still being established to bsv.aftrek.org but for some reason protocol negotiation is failing.

electrumsv/network.py Outdated Show resolved Hide resolved
electrumsv/network.py Show resolved Hide resolved
@AustEcon AustEcon force-pushed the features/bug-fix-electrumx-protocol-negotiation branch from b40a099 to de75af9 Compare August 14, 2023 14:01
…ly established but on protocol negotiation, the result is "None"

- This crashes the entire asyncio event loop with "TypeError: cannot unpack non-iterable NoneType object"
- Catch the raised TypeError to avoid crashing the asyncio event loop.
@AustEcon AustEcon force-pushed the features/bug-fix-electrumx-protocol-negotiation branch from de75af9 to 032ffac Compare August 14, 2023 21:52
- Servers will now be blacklisted if `DisconnectSessionError` is raised with blacklist=True
- Added type assertions to `_negotiate_protocol` handler to ensure bad responses from a misbehaving ElectrumX server are appropriately caught.
@rt121212121 rt121212121 merged commit b7f2a91 into releases/1.3 Aug 17, 2023
10 checks passed
@rt121212121 rt121212121 deleted the features/bug-fix-electrumx-protocol-negotiation branch August 17, 2023 22:55
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.

None yet

2 participants