polkascan / py-substrate-interface

Python Substrate Interface
https://polkascan.github.io/py-substrate-interface/
Apache License 2.0
239 stars 111 forks source link

RecursionError when initializing new `SubstrateInterface` #355

Open DamianStraszak opened 9 months ago

DamianStraszak commented 9 months ago

Version of library: 1.7.4

I face an issue, which looks quite random, and I cannot really pin down exact circumstances when this happens, but it's kind of weird. Roughly the scenario is as follows:

1) I initialize one SubstrateInterface with endpoint MAINNET_WS = "wss://ws.azero.dev" (although I doubt it matters much) 2) I do a lot of smart contract queries (reads) on different contracts 3) I try to initialize another instrance of SubstrateInterface, with the same WS (sometimes the error happens, sometimes it doesn't) after which I get

File "[REDACTED]/updater.py", line 171, in mainnet
    return SubstrateInterface(MAINNET_WS)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "[REDACTED]/lib/python3.11/site-packages/substrateinterface/base.py", line 101, in __init__
    runtime_config = RuntimeConfigurationObject()
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "[REDACTED]/lib/python3.11/site-packages/scalecodec/base.py", line 58, in __init__
    self.clear_type_registry()
  File "[REDACTED]/lib/python3.11/site-packages/scalecodec/base.py", line 205, in clear_type_registry
    cls.__name__.lower(): cls for cls in self.all_subclasses(ScaleDecoder)
                                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "[REDACTED]/lib/python3.11/site-packages/scalecodec/base.py", line 52, in all_subclasses
    [s for c in class_.__subclasses__() for s in cls.all_subclasses(c)])
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "[REDACTED]/lib/python3.11/site-packages/scalecodec/base.py", line 52, in <listcomp>
    [s for c in class_.__subclasses__() for s in cls.all_subclasses(c)])
                                                 ^^^^^^^^^^^^^^^^^^^^^
  File "[REDACTED]/lib/python3.11/site-packages/scalecodec/base.py", line 52, in all_subclasses
    [s for c in class_.__subclasses__() for s in cls.all_subclasses(c)])
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

... LOTS OF LINES ....

  File "[REDACTED]/lib/python3.11/site-packages/scalecodec/base.py", line 51, in all_subclasses
    return set(class_.__subclasses__()).union(
               ^^^^^^^^^^^^^^^^^^^^^^^
RecursionError: maximum recursion depth exceeded while calling a Python object

I tried to create a minimal example when this happens, but it happens quite rarily, and somehow only when I run a large piece of code that does lots of stuff :/