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

Avoid IllegalArgumentException when setting WebSocket error status #28836

Conversation

FlorianKirmaier
Copy link
Contributor

Fixing internal error, when the message of an exception doesn't contain any text.

In my application, this probably caused a memory leak. (Which I will retest with a fork, but it will take some time because the issue happened very infrequently)

This is how it looks in the log:

java.lang.IllegalArgumentException: Reason must not be empty
	at org.springframework.util.Assert.hasText(Assert.java:289) ~[spring-core-5.3.21.jar!/:5.3.21]
	at org.springframework.web.reactive.socket.CloseStatus.withReason(CloseStatus.java:184) ~[spring-webflux-5.3.21.jar!/:5.3.21]
	at org.springframework.web.reactive.socket.adapter.AbstractListenerWebSocketSession.onError(AbstractListenerWebSocketSession.java:250) ~[spring-webflux-5.3.21.jar!/:5.3.21]
	at reactor.core.publisher.StrictSubscriber.onError(StrictSubscriber.java:106) ~[reactor-core-3.4.19.jar!/:3.4.19]
	at reactor.core.publisher.FluxOnAssembly$OnAssemblySubscriber.onError(FluxOnAssembly.java:544) ~[reactor-core-3.4.19.jar!/:3.4.19]
	at reactor.core.publisher.FluxDoFinally$DoFinallySubscriber.onError(FluxDoFinally.java:119) ~[reactor-core-3.4.19.jar!/:3.4.19]
	at reactor.core.publisher.MonoFlatMap$FlatMapMain.secondError(MonoFlatMap.java:192) ~[reactor-core-3.4.19.jar!/:3.4.19]
	at reactor.core.publisher.MonoFlatMap$FlatMapInner.onError(MonoFlatMap.java:259) ~[reactor-core-3.4.19.jar!/:3.4.19]
	at reactor.core.publisher.MonoIgnoreElements$IgnoreElementsSubscriber.onError(MonoIgnoreElements.java:84) ~[reactor-core-3.4.19.jar!/:3.4.19]
	at reactor.core.publisher.FluxFlatMap$FlatMapMain.checkTerminated(FluxFlatMap.java:842) ~[reactor-core-3.4.19.jar!/:3.4.19]
	at reactor.core.publisher.FluxFlatMap$FlatMapMain.drainLoop(FluxFlatMap.java:608) ~[reactor-core-3.4.19.jar!/:3.4.19]
	at reactor.core.publisher.FluxFlatMap$FlatMapMain.drain(FluxFlatMap.java:588) ~[reactor-core-3.4.19.jar!/:3.4.19]
	at reactor.core.publisher.FluxFlatMap$FlatMapMain.innerError(FluxFlatMap.java:863) ~[reactor-core-3.4.19.jar!/:3.4.19]
	at reactor.core.publisher.FluxFlatMap$FlatMapInner.onError(FluxFlatMap.java:990) ~[reactor-core-3.4.19.jar!/:3.4.19]
	at reactor.core.publisher.MonoPeekTerminal$MonoTerminalPeekSubscriber.onError(MonoPeekTerminal.java:258) ~[reactor-core-3.4.19.jar!/:3.4.19]
	at reactor.core.publisher.FluxPeekFuseable$PeekConditionalSubscriber.onError(FluxPeekFuseable.java:903) ~[reactor-core-3.4.19.jar!/:3.4.19]
	at reactor.core.publisher.MonoSubscribeOn$SubscribeOnSubscriber.onError(MonoSubscribeOn.java:152) ~[reactor-core-3.4.19.jar!/:3.4.19]
	at reactor.core.publisher.SinkEmptyMulticast$VoidInner.error(SinkEmptyMulticast.java:247) ~[reactor-core-3.4.19.jar!/:3.4.19]
	at reactor.core.publisher.SinkEmptyMulticast.tryEmitError(SinkEmptyMulticast.java:88) ~[reactor-core-3.4.19.jar!/:3.4.19]
	at reactor.core.publisher.SinkEmptySerialized.tryEmitError(SinkEmptySerialized.java:65) ~[reactor-core-3.4.19.jar!/:3.4.19]
	at org.springframework.web.reactive.socket.adapter.AbstractListenerWebSocketSession.onError(AbstractListenerWebSocketSession.java:245) ~[spring-webflux-5.3.21.jar!/:5.3.21]
	at reactor.core.publisher.StrictSubscriber.onError(StrictSubscriber.java:106) ~[reactor-core-3.4.19.jar!/:3.4.19]
	at reactor.core.publisher.FluxOnAssembly$OnAssemblySubscriber.onError(FluxOnAssembly.java:544) ~[reactor-core-3.4.19.jar!/:3.4.19]
	at reactor.core.publisher.MonoPeekTerminal$MonoTerminalPeekSubscriber.onError(MonoPeekTerminal.java:258) ~[reactor-core-3.4.19.jar!/:3.4.19]
	at reactor.core.publisher.MonoNext$NextSubscriber.onError(MonoNext.java:93) ~[reactor-core-3.4.19.jar!/:3.4.19]
	at reactor.core.publisher.MonoNext$NextSubscriber.onError(MonoNext.java:93) ~[reactor-core-3.4.19.jar!/:3.4.19]
	at org.springframework.http.server.reactive.WriteResultPublisher$State.publishError(WriteResultPublisher.java:277) ~[spring-web-5.3.21.jar!/:5.3.21]
	at org.springframework.http.server.reactive.WriteResultPublisher.publishError(WriteResultPublisher.java:99) ~[spring-web-5.3.21.jar!/:5.3.21]
	at org.springframework.http.server.reactive.AbstractListenerWriteProcessor$State.onError(AbstractListenerWriteProcessor.java:479) ~[spring-web-5.3.21.jar!/:5.3.21]
	at org.springframework.http.server.reactive.AbstractListenerWriteProcessor.onError(AbstractListenerWriteProcessor.java:132) ~[spring-web-5.3.21.jar!/:5.3.21]
	at reactor.core.publisher.StrictSubscriber.onError(StrictSubscriber.java:106) ~[reactor-core-3.4.19.jar!/:3.4.19]
	at org.springframework.http.server.reactive.AbstractListenerReadPublisher$State.onError(AbstractListenerReadPublisher.java:497) ~[spring-web-5.3.21.jar!/:5.3.21]
	at org.springframework.http.server.reactive.AbstractListenerReadPublisher.onError(AbstractListenerReadPublisher.java:145) ~[spring-web-5.3.21.jar!/:5.3.21]
	at org.springframework.web.reactive.socket.adapter.AbstractListenerWebSocketSession.handleError(AbstractListenerWebSocketSession.java:208) ~[spring-webflux-5.3.21.jar!/:5.3.21]
	at org.springframework.web.reactive.socket.adapter.StandardWebSocketHandlerAdapter.onError(StandardWebSocketHandlerAdapter.java:120) ~[spring-webflux-5.3.21.jar!/:5.3.21]
	at org.apache.tomcat.websocket.server.WsHttpUpgradeHandler.onError(WsHttpUpgradeHandler.java:234) ~[tomcat-embed-websocket-9.0.64.jar!/:na]
	at org.apache.tomcat.websocket.server.WsHttpUpgradeHandler.upgradeDispatch(WsHttpUpgradeHandler.java:161) ~[tomcat-embed-websocket-9.0.64.jar!/:na]
	at org.apache.coyote.http11.upgrade.UpgradeProcessorInternal.dispatch(UpgradeProcessorInternal.java:60) ~[tomcat-embed-core-9.0.64.jar!/:na]
	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:59) ~[tomcat-embed-core-9.0.64.jar!/:na]
	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:890) ~[tomcat-embed-core-9.0.64.jar!/:na]
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1787) ~[tomcat-embed-core-9.0.64.jar!/:na]
	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) ~[tomcat-embed-core-9.0.64.jar!/:na]
	at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191) ~[tomcat-embed-core-9.0.64.jar!/:na]
	at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659) ~[tomcat-embed-core-9.0.64.jar!/:na]
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) ~[tomcat-embed-core-9.0.64.jar!/:na]
	at java.base/java.lang.Thread.run(Thread.java:833) ~[na:na]

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Jul 18, 2022
@rstoyanchev rstoyanchev self-assigned this Jul 20, 2022
@rstoyanchev rstoyanchev added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Jul 20, 2022
@rstoyanchev rstoyanchev added this to the 5.3.23 milestone Jul 20, 2022
@rstoyanchev
Copy link
Contributor

I think we could switch to a very generic message instead.

@FlorianKirmaier
Copy link
Contributor Author

Any suggestions? Then I will change the PR accordingly.

@sbrannen sbrannen added the in: web Issues in web modules (web, webmvc, webflux, websocket) label Jul 27, 2022
rstoyanchev pushed a commit that referenced this pull request Jul 29, 2022
@rstoyanchev rstoyanchev changed the title Fixing internal error, when the message of an exception doesn't contain any text. Avoid IllegalArgumentException when setting WebSocket error status Jul 29, 2022
@rstoyanchev
Copy link
Contributor

I've left it as a status-only response since the status code itself communicates the nature. I've also added logging with the exception message at INFO and the full stacktrace at DEBUG.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: bug A general bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants