question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

HttpContext RequestAborted no longer works.

See original GitHub issue

Describe the bug

Since .NET 6, the HttpContext.RequestAborted does not updates when the request is cancelled. This used to work with .NET 5. IsCancellationRequested stays in false even tho the request has been canceled and CanBeCancelled is set to true.

To Reproduce

I started a .NET 6 Angular project and created an HTTP GET request and subscribe to it, the Request is in an infinite loop intentionally so it can only be ended by the cancellation token. Also have a subject to cancel the request with an other button.

In .NET 5 this works flawlessly. In .NET 6 its unusable.

An Example Repo can be found here: https://github.com/blogcraft/TestCancel

Exceptions (if any)

Further technical details

  • ASP.NET Core version: .NET 6.0.100
  • The IDE (VS / VS Code/ VS4Mac) you’re running on, and its version: VS Code
  • Include the output of dotnet --info:
SDK de .NET (que refleje cualquier global.json): Version: 6.0.100 Commit: 9e8b04bbff

Entorno de tiempo de ejecución: OS Name: Windows OS Version: 10.0.22000 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\6.0.100\

Host (useful for support): Version: 6.0.0 Commit: 4822e3c3aa

.NET SDKs installed: 3.1.415 [C:\Program Files\dotnet\sdk] 5.0.401 [C:\Program Files\dotnet\sdk] 6.0.100 [C:\Program Files\dotnet\sdk]

.NET runtimes installed: Microsoft.AspNetCore.App 3.1.21 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 5.0.10 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 3.1.21 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 5.0.10 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 3.1.21 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 5.0.10 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

To install additional .NET runtimes or SDKs: https://aka.ms/dotnet-download

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:4
  • Comments:21 (18 by maintainers)

github_iconTop GitHub Comments

2reactions
davidfowlcommented, May 13, 2022

@singh733 you’re looking at the wrong method, that’s not how this works. I think you’re a bit in the weeds here. My guess is that the nodejs proxy (the client) isn’t disconnecting properly and that’s likely why the client isn’t seeing the disconnect.

1reaction
blogcraftcommented, Feb 12, 2022

Please don’t close this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

asp.net mvc - What's the difference between HttpContext. ...
RequestAborted is that it is available in all controller's methods, not just actions. The CancellationToken parameter is IMHO better readable ...
Read more >
HttpContext.RequestAborted Property
Notifies when the connection underlying this request is aborted and thus request operations should be cancelled.
Read more >
Handling aborted requests in ASP.NET Core
ASP.NET Core provides the HttpContext.RequestAborted property to detect when the client disconnect. You can check the property ...
Read more >
Canceling abandoned requests in ASP.NET Core : r/dotnet
An alternative is using Request.HttpContext.RequestAborted which is available in every controller action automatically.
Read more >
How does the HttpContext.RequestAborted work? : r/dotnet
The underlying http connection is being closed by the browser or OS. Upvote
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found