Skip to content

"A second operation was started on this context instance…" under simulated latency conditions #855

Open
@marjanoh2

Description

@marjanoh2

Description:
While testing the application with simulated latency using Clumsy (to introduce artificial delays between the app and the database), I frequently encounter the following EF Core exception:

A second operation was started on this context instance before a previous operation completed.

This appears to occur when multiple asynchronous operations are triggered close together, resulting in overlapping usage of the same scoped DbContext.
The error can also occur during rapid component navigation, when an unfinished async database operation is still in progress while a new one begins, both sharing the same scoped DbContext instance.

Question:
Would using IDbContextFactory or DbContextFactory in the handlers be a better and safer long-term approach to prevent this issue—especially under high-latency or concurrent query scenarios?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions