aleph-im / aleph-vm

Aleph.im VM execution engine

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ASGI Lifespan Protocol needs to be implemented

MHHukiewitz opened this issue · comments

Is your feature request related to a problem? Please describe.
When using lifespan events for executing code on startup or shutdown of a VM, like described in the FastAPI Docs, then this will work on apps being run with uvicorn, but not when deployed on Aleph.

Describe the solution you'd like

  • On-demand, as well as persistent VMs, should have their ASGI lifespan events invoked.
  • Ideally, we can autodetect lifespan events like in Uvicorn
  • Lifespan events should belong to the code subject to timeout requirements and may be interrupted if not respecting those

Describe alternatives you've considered

  • Optionally add a "lifespan" config for VMs to explicitly enforce that these events are being sent to the VM or not
  • Stop VM execution if lifespan.startup failed and "lifespan" config is set to true

Additional context
Currently, timeouts are realized at the firecracker_microvm.py level:

return await asyncio.wait_for(
    communicate(reader, writer, scope),
    timeout=self.hardware_resources.seconds,
)

This should be rather on the VmExecution level, given that we might also use other VM jailers. If for any reason startup and shutdown procedures are taking longer than expected, then this should not go "unbilled".

This was merged.