RemoteHost: remove unnecessary try/finally in JsonRpcServer.StartAsync

Open Beginner friendly
#21,747 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 2 days

Nobody has claimed this yet.

Assessment

Difficulty
1/5
Estimated time
1-3 hours
Newbie friendliness
92/100
Issue type
Refactor
Clarity
Clearly specified
Activity status
Active
Tech stack
csharp
Domain
backend, testing

Research direction

Read src/Aspire.Hosting.RemoteHost/JsonRpcServer.cs and simplify StartAsync as described in the issue. Then run the existing Listening tests in tests/Aspire.Hosting.RemoteHost.Tests/JsonRpcAuthenticationTests.cs; done when they pass and startup behavior is unchanged.

Written by the indexing model from the issue text.

Description

needs-area-label

Follow-up from #21531 (review by @sebastienros: https://github.com/microsoft/aspire/pull/21531#discussion_r4463017255).

JsonRpcServer.StartAsync in src/Aspire.Hosting.RemoteHost/JsonRpcServer.cs wraps base.StartAsync in a try/finally so that ObserveExecuteTask() always runs. That failure path doesn't exist: the project targets net10.0, where BackgroundService.StartAsync schedules ExecuteAsync with Task.Run and always returns Task.CompletedTask. Even if it did throw, ExecuteTask would still be null and ObserveExecuteTask would do nothing.

Simplify to:

public override async Task StartAsync(CancellationToken cancellationToken)
{
    await base.StartAsync(cancellationToken).ConfigureAwait(false);
    ObserveExecuteTask();
}

This is a readability cleanup with no behavior change. The existing Listening tests in tests/Aspire.Hosting.RemoteHost.Tests/JsonRpcAuthenticationTests.cs cover the startup, failure and cancellation paths.

🤖 Posted by AspireAgent (AI Agent)

Dominant language
C#
Stars
6.4k
Forks
1k
Avg merge
3d 3h
Merged PRs (30d)
349

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from microsoft/aspire

All issues in microsoft/aspire

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.