dotnet / dotnet/aspnetcore

SignalR - SSE/LongPoll Close connection returns 404

Open
#55,750 2 comments 2 reactions 0 assignees View on GitHub
area-signalr
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 6h
Merged PRs (30d)
290

Description

### Is there an existing issue for this?

- [X] I have searched the existing issues

### Describe the bug

Client - signalR 8.0.0 (typescript/browser)
Server - 8.0.4

I have a browser client that connect to SignalR hub via Server-Sent events (My reverse proxy does not support websockets)
The communication works well.
1) Client connects
2) Sends some data via `invoke` function
3) Once all data is transfered the client calls `connection.stop()`, which generates POST request to a hub with 404/`No Connection with that ID` response
4) It seems that the server successfully closes the connection but returns 404 with

Server logs from close call:
```
[11:51:38.482 INF] Microsoft.AspNetCore.Hosting.Diagnostics - Request starting HTTP/2 POST https://localhost:56480/hubs/plansExport?id=njAzClV6o81z9cB3kHElpg - text/plain;charset=UTF-8 11
[11:51:38.488 DBG] Microsoft.AspNetCore.Routing.Matching.DfaMatcher - 2 candidate(s) found for the request path '/hubs/plansExport'
[11:51:38.510 DBG] Microsoft.AspNetCore.Routing.Matching.DfaMatcher - Endpoint '/hubs/plansExport' with route pattern '/hubs/plansExport' is valid for the request path '/hubs/plansExport'
[11:51:40.829 DBG] Microsoft.AspNetCore.Routing.Matching.DfaMatcher - Endpoint 'Fallback {*path:nonfile}' with route pattern '{*path:nonfile}' is valid for the request path '/hubs/plansExport'
[11:51:40.845 DBG] Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware - Request matched endpoint '/hubs/plansExport'
[11:51:40.970 DBG] Microsoft.AspNetCore.SignalR.HubConnectionHandler - OnConnectedAsync ending.
[11:51:41.844 DBG] Microsoft.AspNetCore.Http.Connections.Internal.HttpConnectionManager - Removing connection njAzClV6o81z9cB3kHElpg from the list of connections.
[11:51:41.853 INF] Microsoft.AspNetCore.Routing.EndpointMiddleware - Executing endpoint '/hubs/plansExport'
[11:51:41.863 INF] Microsoft.AspNetCore.Routing.EndpointMiddleware - Executed endpoint '/hubs/plansExport'
[11:51:42.627 INF] Microsoft.AspNetCore.Hosting.Diagnostics - Request finished HTTP/2 GET https://localhost:56480/hubs/plansExport?id=njAzClV6o81z9cB3kHElpg - 200 null text/event-stream 12650.3697ms
[11:51:42.627 INF] Microsoft.AspNetCore.Routing.EndpointMiddleware - Executed endpoint '/hubs/plansExport'
[11:51:42.671 INF] Microsoft.AspNetCore.Hosting.Diagnostics - Request finished HTTP/2 POST https://localhost:56480/hubs/plansExport?id=njAzClV6o81z9cB3kHElpg - 404 null text/plain 4188.9645ms
```

In logs I can see
- 11:51:38.482 Close request starting
- 11:51:41.844 Connection removed
- 11:51:42.627 SSE connection closed
- 11:51:42.671 Close request finished with 404

- My hub url has a custom query parameter but removing it does not seem to make any change
- I have multiple server instances, but the communication works well except the close call
- The same happens when using Long-Poll
- The same happens with other versions on client/server
- The app is running in linux/docker in production and the same happens when debugging locally with Windows

There is no visible issue for a users, The only thing is that this 404 generates `Failed to Fetch` exception + error log which gets collected by a monitoring tools in both client and server.

Possibly related issues:
- https://github.com/dotnet/aspnetcore/issues/5350
- https://github.com/dotnet/aspnetcore/issues/27584

### Expected Behavior

Close connection should return 2xx if there is no error.

### Steps To Reproduce

I am not able to reproduce it on small/new project.
My application is pretty big. I tried removing all code that is not needed and all middlewares except the minimal needed ones (authorization, session, routing, ...) but the issue still occurs

EDIT: I somehow managed to reporoduce it - https://github.com/omorsky-pcor/signalr_close_404
It returns 404 randomly (about 1 out of 10 close calls) with empty content.
The `No Connection with that ID` is even less frequent

### Exceptions (if any)

_No response_

### .NET Version

8.0.4

### Anything else?

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.