Fixes Race Condition#352
Draft
FriedJannik wants to merge 1 commit into
Draft
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes a race condition in registry descriptor synchronization when
GENERAL_AASREGISTRYINTEGRATION=true.Concurrent
POST /shells/{id}/submodel-refsrequests could trigger parallel registry upserts for the same AAS descriptor. The previous SELECT/insert-style flow was vulnerable under PostgreSQLREAD COMMITTED, allowing both transactions to observe a missing descriptor and then race on insert, causing duplicate key violations and a 500 response.This change adds coverage for the concurrent submodel-reference creation flow and updates descriptor synchronization to serialize conflicting descriptor upserts by descriptor id. A similar overlapping upsert scope in the submodel registry was also guarded.
Changes
POST /shells/{id}/submodel-refswith registry synchronization enabled.Problem
With
GENERAL_AASREGISTRYINTEGRATION=true, two parallel submodel-reference creations for the same shell could both call the AAS descriptor upsert path. Because the old implementation used a SELECT-before-INSERT pattern, PostgreSQL statement snapshots could allow both transactions to see no existing descriptor. One transaction would insert successfully, while the other failed with a duplicate key violation such as:This surfaced as:
Solution
The AAS registry descriptor upsert now serializes concurrent work for the same descriptor id inside the transaction and updates existing descriptor rows instead of deleting/reinserting the root descriptor row. Dependent descriptor data is replaced transactionally so nested descriptor state stays consistent.
A similar race-prone submodel descriptor upsert path was also protected with transaction-scoped per-descriptor serialization.
Testing
go test -v ./internal/common/descriptors ./internal/aasregistry/persistence ./internal/smregistry/persistencego vet ./internal/common/descriptors ./internal/aasregistry/persistence ./internal/smregistry/persistence ./internal/aasenvironment/integration_testsgo test -v ./internal/aasenvironment/integration_testsgo clean -testcachego test -v ./internal/submodelrepository/integration_testsNotes
The new race test is concurrency-based, so the pre-fix failure is timing dependent. The test verifies the intended behavior: concurrent submodel-reference creation must not return 500 responses and must not lose created references.