Skip to content

[Repo Assist] fix: dispose SHA1 instance in Caching.hashString; use SHA1.HashData on .NET 5+#1745

Draft
github-actions[bot] wants to merge 2 commits intomainfrom
repo-assist/improve-sha1-disposal-caching-2026-04-16-f466c854a7d11c78
Draft

[Repo Assist] fix: dispose SHA1 instance in Caching.hashString; use SHA1.HashData on .NET 5+#1745
github-actions[bot] wants to merge 2 commits intomainfrom
repo-assist/improve-sha1-disposal-caching-2026-04-16-f466c854a7d11c78

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

🤖 This is an automated pull request from Repo Assist, an AI assistant for this repository.

Summary

Fixes a resource leak in Caching.fsSHA1.Create() returned a HashAlgorithm (IDisposable) that was never disposed.

Before

let hashBytes = SHA1.Create().ComputeHash(plainTextBytes)
//              ^^^^^^^^^^^^ IDisposable never disposed

After

let hashBytes =
#if NET5_0_OR_GREATER
    SHA1.HashData(plainTextBytes)     // static, no instance, no disposal needed
#else
    use sha1 = SHA1.Create()          // properly disposed via 'use'
    sha1.ComputeHash(plainTextBytes)
#endif

Details

  • netstandard2.0: Wraps the SHA1 instance in use for deterministic disposal — this is the HashAlgorithm.Dispose() path that frees any unmanaged resources.
  • net8.0 (NET5_0_OR_GREATER): Uses SHA1.HashData(byte[]), the static API introduced in .NET 5 that avoids creating a disposable object entirely. This is the idiomatic modern approach.

hashString is called only at design-time (to derive a cache file name from a URL), so the performance impact is negligible — the value here is correctness and clean resource handling.

Test Status

  • dotnet build src/FSharp.Data.Runtime.Utilities/0 errors
  • dotnet test tests/FSharp.Data.Core.Tests/2920 passed, 0 failed
  • ✅ Fantomas format check passed

Generated by Repo Assist

Generated by 🌈 Repo Assist, see workflow run. Learn more.

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@97143ac59cb3a13ef2a77581f929f06719c7402a

…n .NET 5+

On netstandard2.0, SHA1.Create() returns a HashAlgorithm (IDisposable)
that was never disposed — a small but genuine resource leak.

On .NET 5+, use the static SHA1.HashData(byte[]) method which avoids
creating a disposable instance entirely and is the idiomatic modern API.
On netstandard2.0, wrap the instance in 'use' to ensure deterministic
disposal.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants