I use spring gateway as a proxy websocket.
I had a problem with closing a connection with a specific status code (for example - 4401). If I connect directly my custom codes and reasons come to the client. If I use spring gateway, the code and reason are lost.
I tried different options:
CloseStatus[code=1000, reason=null]WebSocketFrame(FIN=1,RSV1=0,RSV2=0,RSV3=0,Opcode=CLOSE,Length=0,CloseCode=1005,Reason=null)Can you provide a complete, minimal, verifiable sample that reproduces the problem? It should be available as a GitHub (or similar) project or attached to this issue as a zip file.
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.
Experiencing the same issue with Spring Cloud Gateway Greenwich.RELEASE
This issue can be reproduced quite easily.
var ws = new WebSocket('ws://localhost:8444/myws;ws.close(3000, "MY REASON");package com.myapp.handler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.web.socket.CloseStatus;
import org.springframework.web.socket.WebSocketSession;
import org.springframework.web.socket.handler.TextWebSocketHandler;
@Service
public class MyWsHandler extends TextWebSocketHandler {
private static final Logger logger = LoggerFactory.getLogger(MyWsHandler.class);
@Override
public void afterConnectionClosed(WebSocketSession recordingSession, CloseStatus status) {
logger.debug("[WS] Closing socket {} and status {}", recordingSession, status);
}
}
will log following:
2019-05-29 18:27:21.735 DEBUG 5096 --- [io-8443-exec-11] c.m.handler.MyWsHandler : [WS] Closing socket StandardWebSocketSession[id=e29c3fba-b5a9-9616-086a-56ac4cbd6b57, uri=ws://localhost:8444/myws] and status CloseStatus[code=3000, reason=MY REASON]
package com.myapp.gateway.config;
import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class TestRouteConfig {
@Bean
public RouteLocator routeLocator(RouteLocatorBuilder builder) {
return builder.routes()
.route("websocket", r -> r.path("/myws")
.uri("ws://localhost:8444"))
.build();
}
}
var ws = new WebSocket('ws://localhost:8777/myws;ws.close(3000, "MY REASON");2019-05-30 11:34:42.367 DEBUG 5096 --- [nio-8443-exec-5] c.m.handler.MyWsHandler : [WS] Closing socket StandardWebSocketSession[id=3035ca7a-a6d2-dadd-67e2-5167321202c2, uri=ws://localhost:8777/myws] and status CloseStatus[code=1000, reason=null]
Hope that helps.
Any updates on this?
Play is very simple.
Run the GatewayApplication
Run the ServerApplication
Run the ServerApplicationTests

Hi, any plan to fix the issue?
Hi, I'm have the same problem now. I guess no new solutions have been emerged...
any plan to fix this, please?
Most helpful comment
Hi, any plan to fix the issue?