Skip to content

Fix memory leak: dispose linked CancellationTokenSource in ChannelAsyncOperation.EndAsync#3812

Merged
marcschier merged 1 commit into
master378from
copilot/investigate-issue-3809
May 28, 2026
Merged

Fix memory leak: dispose linked CancellationTokenSource in ChannelAsyncOperation.EndAsync#3812
marcschier merged 1 commit into
master378from
copilot/investigate-issue-3809

Conversation

Copilot AI commented May 27, 2026

Copy link
Copy Markdown
Contributor

Proposed changes

On pre-.NET 6 targets (.NET Framework 4.8, netstandard2.1), ChannelAsyncOperation.EndAsync creates a CancellationTokenSource via CreateLinkedTokenSource but never disposes it. The linked registration on the parent token accumulates on every service call that passes a non-default CancellationToken, causing gradual memory growth.

- CancellationTokenSource cts = CancellationTokenSource.CreateLinkedTokenSource(ct);
+ using CancellationTokenSource cts = CancellationTokenSource.CreateLinkedTokenSource(ct);

Typical trigger: any polling loop calling ReadAsync (or any other service) with a long-lived CancellationToken. Leak becomes noticeable after 1-2 hours of operation.

Related Issues

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • Enhancement (non-breaking change which adds functionality)
  • Test enhancement (non-breaking change to increase test coverage)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected, requires version increase of Nuget packages)
  • Documentation Update (if none of the other choices apply)

Checklist

  • I have read the CONTRIBUTING doc.
  • I have signed the CLA.
  • I ran tests locally with my changes, all passed.
  • I fixed all failing tests in the CI pipelines.
  • I fixed all introduced issues with CodeQL and LGTM.
  • I have added tests that prove my fix is effective or that my feature works and increased code coverage.
  • I have added necessary documentation (if appropriate).
  • Any dependent changes have been merged and published in downstream modules.

Further comments

The .NET 6+ path uses Task.WaitAsync() which doesn't have this issue. Only the #else fallback path (net48/netstandard2.1) is affected.

…tion.EndAsync (#3809)

On pre-.NET 6 targets (.NET Framework 4.8), CreateLinkedTokenSource was used
without disposal. Each service call with a CancellationToken leaked a linked
CTS registration, causing gradual memory growth.
@romanett
romanett marked this pull request as ready for review May 27, 2026 19:05
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@codecov

codecov Bot commented May 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 60.08%. Comparing base (d621313) to head (6d22a48).

Additional details and impacted files
@@              Coverage Diff              @@
##           master378    #3812      +/-   ##
=============================================
- Coverage      60.09%   60.08%   -0.01%     
=============================================
  Files            378      378              
  Lines          79043    79043              
  Branches       13833    13833              
=============================================
- Hits           47499    47496       -3     
+ Misses         27126    27124       -2     
- Partials        4418     4423       +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@marcschier
marcschier merged commit d1812a0 into master378 May 28, 2026
91 of 92 checks passed
@marcschier
marcschier deleted the copilot/investigate-issue-3809 branch May 28, 2026 05:08
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` | ![age](https://developer.mend.io/api/mc/badges/age/nuget/OPCFoundation.NetStandard.Opc.Ua/1.5.378.152?slim=true) | ![confidence](https://developer.mend.io/api/mc/badges/confidence/nuget/OPCFoundation.NetStandard.Opc.Ua/1.5.378.145/1.5.378.152?slim=true) |

---

### 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 [@&#8203;romanett](https://github.com/romanett) with [@&#8203;Copilot](https://github.com/Copilot) in [#&#8203;3812](OPCFoundation/UA-.NETStandard#3812)
- Fix Race condition in OnPublishComplete by [@&#8203;markuswallen](https://github.com/markuswallen) in [#&#8203;3837](OPCFoundation/UA-.NETStandard#3837)
- \[master378] Use request.SessionId instead of request.Session.Id in the ReportAuditCancelEvent call from CancelRequests. by [@&#8203;mrsuciu](https://github.com/mrsuciu) in [#&#8203;3853](OPCFoundation/UA-.NETStandard#3853)
- Prune extra decoded children that should stay on the type definition only. by [@&#8203;mrsuciu](https://github.com/mrsuciu) in [#&#8203;3843](OPCFoundation/UA-.NETStandard#3843)
- \[Server] Fix NRE in ActivateSession if Session times out before activation completes by [@&#8203;romanett](https://github.com/romanett) in [#&#8203;3844](OPCFoundation/UA-.NETStandard#3844)
- \[Server] Fix [#&#8203;3896](OPCFoundation/UA-.NETStandard#3896): send full certificate chain when CA is in the issuer store (1.5.x) by [@&#8203;marcschier](https://github.com/marcschier) in [#&#8203;3898](OPCFoundation/UA-.NETStandard#3898)
- Synchronize ConditionState branch collection access by [@&#8203;marcschier](https://github.com/marcschier) with [@&#8203;Copilot](https://github.com/Copilot) in [#&#8203;3895](OPCFoundation/UA-.NETStandard#3895)
- Prepare 1.5.378 maintenence release by [@&#8203;mrsuciu](https://github.com/mrsuciu) in [#&#8203;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` | ![age](https://developer.mend.io/api/mc/badges/age/nuget/OPCFoundation.NetStandard.Opc.Ua.Server/1.5.378.152?slim=true) | ![confidence](https://developer.mend.io/api/mc/badges/confidence/nuget/OPCFoundation.NetStandard.Opc.Ua.Server/1.5.378.145/1.5.378.152?slim=true) |

---

### 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 [@&#8203;romanett](https://github.com/romanett) with [@&#8203;Copilot](https://github.com/Copilot) in [#&#8203;3812](OPCFoundation/UA-.NETStandard#3812)
- Fix Race condition in OnPublishComplete by [@&#8203;markuswallen](https://github.com/markuswallen) in [#&#8203;3837](OPCFoundation/UA-.NETStandard#3837)
- \[master378] Use request.SessionId instead of request.Session.Id in the ReportAuditCancelEvent call from CancelRequests. by [@&#8203;mrsuciu](https://github.com/mrsuciu) in [#&#8203;3853](OPCFoundation/UA-.NETStandard#3853)
- Prune extra decoded children that should stay on the type definition only. by [@&#8203;mrsuciu](https://github.com/mrsuciu) in [#&#8203;3843](OPCFoundation/UA-.NETStandard#3843)
- \[Server] Fix NRE in ActivateSession if Session times out before activation completes by [@&#8203;romanett](https://github.com/romanett) in [#&#8203;3844](OPCFoundation/UA-.NETStandard#3844)
- \[Server] Fix [#&#8203;3896](OPCFoundation/UA-.NETStandard#3896): send full certificate chain when CA is in the issuer store (1.5.x) by [@&#8203;marcschier](https://github.com/marcschier) in [#&#8203;3898](OPCFoundation/UA-.NETStandard#3898)
- Synchronize ConditionState branch collection access by [@&#8203;marcschier](https://github.com/marcschier) with [@&#8203;Copilot](https://github.com/Copilot) in [#&#8203;3895](OPCFoundation/UA-.NETStandard#3895)
- Prepare 1.5.378 maintenence release by [@&#8203;mrsuciu](https://github.com/mrsuciu) in [#&#8203;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
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.

4 participants