-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix NLog IPC Websocket over HTTP/2 #3532
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Hmm, very interesting, I guess nobody stumbled upon it before because everybody even remotely interested in accessing that endpoint over secure protocol was doing that through a reverse proxy, where this issue is non-existent. Alternatively, using HTTP 1.1, which would also work. But indeed, if you're attempting to access that endpoint using HTTP/2, it might be different as per the docs you linked - thanks for that. I don't see any problem with this PR - have you tested that this indeed resolves your issue, but also if the endpoint shows up properly in |
|
I have this patch running on my server currently (technically as a backport for V6.3.1.5 because of how I have the build system setup), and I tested that both HTTP/1.1 and HTTP/2 (over TLS) works. I had forgotten about |
There was a problem hiding this 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 fixes WebSocket compatibility over HTTP/2 for the NLog IPC endpoint by removing the [HttpGet] attribute. When using HTTPS, browsers enable HTTP/2 by default, which requires WebSocket endpoints to use CONNECT requests instead of GET requests. The fix aligns with Microsoft's ASP.NET Core documentation recommendations for HTTP/2 WebSocket support.
- Removes the
[HttpGet]attribute from the NLog WebSocket endpoint - Maintains existing WebSocket validation logic in the method
- Ensures compatibility with HTTP/2 WebSocket connections
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Try to add |
|
Or try |
|
Ok, I tested and neither works, but that's for me to fix since it might involve deeper digging. For now, thanks a lot, this PR does more good than harm, so it's appropriate candidate for merging if HTTP/1.1 works properly. Thanks! |
|
To comment on the |
Actually, I've encountered this error before, you even tried to fix it Btw, bug fixed, kudos for @LRFLEW |
Could be the same issue indeed, I'm not denying it - the difference is, here @LRFLEW pointed to the precise issue and also submitted fix for it which I could analyze. It's totally different compared to me looking for issue reported by somebody, only to find out I can't reproduce it. And yes, if it works on Firefox but doesn't on Chrome, that's a hint towards browser-specific problem. If you digged more and pointed out that it's not due to web browsers but due to Chrome using HTTP/2 for websocket and Firefox not, and that's why it doesn't work - I could test that theory and confirm it as well. I'm not a wizard, sometimes the issue is more complex and it's not enough to just point it out, fixing the issue first and foremost requires understanding the culprit, and the culprit back then was not discovered properly. |

Checklist
Changes
This fixes an issue I encountered with the log in the IPC API. When I switched the Kestrel config from HTTP to HTTPS, the live log stopped working in the web-ui. After significant troubleshooting, I discovered the issue was actually with using a WebSocket over HTTP/2 (which browsers only enable when using HTTPS). Microsoft's documentation for WebSockets in ASP.NET has this note about HTTP/2 compatibility:
The
/Api/NLoghad a[HttpGet]attribute, which was breaking compatibility with HTTP/2. Since the class has theRouteattribute, I was able to simply remove theHttpGetattribute to get it working with HTTP/2. Since this function already has an explicit check for whether the request is a WebSocket, this shouldn't meaningfully impact the correctness of this route.Additional info
I saw the checklist includes an entry for adding a test for the change. While a test for this would probably be useful to have, I don't see any existing tests for the IPC API, and I'm not sure how to implement one that isn't just an integration test (i.e. spinning up a full ASF server and sending requests). I think this should be fine to merge without a test, but I left the checkbox unchecked for now.