Skip to content

Async refactorings#1513

Merged
bart-vmware merged 2 commits into
mainfrom
async-refactorings
May 7, 2025
Merged

Async refactorings#1513
bart-vmware merged 2 commits into
mainfrom
async-refactorings

Conversation

@bart-vmware
Copy link
Copy Markdown
Member

@bart-vmware bart-vmware commented May 6, 2025

Description

Reviewed the Steeltoe codebase against the guidance at https://github.com/davidfowl/AspNetCoreDiagnosticScenarios/blob/master/AsyncGuidance.md.

We can't apply all of the guidance because there's simply no async call stack in Configuration. So we're stuck with sync-over-async there. That unnecessarily blocks a thread, but fortunately doesn't deadlock in ASP.NET Core. Our async-void cases catch all exceptions, so it won't crash the process. What remains are quite some violations in DotNetHeapDump, but changing that is very high risk, so I didn't bother.

We have some violations that only appear in tests, resulting in potential memory leaks, but that's not too important, and there is no easy fix.

Closes #1475.

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, Samples and/or MainSite, 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.

@bart-vmware bart-vmware requested a review from Copilot May 6, 2025 14:56
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors asynchronous code related to thread dumping and dynamic task result retrieval within the Steeltoe codebase.

  • Refactored timeout handling logic in EventPipeThreadDumper to use a dedicated CancellationTokenSource.
  • Replaced the direct Result property access with a new GetResult() method in TaskShim and its call sites across multiple connector shims.

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/Management/src/Endpoint/Actuators/ThreadDump/EventPipeThreadDumper.cs Refactored async timeout logic to use an internal CancellationTokenSource and CancelAsync for cleaning up the Task.Delay timer.
src/Connectors/src/Connectors/Redis/DynamicTypeAccess/DatabaseInterfaceShim.cs Updated to use GetResult() for retrieving the task result instead of accessing Result directly.
src/Connectors/src/Connectors/Redis/DynamicTypeAccess/ConnectionMultiplexerShim.cs Similar change applied: using GetResult() to retrieve the task result for consistent behavior.
src/Connectors/src/Connectors/RabbitMQ/DynamicTypeAccess/ConnectionFactoryInterfaceShim.cs Updated retrieval of task result via GetResult() ensuring consistency.
src/Connectors/src/Connectors/MongoDb/DynamicTypeAccess/MongoClientInterfaceShim.cs Consistent update using GetResult() for better clarity in async result extraction.
src/Common/src/Common/DynamicTypeAccess/TaskShim.cs Replaced the Result property with a GetResult() method, impacting multiple shim files for consistency.
Comments suppressed due to low confidence (3)

src/Management/src/Endpoint/Actuators/ThreadDump/EventPipeThreadDumper.cs:443

  • Ensure that CancelAsync() is a valid and well-documented extension method in this codebase, as it is not part of the standard .NET API. Consider using the standard Cancel() method if a custom async cancel behavior is not required.
await timeoutSource.CancelAsync();

src/Common/src/Common/DynamicTypeAccess/TaskShim.cs:26

  • [nitpick] The refactor replacing the 'Result' property with the GetResult() method improves clarity; ensure that its exception handling and performance characteristics match the previous behavior.
public TResult GetResult()

src/Connectors/src/Connectors/Redis/DynamicTypeAccess/DatabaseInterfaceShim.cs:20

  • [nitpick] Updating to GetResult() enhances consistency across dynamic shims; verify that all similar usages have been updated to prevent potential runtime discrepancies.
return taskShim.GetResult();

@bart-vmware bart-vmware force-pushed the async-refactorings branch from 2abfca1 to 6a85fe8 Compare May 6, 2025 15:03
@bart-vmware bart-vmware marked this pull request as ready for review May 6, 2025 15:27
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented May 6, 2025

@bart-vmware bart-vmware requested a review from TimHess May 6, 2025 15:30
@bart-vmware bart-vmware merged commit 85db455 into main May 7, 2025
22 checks passed
@bart-vmware bart-vmware deleted the async-refactorings branch May 7, 2025 09:55
@bart-vmware bart-vmware added Component/Connectors Issues related to Steeltoe connectors Component/Management Issues related to Steeltoe Management (actuators) ReleaseLine/4.x Identified as a feature/fix for the 4.x release line labels May 23, 2025
@bart-vmware bart-vmware added this to the 4.0.0-rc1 milestone May 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Component/Connectors Issues related to Steeltoe connectors Component/Management Issues related to Steeltoe Management (actuators) 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.

Apply guidance for multi-threaded / async code

3 participants