App经过网关转发websocket请求,app发送连接请求是正常的,app应用手动发送断开连接是正常的,app应用切换到后台时自动关闭websocket连接请求时网关报错,但也走了websocket服务端onclose方法连接正常关闭了,就是网关老报错。
个人感觉应该跟网关配置那块有问题
spring:
application:
name: sc-gateway
main:
allow-bean-definition-overriding: true
cloud:
gateway:
discovery:
locator:
enabled: false ###参考网上资料是不是不应该配置
lower-case-service-id: true
globalcors:
corsConfigurations:
'[/**]':
allowedOrigins: "docs.spring.io"
allowedMethods:
- GET
POST
DELETE
PUT
OPTION
routes:
#mini-mes基础服务
- id: mini-mes
order: 3
uri: lb://mini-mes
predicates:
- Path=/api-i/**
filters:
- StripPrefix=1
#mini-mes的webscoket接口
- id: mini-mes-socket
order: 2
uri: lb:ws://mini-mes
predicates:
- Path=/api-i/webScoket/**
filters:
- StripPrefix=1
- RemoveRequestHeader= SESSION
线上错误
```java
2023-04-21 14:19:38.273 ERROR 1 --- [-server-epoll-5] .a.w.r.e.DefaultErrorWebExceptionHandler : Failed to handle request [GET http://www.ccc.com:8766/api-i/webScoket/82-SA0003-appSendData]
io.netty.channel.unix.Errors$NativeIoException: syscall:read(..) failed: Connection reset by peer
at io.netty.channel.unix.FileDescriptor.readAddress(..)(Unknown Source)
2023-04-21 14:19:38.274 ERROR 1 --- [-server-epoll-5] o.s.w.s.adapter.HttpWebHandlerAdapter : Failed to handle request [GET http://www.ccc.com:8766/api-i/webScoket/82-SA0003-appSendData]
java.lang.IllegalStateException: Status and headers already sent
at reactor.ipc.netty.http.server.HttpServerOperations.status(HttpServerOperations.java:346)
at org.springframework.http.server.reactive.ReactorServerHttpResponse.applyStatusCode(ReactorServerHttpResponse.java:67)
at org.springframework.http.server.reactive.AbstractServerHttpResponse.lambda$null$4(AbstractServerHttpResponse.java:214)
at reactor.core.publisher.MonoRunnable.subscribe(MonoRunnable.java:42)
at reactor.core.publisher.Mono.subscribe(Mono.java:3080)
at reactor.core.publisher.FluxConcatIterable$ConcatIterableSubscriber.onComplete(FluxConcatIterable.java:147)
at reactor.core.publisher.FluxConcatIterable.subscribe(FluxConcatIterable.java:61)
at reactor.core.publisher.MonoIgnoreElements.subscribe(MonoIgnoreElements.java:37)
at reactor.core.publisher.Mono.subscribe(Mono.java:3080)
at org.springframework.http.server.reactive.ChannelSendOperator$WriteBarrier.onNext(ChannelSendOperator.java:181)
at reactor.core.publisher.FluxPeekFuseable$PeekFuseableSubscriber.onNext(FluxPeekFuseable.java:198)
at reactor.core.publisher.FluxMapFuseable$MapFuseableSubscriber.onNext(FluxMapFuseable.java:115)
at reactor.core.publisher.FluxJust$WeakScalarSubscription.request(FluxJust.java:99)
at reactor.core.publisher.FluxMapFuseable$MapFuseableSubscriber.request(FluxMapFuseable.java:156)
at reactor.core.publisher.FluxPeekFuseable$PeekFuseableSubscriber.request(FluxPeekFuseable.java:138)
at org.springframework.http.server.reactive.ChannelSendOperator$WriteBarrier.onSubscribe(ChannelSendOperator.java:163)
线下错误
2023-04-21 14:30:05.170 ERROR 7904 --- [ctor-http-nio-7] r.i.n.channel.CloseableContextHandler : Handler failure while no child channelOperation was present
java.io.IOException: 远程主机强迫关闭了一个现有的连接。
at sun.nio.ch.SocketDispatcher.read0(Native Method)
at sun.nio.ch.SocketDispatcher.read(SocketDispatcher.java:43)
at sun.nio.ch.IOUtil.readIntoNativeBuffer(IOUtil.java:223)
at sun.nio.ch.IOUtil.read(IOUtil.java:192)
at sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:380)
at io.netty.buffer.PooledUnsafeDirectByteBuf.setBytes(PooledUnsafeDirectByteBuf.java:288)
at io.netty.buffer.AbstractByteBuf.writeBytes(AbstractByteBuf.java:1108)
at io.netty.channel.socket.nio.NioSocketChannel.doReadBytes(NioSocketChannel.java:345)
at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:148)
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:647)
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:582)
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:499)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:461)
at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:884)
at java.lang.Thread.run(Thread.java:748)
2023-04-21 14:30:05.187 ERROR 7904 --- [ctor-http-nio-7] .a.w.r.e.DefaultErrorWebExceptionHandler : Failed to handle request [GET http://192.168.3.5:8766/api-i/webScoket/20-SA0003-appSendData]
java.io.IOException: 远程主机强迫关闭了一个现有的连接。
at sun.nio.ch.SocketDispatcher.read0(Native Method)
at sun.nio.ch.SocketDispatcher.read(SocketDispatcher.java:43)
at sun.nio.ch.IOUtil.readIntoNativeBuffer(IOUtil.java:223)
at sun.nio.ch.IOUtil.read(IOUtil.java:192)
at sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:380)
at io.netty.buffer.PooledUnsafeDirectByteBuf.setBytes(PooledUnsafeDirectByteBuf.java:288)
at io.netty.buffer.AbstractByteBuf.writeBytes(AbstractByteBuf.java:1108)
at io.netty.channel.socket.nio.NioSocketChannel.doReadBytes(NioSocketChannel.java:345)
at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:148)
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:647)
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:582)
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:499)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:461)
at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:884)
at java.lang.Thread.run(Thread.java:748)
2023-04-21 14:30:05.206 ERROR 7904 --- [ctor-http-nio-7] o.s.w.s.adapter.HttpWebHandlerAdapter : Failed to handle request [GET http://192.168.3.5:8766/api-i/webScoket/20-SA0003-appSendData]
java.lang.IllegalStateException: Status and headers already sent
at reactor.ipc.netty.http.server.HttpServerOperations.status(HttpServerOperations.java:346)
at org.springframework.http.server.reactive.ReactorServerHttpResponse.applyStatusCode(ReactorServerHttpResponse.java:67)
at org.springframework.http.server.reactive.AbstractServerHttpResponse.lambda$null$4(AbstractServerHttpResponse.java:214)
at reactor.core.publisher.MonoRunnable.subscribe(MonoRunnable.java:42)
at reactor.core.publisher.Mono.subscribe(Mono.java:3080)
at reactor.core.publisher.FluxConcatIterable$ConcatIterableSubscriber.onComplete(FluxConcatIterable.java:147)
at reactor.core.publisher.FluxConcatIterable.subscribe(FluxConcatIterable.java:61)
at reactor.core.publisher.MonoIgnoreElements.subscribe(MonoIgnoreElements.java:37)
```