Skip to content

Condition's branch collection (ConditionState.m_branches) accessed from multiple threads without synchronization, resulting in crashes #3894

Description

@marcschier

Type of issue

  • Bug
  • Enhancement
  • Compliance
  • Question
  • Help wanted

Current Behavior

The OPC UA stack (OPCFoundation.NetStandard.Opc.Ua.Core 1.5.378.145) accesses a condition's branch collection (ConditionState.m_branches, a plain Dictionary<string, ConditionState>) from multiple threads without synchronization:

Readers: ConditionState.GetRetainState (via UpdateRetainState), ConditionState.ConditionRefresh, GetBranch
Writers: ConditionState.CreateBranch, ReplaceBranchEvent, RemoveBranchEvent, ClearBranches
When a condition's state changes on a background thread while the branch dictionary is concurrently enumerated, the enumeration can observe a torn/garbage entry and dereference it, crashing the process with a native access violation (observed as Opc.Ua.ConditionState.IsBranch on a null this).

This is on 1.5.378.145, therefore, could be on master378, but also on master branch, both - if exist - should be fixed.

Expected Behavior

No response

Steps To Reproduce

No response

Environment

- OS:
- Environment:
- Runtime:
- Nuget Version:
- Component:
- Server:
- Client:

Anything else?

No response

Metadata

Metadata

Labels

bugA bug was identified and should be fixed.

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions