BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News ASP.NET Core 9 RC 1: Keep-Alive Timeouts for Websockets, Improved SignalR Tracing, and More

ASP.NET Core 9 RC 1: Keep-Alive Timeouts for Websockets, Improved SignalR Tracing, and More

Last week, Microsoft released the first .NET 9 Release Candidate. This is the first Go-live version of the new framework, expected to be released later this year. Among other features, it consolidates significant updates to ASP.NET Core, including: keep-alive timeout for WebSockets, support for Keyed DI services in middleware, and improvements to SignalR distributed tracing.

One of the most important features of this release is the addition of keep-alive timeouts in the WebSockets middleware configuration. The new APIs on ClientWebSocketOptions and WebSocketCreationOptions allow for sending WebSocket pings, aborting the connection ( and throwing an exception) if the client does not respond within the specified timeout period. This is a fix for an issue raised in 2021 by GitHub user @bjornen77:

Today, the ClientWebSocket is closed when the TCP Retransmission times out (if the connection to the server drops for some reason). This timeout seems to be different on Windows and Linux. By default, on Windows it takes about 21 seconds and on Linux it takes about 15 minutes before the WebSocket is closed. It would be good if we could have a separate Timeout setting, so that we get the same behavior regardless of the platform. And also that this could be configured by the application without having to modify the TCP Timeout settings in the OS.

Another interesting update in this release is the support for Keyed DI services in both the constructor and the Invoke / InvokeAsync methods. "Keyed DI" refers to a mechanism for registering and retrieving Dependency Injection (DI) services using keys. Once a service is registered with a key, this key can be used for accessing its associated service later. The example below shows the use of keyed services in the new release:

var app = builder.Build();
app.UseMiddleware<MyMiddleware>();
app.Run();

internal class MyMiddleware
{
    private readonly RequestDelegate _next;

    public MyMiddleware(RequestDelegate next, [FromKeyedServices("test")] MySingletonClass service)
    {
        _next = next;
    }

    public Task Invoke(HttpContext context, [FromKeyedServices("test2")] MyScopedClass scopedService) => _next(context);
}

Source: Microsoft

SignalR distributed tracing, introduced in .NET 9 Preview 6, allows the emission of events for hub method calls. In this release, the new tracing capabilities include the creation of a client span by hub invocations and support for context propagation. As a result, it is now possible to see the invocations flow from the client and server and back:

 

Source: Microsoft

Other updates in this release include type overriding support for the InputNumber component and Linux (Ubuntu- and Fedora-based distros) support for the ASP.NET Core HTTPS development certificate to be configured as a trusted certificate for Chromium and Mozilla browsers, as well as for use with .NET APIs.

You can find more information about the ASP.NET Core updates in .NET 9 RC1 in the official release notes. The ASP.NET Core roadmap for .NET 9 is also available on GitHub.

About the Author

Rate this Article

Adoption
Style

BT