ERROR:__main__:Error during shutdown: object NoneT...
# ask-ai
c
ERROR main Error during shutdown: object NoneType can't be used in 'await' expression
t
Thanks for reaching out, Hai. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
It looks like this error happens when an
await
is used on a variable or function call that ends up being
None
. This is quite common during shutdown, especially when cleanup routines try to
await
asynchronous close methods on objects that might not have been properly initialized. A good way to fix this is by checking if an object isn’t
None
before you await its asynchronous close method. Here’s a simple example you can follow:
Copy code
async def _safe_shutdown(self):
    if self._proc_pool is not None:
        await self._proc_pool.aclose()

    if self._http_session is not None:
        await self._http_session.close()

    if self._http_server is not None:
        await self._http_server.aclose()

    if self._inference_executor is not None:
        await self._inference_executor.aclose()

    if self._prometheus_server is not None:
        await self._prometheus_server.aclose()

    if self._api is not None:
        await self._api.aclose()

    await asyncio.gather(*self._tasks, return_exceptions=True)
    self._msg_chan.close()
    await self._close_future
This approach helps make sure you’re never awaiting
None
, which should prevent that error from popping up. If you have any more questions or want me to walk you through this further, just let me know—I’m here to help! Sources: livekit-agents/livekit/agents/voice/agent.py | rag/rag_handler.py