Skip to content

Conversation

@verdie-g
Copy link
Contributor

  • ASP.NET Core 3.1 -> 8.0
  • JsonApiDotNetcore 4.2.0-beta -> 5.5.1
  • Npgsql 3.1.11 -> 8.0.2
Copy link
Member

@bkoelman bkoelman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for looking into this! This repo was updated long ago, by a former colleague. I'm very unfamiliar with how it all works.

@bkoelman
Copy link
Member

bkoelman commented Feb 18, 2024

Trying to run this in git-bash on Windows, I'm seeing the following happen:

db-1 | creating configuration files ... ok db-1 | running bootstrap script ... ok db-1 | performing post-bootstrap initialization ... ok test-1 | Waiting an arbitrary amount of time to ensure the database is ready to accept connections : not found/test.sh: line 2: 'est-1 | sleep: invalid number '30 : not found/test.sh: line 5: : not found/test.sh: line 8: test-1 | ./test.sh: line 111: syntax error: unexpected end of file (expecting "then") test-1 | Checking to see if webserver is ready app-1 | Unhandled exception. Npgsql.NpgsqlException (0x80004005): Failed to connect to 172.20.0.2:5432 app-1 | ---> System.Net.Sockets.SocketException (111): Connection refused app-1 | at Npgsql.Internal.NpgsqlConnector.Connect(NpgsqlTimeout timeout) app-1 | at Npgsql.Internal.NpgsqlConnector.Connect(NpgsqlTimeout timeout) app-1 | at Npgsql.Internal.NpgsqlConnector.RawOpen(SslMode sslMode, NpgsqlTimeout timeout, Boolean async, CancellationToken cancellationToken, Boolean isFirstAttempt) app-1 | at Npgsql.Internal.NpgsqlConnector.<Open>g__OpenCore|213_1(NpgsqlConnector conn, SslMode sslMode, NpgsqlTimeout timeout, Boolean async, CancellationToken cancellationToken, Boolean isFirstAttempt) app-1 | at Npgsql.Internal.NpgsqlConnector.Open(NpgsqlTimeout timeout, Boolean async, CancellationToken cancellationToken) app-1 | at Npgsql.UnpooledDataSource.Get(NpgsqlConnection conn, NpgsqlTimeout timeout, Boolean async, CancellationToken cancellationToken) app-1 | at Npgsql.NpgsqlConnection.<Open>g__OpenAsync|42_0(Boolean async, CancellationToken cancellationToken) app-1 | at Npgsql.NpgsqlConnection.Open() app-1 | at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenDbConnection(Boolean errorsExpected) app-1 | at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenInternal(Boolean errorsExpected) app-1 | at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.Open(Boolean errorsExpected) app-1 | at Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.NpgsqlDatabaseCreator.Exists(Boolean async, CancellationToken cancellationToken) app-1 | at Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.NpgsqlDatabaseCreator.Exists(Boolean async, CancellationToken cancellationToken) app-1 | at Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.NpgsqlDatabaseCreator.Exists() app-1 | at Microsoft.EntityFrameworkCore.Storage.RelationalDatabaseCreator.EnsureDeleted() app-1 | at Microsoft.EntityFrameworkCore.Infrastructure.DatabaseFacade.EnsureDeleted() app-1 | at app.Seeder.EnsureSampleData(AppDbContext dbContext) in /app/dotnetapp/Seeder.cs:line 13 app-1 | at Program.<Main>$(String[] args) in /app/dotnetapp/Program.cs:line 23 test-1 exited with code 2 db-1 | initdb: warning: enabling "trust" authentication for local connections db-1 | initdb: hint: You can change this by editing pg_hba.conf or using the option -A, or --auth-local and --auth-host, the next time you run initdb. db-1 | syncing data to disk ... ok 

The sleep doesn't seem to work. Then the app crashes at startup because the db isn't up yet. Are you getting this too? I'm seeing odd quotes in:

'est-1 | sleep: invalid number '30 

I'm wondering if this could be related to line-ending settings? Are you getting the same? Am I doing something wrong?

@verdie-g
Copy link
Contributor Author

Hmm no idea. I should try on Windows. But actually I've been playing with that project a little and there are three main things that could be improved:

  1. JADNC is used through the nuget package so this tool is not really usable to verify the performance diff of a local/recent change
  2. Because it's not in the main repo, it is not enforced to keep the usages of JADNC up to date
  3. Running the app in docker adds a lot of barrier to do proper profiling. For example you can't run perf (1) without relaxing the docker securities

I think I'll make a proposal after I'm done working on OpenAPI.

@verdie-g
Copy link
Contributor Author

verdie-g commented Feb 19, 2024

Hmm okay I got the error Npgsql.NpgsqlException (0x80004005): Failed to connect to 172.20.0.2:5432 but not the bash ones. Restarting the script a second worked though. I think the app can start before the db is ready. But as mentioned above, I'll probably not invest more time on that project.

@bkoelman
Copy link
Member

Hmm okay I got the error Npgsql.NpgsqlException (0x80004005): Failed to connect to 172.20.0.2:5432 but not the bash ones. Restarting the script a second worked though. I think the app can start before the db is ready. But as mentioned above, I'll probably not invest more time on that project.

Nope. It needs the db to be available at startup, otherwise seed data isn't inserted.

@verdie-g
Copy link
Contributor Author

Yes I meant that's probably why it's crashing, there is nothing preventing the app to start before the db.

@verdie-g
Copy link
Contributor Author

I've added some code that waits for the db to be up.

@bkoelman
Copy link
Member

Thanks, that should help. How do I run the orchestration on Windows, using WSL or something?

There are a few more things you can do to update the app to the latest bits:

  • Add to .csproj:
    <Nullable>enable</Nullable> <ImplicitUsings>enable</ImplicitUsings>
  • Use auto-generated controllers (add [Resource] on the model classes) and delete existing controllers
  • Adapt AppDbContext properties to be NRT-friendly, ie:
    public DbSet<TodoItem> TodoItems => Set<TodoItem>();
  • Update the model properties to match with what's in JsonApiDotNetCoreExample (may affect the seeder and load tests)
  • Swap order of members in TodoItemPriority to match with JsonApiDotNetCoreExample
  • Use .NET default location for connection strings instead of Data:DefaultConnection
  • Rename EnsureSampleData to EnsureSampleDataAsync
  • Use app.Services.CreateAsyncScope with await using
  • Temporarily copy in JsonApiDotNetCore.sln.DotSettings (rename accordingly), reformat the solution, and delete it. I don't want to maintain multiple copies, but making the code style look similar to elsewhere would be nice.
@bkoelman
Copy link
Member

As we're on .NET 8 now, should use DbContext pooling, possibly with DbDataSource, needs investigation, there are bugs...

@verdie-g
Copy link
Contributor Author

I'll make a proposal some day to integrate a tool like that in the main repo.

@verdie-g verdie-g closed this Feb 19, 2024
@bkoelman
Copy link
Member

From my point of view, there's value in pursuing this PR. See json-api-dotnet/JsonApiDotNetCore#1472 (comment).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants