Skip to content

There appears to be a race in the apphost example code #3715

@willdean

Description

@willdean

Type of issue

Code doesn't work

Description

The apphost example code looks like this:

builder.AddProject<Projects.SupportTicketApi_Api>("api")
    .WithReference(sql)
    .WaitFor(sql);

builder.AddProject<Projects.SupportTicketApi_MigrationService>("migrations")
    .WithReference(sql)
    .WaitFor(sql);

This does not appear to create any timing relationship between the api service and the migration service - they both race off the database startup. In our case this meant that the application would (sometimes!) fail because the migrations were incomplete when they were required by the application.

Assigning the migrations service to a local variable and adding .WaitForCompletion(migrations) to the application service fixed this.

Clearly not all applications would suffer like this, but given that this is a general sample, maybe it should assume that the migrations:

  1. are numerous and hence take a discernable amount of time
  2. are needed at startup by the application

A naive newcomer might try WaitFor, but that doesn't for reasons which are (with hindsight) obvious.

Page URL

https://learn.microsoft.com/en-us/dotnet/aspire/database/ef-core-migrations

Content source URL

https://github.com/dotnet/docs-aspire/blob/main/docs/database/ef-core-migrations.md

Document Version Independent Id

570db834-663e-58f9-b714-5938e410ebd5

Platform Id

ee92d915-b4f9-6267-19c1-fd336a24baf2

Article author

@IEvangelist

Related Issues


Associated WorkItem - 444605

Metadata

Metadata

Assignees

Labels

Type

Projects

Status

🔖 Ready

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions