dotnet / aspire

An opinionated, cloud ready stack for building observable, production ready, distributed applications in .NET
https://learn.microsoft.com/dotnet/aspire
MIT License
3.61k stars 404 forks source link

`WithDataVolume` causes exception when used with Npgsql Entity Framework Core #5138

Closed pomianowski closed 2 days ago

pomianowski commented 1 month ago

Is there an existing issue for this?

Describe the bug

The WithDataVolume() method causes a Npgsql.PostgresException when used in combination with a Postgres database. Specifically, the exception indicates that password authentication fails for the user "postgres". This issue is reproducible when using the specific code variant 2 and 4 in attached minimalistic project (https://github.com/pomianowski/poc-fail-aspire)

Expected Behavior

The application should start and connect to the Postgres database without any authentication issues, even when the WithDataVolume() method is used.

Steps To Reproduce

A minimalistic project to reproduce this issue is provided in the code snippet below: https://github.com/pomianowski/poc-fail-aspire

Exceptions (if any)

Npgsql.PostgresException (0x80004005): 28P01: password authentication failed for user "postgres" at Npgsql.Internal.NpgsqlConnector.ReadMessageLong(Boolean async, DataRowLoadingMode dataRowLoadingMode, Boolean readingNotifications, Boolean isReadingPrependedMessage) at System.Runtime.CompilerServices.PoolingAsyncValueTaskMethodBuilder1.StateMachineBox1.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token) at Npgsql.Internal.NpgsqlConnector.AuthenticateSASL(List`1 mechanisms, String username, Boolean async, CancellationToken cancellationToken) at Npgsql.Internal.NpgsqlConnector.Authenticate(String username, NpgsqlTimeout timeout, Boolean async, CancellationToken cancellationToken) at Npgsql.Internal.NpgsqlConnector.g__OpenCore|213_1(NpgsqlConnector conn, SslMode sslMode, NpgsqlTimeout timeout, Boolean async, CancellationToken cancellationToken, Boolean isFirstAttempt) at Npgsql.Internal.NpgsqlConnector.Open(NpgsqlTimeout timeout, Boolean async, CancellationToken cancellationToken) at Npgsql.UnpooledDataSource.Get(NpgsqlConnection conn, NpgsqlTimeout timeout, Boolean async, CancellationToken cancellationToken) at Npgsql.NpgsqlConnection.g__OpenAsync|42_0(Boolean async, CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenInternalAsync(Boolean errorsExpected, CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenInternalAsync(Boolean errorsExpected, CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenAsync(CancellationToken cancellationToken, Boolean errorsExpected) at Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.NpgsqlDatabaseCreator.Exists(Boolean async, CancellationToken cancellationToken) at Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.NpgsqlDatabaseCreator.Exists(Boolean async, CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.Migrations.HistoryRepository.ExistsAsync(CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.Migrations.HistoryRepository.GetAppliedMigrationsAsync(CancellationToken cancellationToken) at Npgsql.EntityFrameworkCore.PostgreSQL.Migrations.Internal.NpgsqlMigrator.MigrateAsync(String targetMigration, CancellationToken cancellationToken) at AspirePoc.App.DatabaseTesterBackgroundService.FireAndForget() in E:\poc-fail-aspire\AspirePoc.App\DatabaseTesterBackgroundService.cs:line 40 Exception data: Severity: FATAL SqlState: 28P01 MessageText: password authentication failed for user "postgres" File: auth.c Line: 323 Routine: auth_failed

.NET Version info

.NET SDK: Version: 8.0.303 Commit: 29ab8e3268 Workload version: 8.0.300-manifests.d7126b9e MSBuild version: 17.10.4+10fbfbf2e

Runtime Environment: OS Name: Windows OS Version: 10.0.22631 OS Platform: Windows RID: win-x64 Base Path: C:\Program Files\dotnet\sdk\8.0.303\

Anything else?

No response

pomianowski commented 1 month ago

4956 related

davidfowl commented 2 days ago

This was fixed in 8.1, see https://github.com/dotnet/aspire/issues/1151