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.

WebSocket exception

See original GitHub issue

Ocelot version: 19.0.2

Ocelot configuration, a route:

{
  "UpstreamPathTemplate": "/JavaMessageService/websocket/{url}",
  "UpstreamHttpMethod": [ "Get", "Post", "PUT", "DELETE", "OPTIONS" ],
  "DownstreamPathTemplate": "/api/websocket/{url}",
  "DownstreamScheme": "ws",
  "DownstreamHostAndPorts": [{
    "Host": "192.168.1.22",
    "Port": 9082
  }]
}

Direct Access to ws://192.168.1.22:9082/api/websocket/xxl was successful. 👇 image


Ocelot UpstreamPathTemplate will report an error 👇 image


The error message of Ocelot pipeline is as follows:

System.ArgumentException: Only Uris starting with 'ws://' or 'wss://' are supported. (Parameter 'uri')
   at System.Net.WebSockets.ClientWebSocket.ConnectAsync(Uri uri, CancellationToken cancellationToken)
   at Ocelot.WebSockets.Middleware.WebSocketsProxyMiddleware.Proxy(HttpContext context, String serverEndpoint)
   at Ocelot.WebSockets.Middleware.WebSocketsProxyMiddleware.Invoke(HttpContext httpContext)
   at Ocelot.DownstreamUrlCreator.Middleware.DownstreamUrlCreatorMiddleware.Invoke(HttpContext httpContext)
   at Ocelot.LoadBalancer.Middleware.LoadBalancingMiddleware.Invoke(HttpContext httpContext)
   at Ocelot.Request.Middleware.DownstreamRequestInitialiserMiddleware.Invoke(HttpContext httpContext)
   at Ocelot.Multiplexer.MultiplexingMiddleware.Invoke(HttpContext httpContext)
   at Ocelot.DownstreamRouteFinder.Middleware.DownstreamRouteFinderMiddleware.Invoke(HttpContext httpContext)
   at Microsoft.AspNetCore.Builder.Extensions.MapWhenMiddleware.Invoke(HttpContext context)
   at Ocelot.Errors.Middleware.ExceptionHandlerMiddleware.Invoke(HttpContext httpContext)

Issue Analytics

  • State:open
  • Created 2 months ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
zhaoyongjie183commented, Jul 31, 2023

Hi raman! This is my solution image This is Nacos Config image This is the Gateway port image Direct Access to ws://192.168.1.22:9082/api/websocket/xxl was successful. An error is reported when accessing through the Gateway address (ws://192.168.1.22:4000/JavaMessage Service/websocket/xxl).The entire operation process has been uploaded. From the video, it can be seen that there is an exception when ocelot forwards websockets. Forwarding the HTTP protocol is normal. From the logs in the video, it can be seen that forwarding the HTTP protocol address:/JavaMessageService/note/ureadCount was successful video

0reactions
raman-mcommented, Aug 14, 2023

@zhaoyongjie183 commented on Aug 7:

The cause is that the upstream route template is defined repeatedly, causing the websocket to find the http protocol template

Sorry, does that mean you have invalid definitions of the routes in ocelot.json? For example, if you have a duplicates of upstream templates (routes duplication) then you should have the following validation error in the logs: $"{nameof(route)} {route.UpstreamPathTemplate} has duplicate". If you have some another validation error, you should have in logs a message like that; "Unable to start Ocelot, errors are: bla-bla-bla. Could you confirm once again, that your issue is related to invalid configuration please? Can we close the issue?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Exceptions - websockets 11.0.3 documentation
websockets.exceptions defines the following exception hierarchy: ... Raised to abort the handshake on purpose and return an HTTP response. This exception is an ......
Read more >
How to use the websockets.exceptions. ...
To help you get started, we've selected a few websockets.exceptions.ConnectionClosedOK examples, based on popular ways it is used in public projects.
Read more >
WebSocketException Class (System.Net.WebSockets)
Represents an exception that occurred when performing an operation on a WebSocket connection.
Read more >
WebSocket: error event - Web APIs | MDN
The error event is fired when a connection with a WebSocket has been closed due to an error (some data couldn't be sent...
Read more >
Python websockets error handling: growing number of ...
Unfortunately, my implementation leads to growing number of threads (one per error). What am I doing wrong here? import websockets import ...
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