Scope FileType handles to Sessions (OPC 10000-5)#4048
Conversation
Bind opaque file handles to the opening Session, reject cross-Session access, and close owned handles when the Session closes. Implements OPC 10000-5 Section 6.2.5.2 and documents the Session-scoped lifetime. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Note
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Scopes server-side FileType file handles to the owning OPC UA Session, preventing cross-session handle reuse and ensuring handles are closed when their session ends (per OPC 10000-5).
Changes:
- Bind open file streams to the Session that opened them and reject handle operations from other Sessions.
- Add
SessionClosingAsynccleanup to close only the departing Session’s file handles. - Update/extend unit tests and client documentation to cover/describe session-bound handle behavior.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/Opc.Ua.Server.Tests/FileSystem/FileObjectStateTests.cs | Adds session-aware FileObjectState tests (opaque handles, session validation, session-closing behavior). |
| tests/Opc.Ua.Server.Tests/FileSystem/FileHandleTests.cs | Updates FileHandle tests to pass session id and assert opaque/non-zero handles. |
| tests/Opc.Ua.Server.Tests/FileSystem/DirectoryObjectStateTests.cs | Updates test context to include a Session for session-required operations. |
| src/Opc.Ua.Server/FileSystem/FileSystemNodeManager.cs | Implements SessionClosingAsync to close handles owned by the closing session. |
| src/Opc.Ua.Server/FileSystem/FileObjectState.cs | Requires Session for Open/Read/Write/Seek/Close; adds session-id extraction helper. |
| src/Opc.Ua.Server/FileSystem/FileHandle.cs | Tracks session ownership per handle; generates opaque handles; adds CloseSession. |
| src/Opc.Ua.Server/FileSystem/DirectoryObjectState.cs | Requires Session when CreateFile requests an open handle. |
| docs/FileSystemClient.md | Documents that server file handles are opaque and session-bound with session-lifetime cleanup. |
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #4048 +/- ##
==========================================
+ Coverage 73.55% 73.59% +0.04%
==========================================
Files 1345 1345
Lines 180036 180182 +146
Branches 31677 31704 +27
==========================================
+ Hits 132427 132612 +185
+ Misses 36911 36858 -53
- Partials 10698 10712 +14
🚀 New features to boost your workflow:
|
Description
This focused draft extracts the FileType handle ownership fix from #4021. It contains only the server FileSystem handle implementation, focused tests, and FileSystem client documentation.
Failure
FileHandleissued predictable per-file identifiers without recording the owning Session. A different Session that obtained a handle could read, write, seek, or close the stream, and open streams survived Session closure.Fix
Open.FileType.Open,CreateFilewhen it requests an open handle, and all subsequent handle operations.FileSystemNodeManager.SessionClosingAsync.OPC 10000-5 Section 6.2.5.2, Table 27 states that a
fileHandleis valid only for the Session used to callOpenand that the Server shall automatically close the file when that Session closes.Tests
dotnet test tests\Opc.Ua.Server.Tests\Opc.Ua.Server.Tests.csproj -f net10.0 --filter "FullyQualifiedName~FileHandleTests|FullyQualifiedName~FileObjectStateTests|FullyQualifiedName~DirectoryObjectStateTests" --no-restore: 71 passed.dotnet test tests\Opc.Ua.Server.Tests\Opc.Ua.Server.Tests.csproj -f net48 --filter "FullyQualifiedName~FileHandleTests|FullyQualifiedName~FileObjectStateTests|FullyQualifiedName~DirectoryObjectStateTests" --no-restore: 71 passed.Both builds emitted the same existing CA1873 warnings in unchanged
Opc.Ua.Clientfiles; the changed files produced no warnings.Related Issues
Checklist