A dependency with yield has exit code after the yield that FastAPI runs when the request finishes. Before FastAPI 0.106.0 that exit code ran after background tasks completed, so a background task could keep using a database session opened by the dependency. From 0.106.0 the exit code runs before the response is sent, and therefore before background tasks run.
The symptom after upgrading is a background task failing on a closed resource, typically a SQLAlchemy error about the session being closed or a detached instance, and only under load or in production where the timing is visible.
The fix is to create the resource inside the background task function rather than passing one in. Open a fresh session there, or move the work to a real task queue if it is long-running. This is also why a dependency with yield should not be used to hold something that must outlive the response. To confirm the behaviour in a given version, log inside the exit block and inside the background task and compare the ordering.