Skip to content
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

YARP keep terminating the WebSocket after around 2 minutes #2615

Closed
AbdallahR99 opened this issue Sep 24, 2024 · 6 comments
Closed

YARP keep terminating the WebSocket after around 2 minutes #2615

AbdallahR99 opened this issue Sep 24, 2024 · 6 comments
Labels
needs-author-action An issue or pull request that requires more info or actions from the author. Type: Bug Something isn't working

Comments

@AbdallahR99
Copy link

AbdallahR99 commented Sep 24, 2024

When I connect to the web socket through the original site, there is no problem in connecting and it lasts for a long time

But when I connect through YARP reverse proxy , this error appears after around 2 minutes:

UpgradeActivityTimeout: The WebSocket connection was closed after being idle longer than the Activity Timeout.

System.OperationCanceledException: The operation was canceled.

   at System.Threading.CancellationToken.ThrowOperationCanceledException()

   at System.IO.Pipelines.Pipe.GetReadAsyncResult()

   at Microsoft.AspNetCore.Server.IIS.Core.IISHttpContext.ReadAsync(Memory`1 memory, CancellationToken cancellationToken)

   at Microsoft.AspNetCore.Server.IIS.Core.HttpRequestStream.ReadAsyncInternal(Memory`1 buffer, CancellationToken cancellationToken)

   at Yarp.ReverseProxy.Forwarder.StreamCopier.CopyAsync(Stream input, Stream output, Int64 promisedContentLength, StreamCopierTelemetry telemetry, ActivityCancellationTokenSource activityToken, Boolean autoFlush, CancellationToken cancellation)

I also noticed that yarp receive the ws calls as http

Screenshot 2024-09-24 091748

image

@AbdallahR99 AbdallahR99 added the Type: Bug Something isn't working label Sep 24, 2024
@MihaZupan
Copy link
Member

YARP uses an ActivityTimeout with a 100-second default on all requests.
See https://microsoft.github.io/reverse-proxy/articles/http-client-config.html#httprequest

The way to avoid it triggering for long-lived requests like WebSockets is to enable keep-alive/ping mechanisms.

@MihaZupan MihaZupan added the needs-author-action An issue or pull request that requires more info or actions from the author. label Sep 24, 2024
@AbdallahR99
Copy link
Author

@MihaZupan modified the ActivityTimeout and still facing the same issue
tried also to override the keep-alive in the headers and nothing changed

@MihaZupan
Copy link
Member

You're seeing messages about The WebSocket connection was closed after being idle longer than the Activity Timeout. after two minutes even after increasing the timeout?

Are you able to create a small runnable repro?

Keep-Alive headers won't affect this. What I was referring to are actual periodic pings sent by the WebSocket client and/or server. E.g. if the client is using ClientWebSocket, you can change the KeepAliveInterval.

@AbdallahR99
Copy link
Author

You're seeing messages about The WebSocket connection was closed after being idle longer than the Activity Timeout. after two minutes even after increasing the timeout?

Yes exactly the same message

Are you able to create a small runnable repro?

can't it requires to set up qliksense enterprise

Keep-Alive headers won't affect this. What I was referring to are actual periodic pings sent by the WebSocket client and/or server. E.g. if the client is using ClientWebSocket, you can change the KeepAliveInterval.

doesn't work

@MihaZupan
Copy link
Member

If you're seeing that message after 2 minutes after having increased the ActivityTimeout, my guess is that the setting change wasn't applied correctly.

Can you share how you're configuring YARP? Without any info, this isn't actionable from our side.

doesn't work

You've enabled WebSocket pings and you're still seeing the timeout? Can you share a network capture?

@AbdallahR99
Copy link
Author

I just ran the project now and found it working fine

I guess it was a cache issue

I just tested it and commented the "ActivityTimeout": "00:30:00", line and tried the guest browser to avoid the cache then I faced the issue again and worked fine when I uncommented it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-author-action An issue or pull request that requires more info or actions from the author. Type: Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants