YongGoose opened a new issue, #1040:
URL: https://github.com/apache/burr/issues/1040

   ### Current behavior
   
   When the Burr UI is mounted inside another FastAPI app with 
`mount_burr_ui()` (#503, #671), its lifespan never runs:
   
   - `GET /burr/ready` returns 503 `Backend is not ready yet.` for as long as 
the server is up.
   - The work in the UI's `lifespan()` never happens: `backend.lifespan(app)`, 
`download_snapshot()`, and starting the `sync_index()` / `save_snapshot()` jobs 
(`burr/tracking/server/run.py`).
   
   Starlette does not run the lifespan of a mounted sub-app. Only the top-level 
app's lifespan runs, and `mount_burr_ui()` just calls `parent_app.mount(path, 
ui_app)`.
   
   ### Steps to replicate behavior
   
   Using the repo's own example, `examples/fastapi_mount_example.py`:
   
   ```bash
   BURR_SERVE_STATIC=false uvicorn examples.fastapi_mount_example:app --port 
8003
   curl -i localhost:8003/burr/ready
   # HTTP/1.1 503 Service Unavailable
   # {"detail":"Backend is not ready yet."}
   ```
   
   The same UI run on its own (`create_burr_ui_app()`) returns `200 {"ready": 
true}`.
   
   Or with `TestClient`, which runs the parent app's lifespan:
   
   ```python
   from fastapi import FastAPI
   from fastapi.testclient import TestClient
   from burr.tracking.server.run import mount_burr_ui
   
   parent = FastAPI()
   mount_burr_ui(parent, path="/burr", serve_static=False)
   with TestClient(parent) as client:
       print(client.get("/burr/ready").status_code)  # 503
   ```
   
   ### Expected behavior
   
   The mounted UI starts like a standalone one: `/burr/ready` returns 200 and 
the backend's startup runs.
   
   ### Library & system information
   
   - burr: `main` at 36e3ff3
   - Python 3.12, FastAPI 0.162.2, Starlette 1.10.0, macOS
   - I tested this with the default local backend only. I have not tried the S3 
backend, but its startup goes through the same lifespan.
   
   ### Proposed fix
   
   In `mount_burr_ui()`, wrap the parent app's `router.lifespan_context` so the 
UI's lifespan runs around it, keeping the parent's own lifespan and any state 
it yields. I'll open a PR.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to