Repository: Chia-Network/chia-blockchain

Issue:
[Bug] Python 3.10.8 causes full node to be unable to connect to peers
### What happened?

After upgrading Arch Linux, which upgrades python to 3.10.8, I found that the full node was unable to connect to any peers and sync, and there were python errors in the log. I tried to downgrade chia to 1.5.1 and the problem remained. I downgraded python to 3.10.7 and the issue was resolved in both chia v1.5.1 and v1.6.0.

### Version

1.6.0

### What platform are you using?

Linux

### What ui mode are you using?

CLI

### Relevant log output

```shell
2022-10-15T01:17:43.272 full_node full_node_server        : ERROR    Exception: object of type 'NoneType' has no len(), {'host': 'xx.xx.xx.xx', 'port': 8444}. Traceb
ack (most recent call last):
  File "/home/server/chia-blockchain/chia/server/server.py", line 597, in wrapped_coroutine
    result = await coroutine
  File "/home/server/chia-blockchain/chia/full_node/full_node_api.py", line 114, in new_peak
    waiter_count = len(self.full_node.new_peak_sem._waiters)
TypeError: object of type 'NoneType' has no len()

2022-10-15T01:17:43.273 full_node full_node_server        : ERROR    Exception: object of type 'NoneType' has no len() <class 'TypeError'>, closing connection {'host':
'xx.xx.xx.xx', 'port': 8444}. Traceback (most recent call last):
  File "/home/server/chia-blockchain/chia/server/server.py", line 607, in api_call
    response: Optional[Message] = await asyncio.wait_for(wrapped_coroutine(), timeout=timeout)
  File "/usr/lib/python3.10/asyncio/tasks.py", line 408, in wait_for
    return await fut
  File "/home/server/chia-blockchain/chia/server/server.py", line 604, in wrapped_coroutine
    raise e
  File "/home/server/chia-blockchain/chia/server/server.py", line 597, in wrapped_coroutine
    result = await coroutine
  File "/home/server/chia-blockchain/chia/full_node/full_node_api.py", line 114, in new_peak
    waiter_count = len(self.full_node.new_peak_sem._waiters)
TypeError: object of type 'NoneType' has no len()
```



Discussion:

Resolving patch:
diff --git a/chia/full_node/full_node_api.py b/chia/full_node/full_node_api.py
--- a/chia/full_node/full_node_api.py
+++ b/chia/full_node/full_node_api.py
@@ -122,7 +122,8 @@ async def new_peak(self, request: full_node_protocol.NewPeak, peer: ws.WSChiaCon
         """
         # this semaphore limits the number of tasks that can call new_peak() at
         # the same time, since it can be expensive
-        waiter_count = len(self.full_node.new_peak_sem._waiters)
+        new_peak_sem = self.full_node.new_peak_sem
+        waiter_count = 0 if new_peak_sem._waiters is None else len(new_peak_sem._waiters)
 
         if waiter_count > 0:
             self.full_node.log.debug(f"new_peak Waiters: {waiter_count}")
@@ -130,7 +131,7 @@ async def new_peak(self, request: full_node_protocol.NewPeak, peer: ws.WSChiaCon
         if waiter_count > 20:
             return None
 
-        async with self.full_node.new_peak_sem:
+        async with new_peak_sem:
             await self.full_node.new_peak(request, peer)
         return None
 
@@ -1436,7 +1437,9 @@ async def new_compact_vdf(
         if self.full_node.sync_store.get_sync_mode():
             return None
 
-        if len(self.full_node.compact_vdf_sem._waiters) > 20:
+        compact_vdf_sem = self.full_node.compact_vdf_sem
+        waiter_count = 0 if compact_vdf_sem._waiters is None else len(compact_vdf_sem._waiters)
+        if waiter_count > 20:
             self.log.debug(f"Ignoring NewCompactVDF: {request}, _waiters")
             return None
 


Test patch: