Skip to content

Various reliability fixes (mostly in tests) - #1756

Merged
bart-vmware merged 9 commits into
mainfrom
reliability-fixes
Oct 9, 2026
Merged

bart-vmware merged 9 commits into
mainfrom
reliability-fixes

Conversation

@bart-vmware

@bart-vmware bart-vmware commented Oct 9, 2026 •

Copy link
Copy Markdown
Member

Description

This PR fixes leaked resources, such as proper disposal of configuration providers with file system watchers attached, as well as disposing objects related to HttpClient usage. It affects tests for the most part, but also includes a few Steeltoe fixes. Another notable pattern in tests is where a host builder is created, but never built or started, resulting in their resources in IConfiguration never getting disposed.

Before review, start by reading the new pattern in ConfigurationBuilderExtensions (in the TestResources project):

/// There are basically two patterns to ensure configuration providers are properly disposed in tests.
/// <para>
/// <example>
/// 1. Simple tests without a service provider in a using statement:<![CDATA[
/// using var root = new ConfigurationBuilder().Add(...).BuildAsRoot();
/// ]]>
/// </example>
/// </para>
/// <para>
/// <example>
/// 2. Tests where the service provider disposes the configuration by passing a lambda:
/// <![CDATA[
/// var root = new ConfigurationBuilder().Add(...).Build();
/// 
/// var services = new ServiceCollection();
/// services.AddSingleton<IConfiguration>(_ => root);
/// ]]>
/// </example>
/// </para>
public static ConfigurationRoot BuildAsRoot(this IConfigurationBuilder builder)
{
    return (ConfigurationRoot)builder.Build();
}

Why?

  • IConfigurationRoot is not disposable, which is why the BuildAsRoot extension method is being introduced: it allows to track all usages and the callers don't need to cast to ConfigurationRoot (which is disposable).

  • Taking a lambda in AddSingleton ensures ownership is taken, which is not the case when passing an instance directly.

Additionally, see the commit messages for details.

Quality checklist

  • Your code complies with our Coding Style.
  • You've updated unit and/or integration tests for your change, where applicable.
  • You've updated documentation for your change, where applicable.
    If your change affects other repositories, such as Documentation and/or Samples, add linked PRs here.
  • There's an open issue for the PR that you are making. If you'd like to propose a new feature or change, please open an issue to discuss the change or find an existing issue.
  • You've added required license files and/or file headers (explaining where the code came from with proper attribution), where code is copied from StackOverflow, a blog, or OSS.

@github-actions

github-actions Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Summary - All Code Coverage (ubuntu-latest)

Line coverage Branch coverage

Assembly Line coverage Branch coverage
Steeltoe.Bootstrap.AutoConfiguration 97.4% 83.3%
Steeltoe.Common 92.9% 84.4%
Steeltoe.Common.Certificates 95.6% 83.3%
Steeltoe.Common.Hosting 83.5% 65%
Steeltoe.Common.Http 97.2% 80.9%
Steeltoe.Common.Logging 82.9% 56.2%
Steeltoe.Common.Net 64.5% 66.6%
Steeltoe.Configuration.Abstractions 96.3% 89.4%
Steeltoe.Configuration.CloudFoundry 98.4% 92.7%
Steeltoe.Configuration.ConfigServer 92.1% 87.2%
Steeltoe.Configuration.Encryption 97.6% 87.5%
Steeltoe.Configuration.Kubernetes.ServiceBindings 95.6% 82.1%
Steeltoe.Configuration.Placeholder 94% 82.6%
Steeltoe.Configuration.RandomValue 93.2% 83.3%
Steeltoe.Configuration.SpringBoot 98.3% 85%
Steeltoe.Connectors 94.5% 85.5%
Steeltoe.Connectors.EntityFrameworkCore 81% 70.8%
Steeltoe.Discovery.Configuration 96.3% 75%
Steeltoe.Discovery.Consul 91.5% 84.5%
Steeltoe.Discovery.Eureka 90.2% 81.8%
Steeltoe.Discovery.HttpClients 89.9% 91.1%
Steeltoe.Logging.Abstractions 99.4% 95.6%
Steeltoe.Logging.DynamicConsole 100% 92.3%
Steeltoe.Logging.DynamicSerilog 99.1% 95.4%
Steeltoe.Management.Abstractions 100% 100%
Steeltoe.Management.Endpoint 95.9% 86.9%
Steeltoe.Management.GitProperties.Build 95.2% 83.9%
Steeltoe.Management.Prometheus 96.8% 81.2%
Steeltoe.Management.Tasks 95.2% 80%
Steeltoe.Management.Tracing 100% 75%
Steeltoe.Security.Authentication.JwtBearer 100% 95.6%
Steeltoe.Security.Authentication.OpenIdConnect 87.8% 77.2%
Steeltoe.Security.Authorization.Certificate 96.8% 66.6%
Steeltoe.Security.DataProtection.Redis 100% ****

@bart-vmware bart-vmware added Component/Configuration Issues related to Configuration providers Component/Connectors Issues related to Steeltoe connectors Component/Management Issues related to Steeltoe Management (actuators) Component/Security Issues related to Steeltoe Security components (not app-sec) Component/Discovery Issues related to Steeltoe Service Discovery ReleaseLine/4.x Identified as a feature/fix for the 4.x release line labels Oct 9, 2026
@bart-vmware bart-vmware added this to the 4.3.1 milestone Oct 9, 2026
@bart-vmware
bart-vmware marked this pull request as ready for review October 9, 2026 15:33
@bart-vmware
bart-vmware requested a review from TimHess October 9, 2026 15:33

@TimHess TimHess left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for chasing down these resource links, LGTM

@bart-vmware

Copy link
Copy Markdown
Member Author

I had to rebase, nothing changed since approval.

@sonarqubecloud

sonarqubecloud Bot commented Oct 9, 2026

Copy link
Copy Markdown

@bart-vmware
bart-vmware merged commit f13e514 into main Oct 9, 2026
25 checks passed
@bart-vmware
bart-vmware deleted the reliability-fixes branch October 9, 2026 20:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Component/Configuration Issues related to Configuration providers Component/Connectors Issues related to Steeltoe connectors Component/Discovery Issues related to Steeltoe Service Discovery Component/Management Issues related to Steeltoe Management (actuators) Component/Security Issues related to Steeltoe Security components (not app-sec) ReleaseLine/4.x Identified as a feature/fix for the 4.x release line

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants