ethereum / trinity

The Trinity client for the Ethereum network
https://trinity.ethereum.org
MIT License
474 stars 145 forks source link

Trinity prints noisy error message when being port-scanned #13

Closed veox closed 5 years ago

veox commented 5 years ago

What is wrong?

Running trinity as

% nice ionice -c3 trinity --network-id=1 --sync-mode=light --discv5 $ETHSTATS_OPTIONS

and then checking if the port is accessible with

% nc -vz localhost 30303

results in this error message being printed:

   ERROR  12-20 17:58:10           LightServer  Unexpected error handling handshake
Traceback (most recent call last):
  File "/home/veox/src/py-evm/trinity/server.py", line 185, in receive_handshake
    await self._receive_handshake(reader, writer)
  File "/home/veox/src/py-evm/trinity/server.py", line 199, in _receive_handshake
    ip, socket, *_ = writer.get_extra_info("peername")
TypeError: cannot unpack non-iterable NoneType object

Not sure if fresh or regression.

How can it be fixed

Not sure.

Checking how "regular" sync mode reacts to this and handles it would be a good start.

veox commented 5 years ago

The "fast" sync variant has:

   ERROR  12-20 18:54:08            FullServer  Unexpected error handling handshake
Traceback (most recent call last):
  File "/home/veox/src/py-evm/trinity/server.py", line 185, in receive_handshake
    await self._receive_handshake(reader, writer)
  File "/home/veox/src/py-evm/trinity/server.py", line 199, in _receive_handshake
    ip, socket, *_ = writer.get_extra_info("peername")
TypeError: cannot unpack non-iterable NoneType object

(Same code path.)

pipermerriam commented 5 years ago

So we use this API:

https://docs.python.org/3/library/asyncio-protocol.html#asyncio.BaseTransport.get_extra_info

Which delegates to this API

https://docs.python.org/3/library/socket.html#socket.socket.getpeername

It looks like we just need to implement some error handling there for the case where that returns None and probably log some information about the connection for debug purposes.

pipermerriam commented 5 years ago

@veox I wasn't able to reproduce this locally, but I'm curious if you would pull #1661 and run it and tell me what happens with the new error handling code.

veox commented 5 years ago

@pipermerriam Works for me. ^_^ (Replied in PR.)

carver commented 5 years ago

Theoretically fixed by #104