Fix Race condition in OnPublishComplete#3837
Merged
Merged
Conversation
The catch block in OnPublishComplete reads m_subscriptions.Count and
m_subscriptions.Any(s => s.Created) without holding m_lock, while all
other accesses (AddSubscription, RemoveSubscriptionAsync,
RemoveTransferredSubscription) correctly lock before modifying the list.
This causes an InvalidOperationException ("Collection was modified;
enumeration operation may not execute") when a publish response errors
concurrently with a subscription being removed during reconnect.
Snapshot both values under m_lock, consistent with all other call sites.
marcschier
approved these changes
Jun 3, 2026
Contributor
|
@marcschier is this fix also needed for master (ClassicSubscriptionEngine) |
Closed
7 tasks
Collaborator
No, we already lock and copy in master. The copilot provided fix was just replacing linq Any, which would make it faster, sure, but this is on exception path, so lets leave for now. |
5 tasks
This was referenced Jun 26, 2026
GoetzGoerisch
pushed a commit
to umati/connect
that referenced
this pull request
Jul 2, 2026
…5.378.152 (#21) This PR contains the following updates: | Package | Change | [Age](https://docs.renovatebot.com/merge-confidence/) | [Confidence](https://docs.renovatebot.com/merge-confidence/) | |---|---|---|---| | [OPCFoundation.NetStandard.Opc.Ua](https://github.com/OPCFoundation/UA-.NETStandard) | `1.5.378.145` → `1.5.378.152` |  |  | --- ### Release Notes <details> <summary>OPCFoundation/UA-.NETStandard (OPCFoundation.NetStandard.Opc.Ua)</summary> ### [`v1.5.378.152`](https://github.com/OPCFoundation/UA-.NETStandard/releases/tag/1.5.378.152): OPC UA 1.05 Maintenance Update [Compare Source](OPCFoundation/UA-.NETStandard@1.5.378.145...1.5.378.152) Maintenance Release for fixing bugs found on the main378 development branch. #### Released packages [OPCFoundation.NetStandard.Opc.Ua](https://www.nuget.org/packages/OPCFoundation.NetStandard.Opc.Ua/1.5.378.152) [OPCFoundation.NetStandard.Opc.Ua.Core](https://www.nuget.org/packages/OPCFoundation.NetStandard.Opc.Ua.Core/1.5.378.152) [OPCFoundation.NetStandard.Opc.Ua.Security.Certificates](https://www.nuget.org/packages/OPCFoundation.NetStandard.Opc.Ua.Security.Certificates/1.5.378.152) [OPCFoundation.NetStandard.Opc.Ua.Configuration](https://www.nuget.org/packages/OPCFoundation.NetStandard.Opc.Ua.Configuration/1.5.378.152) [OPCFoundation.NetStandard.Opc.Ua.Server](https://www.nuget.org/packages/OPCFoundation.NetStandard.Opc.Ua.Server/1.5.378.152) [OPCFoundation.NetStandard.Opc.Ua.Client](https://www.nuget.org/packages/OPCFoundation.NetStandard.Opc.Ua.Client/1.5.378.152) [OPCFoundation.NetStandard.Opc.Ua.Client.ComplexTypes](https://www.nuget.org/packages/OPCFoundation.NetStandard.Opc.Ua.Client.ComplexTypes/1.5.378.152) [OPCFoundation.NetStandard.Opc.Ua.Bindings.Https](https://www.nuget.org/packages/OPCFoundation.NetStandard.Opc.Ua.Bindings.Https/1.5.378.152) [OPCFoundation.NetStandard.Opc.Ua.PubSub](https://www.nuget.org/packages/OPCFoundation.NetStandard.Opc.Ua.PubSub/1.5.378.152) #### What's Changed - Fix memory leak: dispose linked CancellationTokenSource in ChannelAsyncOperation.EndAsync by [@​romanett](https://github.com/romanett) with [@​Copilot](https://github.com/Copilot) in [#​3812](OPCFoundation/UA-.NETStandard#3812) - Fix Race condition in OnPublishComplete by [@​markuswallen](https://github.com/markuswallen) in [#​3837](OPCFoundation/UA-.NETStandard#3837) - \[master378] Use request.SessionId instead of request.Session.Id in the ReportAuditCancelEvent call from CancelRequests. by [@​mrsuciu](https://github.com/mrsuciu) in [#​3853](OPCFoundation/UA-.NETStandard#3853) - Prune extra decoded children that should stay on the type definition only. by [@​mrsuciu](https://github.com/mrsuciu) in [#​3843](OPCFoundation/UA-.NETStandard#3843) - \[Server] Fix NRE in ActivateSession if Session times out before activation completes by [@​romanett](https://github.com/romanett) in [#​3844](OPCFoundation/UA-.NETStandard#3844) - \[Server] Fix [#​3896](OPCFoundation/UA-.NETStandard#3896): send full certificate chain when CA is in the issuer store (1.5.x) by [@​marcschier](https://github.com/marcschier) in [#​3898](OPCFoundation/UA-.NETStandard#3898) - Synchronize ConditionState branch collection access by [@​marcschier](https://github.com/marcschier) with [@​Copilot](https://github.com/Copilot) in [#​3895](OPCFoundation/UA-.NETStandard#3895) - Prepare 1.5.378 maintenence release by [@​mrsuciu](https://github.com/mrsuciu) in [#​3893](OPCFoundation/UA-.NETStandard#3893) **Full Changelog**: <OPCFoundation/UA-.NETStandard@1.5.378.145...1.5.378.152> </details> --- ### Configuration 📅 **Schedule**: (UTC) - Branch creation - Between 12:00 AM and 03:59 AM (`* 0-3 * * *`) - Automerge - At any time (no schedule defined) 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0My4yNDIuMCIsInVwZGF0ZWRJblZlciI6IjQzLjI0Mi4wIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6W119--> Reviewed-on: https://codeberg.org/umati/connect/pulls/21
GoetzGoerisch
pushed a commit
to umati/connect
that referenced
this pull request
Jul 2, 2026
…r to 1.5.378.152 (#22) This PR contains the following updates: | Package | Change | [Age](https://docs.renovatebot.com/merge-confidence/) | [Confidence](https://docs.renovatebot.com/merge-confidence/) | |---|---|---|---| | [OPCFoundation.NetStandard.Opc.Ua.Server](https://github.com/OPCFoundation/UA-.NETStandard) | `1.5.378.145` → `1.5.378.152` |  |  | --- ### Release Notes <details> <summary>OPCFoundation/UA-.NETStandard (OPCFoundation.NetStandard.Opc.Ua.Server)</summary> ### [`v1.5.378.152`](https://github.com/OPCFoundation/UA-.NETStandard/releases/tag/1.5.378.152): OPC UA 1.05 Maintenance Update [Compare Source](OPCFoundation/UA-.NETStandard@1.5.378.145...1.5.378.152) Maintenance Release for fixing bugs found on the main378 development branch. #### Released packages [OPCFoundation.NetStandard.Opc.Ua](https://www.nuget.org/packages/OPCFoundation.NetStandard.Opc.Ua/1.5.378.152) [OPCFoundation.NetStandard.Opc.Ua.Core](https://www.nuget.org/packages/OPCFoundation.NetStandard.Opc.Ua.Core/1.5.378.152) [OPCFoundation.NetStandard.Opc.Ua.Security.Certificates](https://www.nuget.org/packages/OPCFoundation.NetStandard.Opc.Ua.Security.Certificates/1.5.378.152) [OPCFoundation.NetStandard.Opc.Ua.Configuration](https://www.nuget.org/packages/OPCFoundation.NetStandard.Opc.Ua.Configuration/1.5.378.152) [OPCFoundation.NetStandard.Opc.Ua.Server](https://www.nuget.org/packages/OPCFoundation.NetStandard.Opc.Ua.Server/1.5.378.152) [OPCFoundation.NetStandard.Opc.Ua.Client](https://www.nuget.org/packages/OPCFoundation.NetStandard.Opc.Ua.Client/1.5.378.152) [OPCFoundation.NetStandard.Opc.Ua.Client.ComplexTypes](https://www.nuget.org/packages/OPCFoundation.NetStandard.Opc.Ua.Client.ComplexTypes/1.5.378.152) [OPCFoundation.NetStandard.Opc.Ua.Bindings.Https](https://www.nuget.org/packages/OPCFoundation.NetStandard.Opc.Ua.Bindings.Https/1.5.378.152) [OPCFoundation.NetStandard.Opc.Ua.PubSub](https://www.nuget.org/packages/OPCFoundation.NetStandard.Opc.Ua.PubSub/1.5.378.152) #### What's Changed - Fix memory leak: dispose linked CancellationTokenSource in ChannelAsyncOperation.EndAsync by [@​romanett](https://github.com/romanett) with [@​Copilot](https://github.com/Copilot) in [#​3812](OPCFoundation/UA-.NETStandard#3812) - Fix Race condition in OnPublishComplete by [@​markuswallen](https://github.com/markuswallen) in [#​3837](OPCFoundation/UA-.NETStandard#3837) - \[master378] Use request.SessionId instead of request.Session.Id in the ReportAuditCancelEvent call from CancelRequests. by [@​mrsuciu](https://github.com/mrsuciu) in [#​3853](OPCFoundation/UA-.NETStandard#3853) - Prune extra decoded children that should stay on the type definition only. by [@​mrsuciu](https://github.com/mrsuciu) in [#​3843](OPCFoundation/UA-.NETStandard#3843) - \[Server] Fix NRE in ActivateSession if Session times out before activation completes by [@​romanett](https://github.com/romanett) in [#​3844](OPCFoundation/UA-.NETStandard#3844) - \[Server] Fix [#​3896](OPCFoundation/UA-.NETStandard#3896): send full certificate chain when CA is in the issuer store (1.5.x) by [@​marcschier](https://github.com/marcschier) in [#​3898](OPCFoundation/UA-.NETStandard#3898) - Synchronize ConditionState branch collection access by [@​marcschier](https://github.com/marcschier) with [@​Copilot](https://github.com/Copilot) in [#​3895](OPCFoundation/UA-.NETStandard#3895) - Prepare 1.5.378 maintenence release by [@​mrsuciu](https://github.com/mrsuciu) in [#​3893](OPCFoundation/UA-.NETStandard#3893) **Full Changelog**: <OPCFoundation/UA-.NETStandard@1.5.378.145...1.5.378.152> </details> --- ### Configuration 📅 **Schedule**: (UTC) - Branch creation - Between 12:00 AM and 03:59 AM (`* 0-3 * * *`) - Automerge - At any time (no schedule defined) 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0My4yNDIuMCIsInVwZGF0ZWRJblZlciI6IjQzLjI0OS41IiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6W119--> Reviewed-on: https://codeberg.org/umati/connect/pulls/22
This was referenced Jul 4, 2026
Closed
This was referenced Jul 13, 2026
Open
Closed
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
The catch block in OnPublishComplete reads m_subscriptions.Count and m_subscriptions.Any(s => s.Created) without holding m_lock, while all other accesses (AddSubscription, RemoveSubscriptionAsync, RemoveTransferredSubscription) correctly lock before modifying the list.
This causes an InvalidOperationException ("Collection was modified; enumeration operation may not execute") when a publish response errors concurrently with a subscription being removed during reconnect.
Snapshot both values under m_lock, consistent with all other call sites.
Related Issues
Checklist
Put an
xin the boxes that apply. You can complete these step by step after opening the PR.