Skip to content

Fix installing on LiteDB and the first concurrent requests after a start (2.4.x) - #1025

Merged
KrzysztofPajak merged 2 commits into
2.4.xfrom
fix/2.4.x-litedb
Nov 5, 2026
Merged

KrzysztofPajak merged 2 commits into
2.4.xfrom
fix/2.4.x-litedb

Conversation

@KrzysztofPajak

Copy link
Copy Markdown
Member

Type: bugfix

The LiteDB part of #997 and #1004, for 2.4.x.

Issue

  • A new installation on LiteDB fails with "The process cannot access the file '...\App_Data\database.db' because it is being used by another process." InstallationService.CreateTables opened a database context before it checked the provider, which on LiteDB is a second LiteDatabase on the file the registered one already holds (Fix installing on LiteDB #997).
  • The first concurrent requests after a start can fail. LiteDB 5.0.21 publishes an entity mapper before it fills its members, and reads it outside the lock. The first concurrent use of a type gave "Collection was modified", "Member Id not found" or objects with missing fields.
  • The gift voucher query by purchased order item threw on LiteDB for a voucher created by hand, which made deleting an order return 500. The order query by billing last name threw for an address without a last name.

Solution

  • CreateTables opens the database context only for MongoDB (Fix installing on LiteDB #997, cherry-picked).
  • LiteDBMapperWarmup builds the mappers of every BaseEntity type, their nested, base and interface types, while startup is still single-threaded. StartupApplication calls it for all entities, those of uninstalled plugins included, and the API module for its models (LiteDbMapperStartup).
  • The two queries check for null first.

Not included from #1004: removing the Database:Singleton option. It stays on 2.4.x so existing configuration does not change. The time zone, guest save and first-click fixes are already on 2.4.x (#1006).

No new resources, settings or migrations. MongoDB installations are not affected.

Breaking changes

None.

Testing

Unit tests pass: Grand.Business.Checkout.Tests (246), Grand.Data.Tests (89), Grand.Infrastructure.Tests (167), Grand.Module.Api.Tests (41). The two new query tests fail without the null checks.

Run on this branch (Release build, Kestrel, Database__UseLiteDb=true):

  1. Install on LiteDB with sample data: it completes (16 s) and reports the application as installed.
  2. Restart and send 56 concurrent storefront requests right after the start (home, categories, search, blog, news, account pages), 8 times: 0 of 448 failed.
  3. The same with the warm-up call disabled, 3 times: 1 of 168 returned 500 with "Collection was modified".

KrzysztofPajak and others added 2 commits November 4, 2026 20:33
CreateTables opened a database context before checking the provider. For
LiteDB that is a second LiteDatabase on the file the one registered in DI
already holds, so the installation failed with "being used by another
process". The context is only needed for MongoDB and is now created there.

Co-authored-by: support <support@grandnode.com>
(cherry picked from commit b136c22)
…nst nulls

Backport from #1004, without removing the Database:Singleton option:
- LiteDB 5.0.21 publishes an entity mapper before its members are filled, so the first concurrent requests for a type could fail or read objects with missing fields. StartupApplication builds the mappers of all entities, including those of uninstalled plugins, while startup is still single-threaded. The API module does the same for its models.
- The gift voucher query by purchased order item and the order query by billing last name no longer throw on LiteDB for a voucher created by hand or an address without a last name.
@KrzysztofPajak
KrzysztofPajak merged commit 5d8c5da into 2.4.x Nov 5, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant