aspire icon indicating copy to clipboard operation
aspire copied to clipboard

SQLServer `.WithDataVolume()` fails to start if you restart aspire too quickly

Open afscrome opened this issue 9 months ago • 1 comments

If you have a sql server configured WithDataVolume(), then if you try to restart aspire too quickly after closing the last session, then SQL server will fail to start up complaining that another instance is already running

2024-05-02T16:55:55.8514747 /opt/mssql/bin/sqlservr: Another instance of the application is already running.

This can be reproduced by restarting aspire whilst a session is already in progress. (e.g. by going to Debug > Start without Debugging in Visual Studio whilst the project is already running.)

The problem seems to be that the new instance of aspire will start the sql server container before the old one has terminated. If you run the following command, you'll see there's a period when there are two containers trying to access the same data volume

while($true) {
  docker ps --filter Volume=MYAPP-SqlServer-data
  Start-Sleep -Milliseconds 200
}

Example output:

CONTAINER ID   IMAGE      COMMAND                  CREATED          STATUS                  PORTS                       NAMES
a86f794e0650   REDACTED   "/bin/bash /app/entr…"   1 second ago     Up Less than a second   127.0.0.1:32796->1433/tcp   SqlServer-b16k6ig
d8f04623bf55   REDACTED   "/bin/bash /app/entr…"   26 seconds ago   Up 25 seconds           127.0.0.1:32794->1433/tcp   SqlServer-ae1fag8

When WithDataVolume() is used with sql server, aspire should and make sure the volume is no longer in use before starting the new instance of SQL Server.

afscrome avatar May 02 '24 16:05 afscrome