spring-cloud / spring-cloud-gateway

An API Gateway built on Spring Framework and Spring Boot providing routing and more.
http://cloud.spring.io
Apache License 2.0
4.51k stars 3.31k forks source link

When using a Web Socket behind the Eureka Load Balancer, API gateway throws a 404 Exception? #3044

Open surajkumar opened 1 year ago

surajkumar commented 1 year ago

Describe the bug

Example: https://github.com/surajkumar/spring-ws-gateway-issue

I have a simple Spring API Gateway and within the application.yaml I have the following:

- id: websocket-bad
  uri: lb:ws://websocket
  predicates:
    - Path=/websocket-bad/**

The websocket is a simple application that has a web socket server that has been created in Vert.x, running on port 80.

When I hit the endpoint using Postman: ws://localhost:8080/websocket-bad the following error is display in the API Gateway's console:

io.netty.handler.codec.http.websocketx.WebSocketClientHandshakeException: Invalid handshake response getStatus: 404

If I change the application.yaml and use this:

- id: websocket-good
  uri: ws://localhost:80
  predicates:
   - Path=/websocket-good/**

This works!

There's a problem somewhere when there's a load balancer infront.

I have ensured that the issue is with a web socket in front of the load balancer and not a configuration issue.

Spring Cloud Version: 2022.0.4

surajkumar commented 1 year ago

Added sample code to reproduce this issue: https://github.com/surajkumar/spring-ws-gateway-issue