DiamondLightSource / coniql

Control system interface in GraphQL
Apache License 2.0
6 stars 4 forks source link

Poor handling of failure to get loop in subscribe_channel #86

Closed AlexanderWells-diamond closed 1 year ago

AlexanderWells-diamond commented 1 year ago

In subscribe_channel in caplugin.py is the code:

try:
    loop = asyncio.get_running_loop()
except RuntimeError:
    # 'RuntimeError: There is no current event loop...'
    coniql_logger.error("No running event loop...", stack_info=True)
    loop = None

And we try to continue if there is no loop. However, all later code checks for whether loop is non-None, and so there's no actual work done if we hit this error case. We should probably fail here - at the least raise an exception that will be propogated back into the GraphQL engine, or possibly even end the process as we're likely to be in a catastrophically bad state if we can't get asyncio loops.

Spotted by @MJGaughran .