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

Feature/websocket closeoutput exceptions #1030

Conversation

tdejong-tools4ever
Copy link
Contributor

Fixes / New Feature #
Fixes exceptions being thrown because of already closed WebSockets when the state is both updated by the source and destination.

Proposed Changes

  • Only close websocket connection if the current state allows it

Stacktrace of exception that is intended to fix:

requestId: 0HLPTRFNQ4IJE:00000001, previousRequestId: no previous request id, message: Exception caught in global error handler, exception message: The WebSocket is in an invalid state ('Aborted') for this operation. Valid states are: 'Open, CloseReceived', exception stack: at System.Net.WebSockets.WebSocketValidate.ThrowIfInvalidState(WebSocketState currentState, Boolean isDisposed, WebSocketState[] validStates) at System.Net.WebSockets.ManagedWebSocket.CloseOutputAsync(WebSocketCloseStatus closeStatus, String statusDescription, CancellationToken cancellationToken) --- End of stack trace from previous location where exception was thrown --- at Ocelot.WebSockets.Middleware.WebSocketsProxyMiddleware.PumpWebSocket(WebSocket source, WebSocket destination, Int32 bufferSize, CancellationToken cancellationToken) at Ocelot.WebSockets.Middleware.WebSocketsProxyMiddleware.Proxy(HttpContext context, String serverEndpoint) at Ocelot.WebSockets.Middleware.WebSocketsProxyMiddleware.Invoke(DownstreamContext context) at Ocelot.DownstreamUrlCreator.Middleware.DownstreamUrlCreatorMiddleware.Invoke(DownstreamContext context) at Ocelot.LoadBalancer.Middleware.LoadBalancingMiddleware.Invoke(DownstreamContext context) at Ocelot.Request.Middleware.DownstreamRequestInitialiserMiddleware.Invoke(DownstreamContext context) at Ocelot.Middleware.Multiplexer.Multiplexer.Fire(DownstreamContext context, OcelotRequestDelegate next) at Ocelot.Middleware.Multiplexer.Multiplexer.Multiplex(DownstreamContext context, ReRoute reRoute, OcelotRequestDelegate next) at Ocelot.DownstreamRouteFinder.Middleware.DownstreamRouteFinderMiddleware.Invoke(DownstreamContext context) at Ocelot.Middleware.Pipeline.MapWhenMiddleware.Invoke(DownstreamContext context) at Ocelot.Errors.Middleware.ExceptionHandlerMiddleware.Invoke(DownstreamContext context)

@Rubbiroid
Copy link

Shouldn't we add the same check to line 68?

@tdejong-tools4ever
Copy link
Contributor Author

I assume you mean to check the connection state when a close message has been recieved?

I guess it should not matter as the connection will be closed anyway with the message, the only difference should be the modified status (not sure where this is used).

Have you thought of any cases where this is relevant? If so please let me know and I will fix it.

@Rubbiroid
Copy link

Currently we have the ocelot in production with this PR applied. And still get same exceptions. As far I see, this is the place, where it could be thrown.
I have added same check to the close condition. After it lands on prod I can check if it helped.

@Rubbiroid
Copy link

Didn't help :(

@TomPallister
Copy link
Member

please open PR again against master branch

OnSive pushed a commit to OnSive/Ocelot that referenced this pull request May 9, 2022
raman-m pushed a commit to OnSive/Ocelot that referenced this pull request May 11, 2023
@raman-m
Copy link
Member

raman-m commented May 11, 2023

From Rubbiroid on Jan 13, 2020

Didn't help :(

@Rubbiroid
Hi Pavel!
Could you share the source code you've applied in Production please?
Why are you so sure that the fix "didn't help"? Could you attach some logs plz?

@raman-m
Copy link
Member

raman-m commented May 11, 2023

Hi @tdejong-tools4ever !
How did you check that your bug fix is really working?
Did you write some tests?
What is your user scenario?

@Rubbiroid
Copy link

From Rubbiroid on Jan 13, 2020

Didn't help :(

@Rubbiroid Hi Pavel! Could you share the source code you've applied in Production please? Why are you so sure that the fix "didn't help"? Could you attach some logs plz?

I have merged the pr, but still got the same exception. Right now I do not have logs anymore.

@tdejong-tools4ever
Copy link
Contributor Author

Hey @raman-m,

Back then we had a reproduction scenario with our wamp service websocket being routed through ocelot causing the issue
multiple times a day. At that point we changed our setup to skip ocelot for websockets and directly forward to the recieving service to circumvent the issue.

I am sorry but I am no longer be able to help you with this reproducing this issue.

@raman-m
Copy link
Member

raman-m commented May 12, 2023

@tdejong-tools4ever
Thank you for the reply!
The original issue #930 will be fixed by other PR.

You and your team could try latest 19.0.2 release of Ocelot NuGet package (.NET 7 release).
Hope in the next minor releases this issue will be fixed.
Good luck with your endeavors with Ocelot!

@ThreeMammals ThreeMammals locked as too heated and limited conversation to collaborators May 12, 2023
@ThreeMammals ThreeMammals unlocked this conversation Jan 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants