javax.net.ssl.SSLException: SSLEngine closed already occasionally for proxied requests
Cloud Gateway version:2.0.1 RELEASE Reactor Netty version: 0.7.8 RELEASE
In our production system, we're observing javax.net.ssl.SSLException: SSLEngine exceptions. The encounter rate has a correlation with the route count, hence traffic. There are other people who came across with the same problem in this inactive issue:https://github.com/spring-cloud/spring-cloud-gateway/issues/228
I'm using elastic pool(default) while proxying requests. Stacktrace:
com.netflix.hystrix.exception.HystrixRuntimeException: xyz failed and no fallback available.
at com.netflix.hystrix.AbstractCommand$22.call(AbstractCommand.java:819)
at com.netflix.hystrix.AbstractCommand$22.call(AbstractCommand.java:804)
at rx.internal.operators.OperatorOnErrorResumeNextViaFunction$4.onError(OperatorOnErrorResumeNextViaFunction.java:140)
at rx.internal.operators.OnSubscribeDoOnEach$DoOnEachSubscriber.onError(OnSubscribeDoOnEach.java:87)
at rx.internal.operators.OnSubscribeDoOnEach$DoOnEachSubscriber.onError(OnSubscribeDoOnEach.java:87)
at com.netflix.hystrix.AbstractCommand$DeprecatedOnFallbackHookApplication$1.onError(AbstractCommand.java:1472)
at com.netflix.hystrix.AbstractCommand$FallbackHookApplication$1.onError(AbstractCommand.java:1397)
at rx.internal.operators.OnSubscribeDoOnEach$DoOnEachSubscriber.onError(OnSubscribeDoOnEach.java:87)
at rx.internal.operators.OnSubscribeThrow.call(OnSubscribeThrow.java:44)
at rx.internal.operators.OnSubscribeThrow.call(OnSubscribeThrow.java:28)
at rx.Observable.unsafeSubscribe(Observable.java:10327)
at rx.internal.operators.OnSubscribeDoOnEach.call(OnSubscribeDoOnEach.java:41)
at rx.internal.operators.OnSubscribeDoOnEach.call(OnSubscribeDoOnEach.java:30)
at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48)
at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)
at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48)
at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)
at rx.Observable.unsafeSubscribe(Observable.java:10327)
at rx.internal.operators.OnSubscribeDoOnEach.call(OnSubscribeDoOnEach.java:41)
at rx.internal.operators.OnSubscribeDoOnEach.call(OnSubscribeDoOnEach.java:30)
at rx.Observable.unsafeSubscribe(Observable.java:10327)
at rx.internal.operators.OnSubscribeDoOnEach.call(OnSubscribeDoOnEach.java:41)
at rx.internal.operators.OnSubscribeDoOnEach.call(OnSubscribeDoOnEach.java:30)
at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48)
at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)
at rx.Observable.unsafeSubscribe(Observable.java:10327)
at rx.internal.operators.OnSubscribeDoOnEach.call(OnSubscribeDoOnEach.java:41)
at rx.internal.operators.OnSubscribeDoOnEach.call(OnSubscribeDoOnEach.java:30)
at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48)
at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)
at rx.Observable.unsafeSubscribe(Observable.java:10327)
at rx.internal.operators.OperatorOnErrorResumeNextViaFunction$4.onError(OperatorOnErrorResumeNextViaFunction.java:142)
at rx.internal.operators.OnSubscribeDoOnEach$DoOnEachSubscriber.onError(OnSubscribeDoOnEach.java:87)
at rx.internal.operators.OnSubscribeDoOnEach$DoOnEachSubscriber.onError(OnSubscribeDoOnEach.java:87)
at com.netflix.hystrix.AbstractCommand$HystrixObservableTimeoutOperator$2.onError(AbstractCommand.java:1194)
at rx.observers.Subscribers$5.onError(Subscribers.java:230)
at com.netflix.hystrix.AbstractCommand$DeprecatedOnRunHookApplication$1.onError(AbstractCommand.java:1431)
at com.netflix.hystrix.AbstractCommand$ExecutionHookApplication$1.onError(AbstractCommand.java:1362)
at rx.internal.reactivestreams.SubscriberAdapter.onError(SubscriberAdapter.java:59)
at reactor.core.publisher.StrictSubscriber.onError(StrictSubscriber.java:106)
at reactor.core.publisher.Operators$MonoSubscriber.onError(Operators.java:1126)
at reactor.core.publisher.MonoIgnoreThen$ThenIgnoreInner.onError(MonoIgnoreThen.java:234)
at reactor.core.publisher.FluxPeek$PeekSubscriber.onError(FluxPeek.java:207)
at reactor.core.publisher.FluxMap$MapSubscriber.onError(FluxMap.java:120)
at reactor.core.publisher.FluxRetryPredicate$RetryPredicateSubscriber.onError(FluxRetryPredicate.java:100)
at reactor.core.publisher.MonoCreate$DefaultMonoSink.error(MonoCreate.java:166)
at reactor.ipc.netty.channel.ContextHandler.fireContextError(ContextHandler.java:272)
at reactor.ipc.netty.http.client.HttpClientOperations.onOutboundError(HttpClientOperations.java:526)
at reactor.ipc.netty.channel.ChannelOperations.onError(ChannelOperations.java:232)
at reactor.core.publisher.Operators$MonoSubscriber.onError(Operators.java:1126)
at reactor.core.publisher.MonoIgnoreThen$ThenIgnoreInner.onError(MonoIgnoreThen.java:234)
at reactor.ipc.netty.FutureMono$FutureSubscription.operationComplete(FutureMono.java:290)
at io.netty.util.concurrent.DefaultPromise.notifyListener0(DefaultPromise.java:511)
at io.netty.util.concurrent.DefaultPromise.notifyListenersNow(DefaultPromise.java:485)
at io.netty.util.concurrent.DefaultPromise.notifyListeners(DefaultPromise.java:424)
at io.netty.util.concurrent.DefaultPromise.tryFailure(DefaultPromise.java:121)
at io.netty.util.internal.PromiseNotificationUtil.tryFailure(PromiseNotificationUtil.java:64)
at io.netty.channel.DelegatingChannelPromiseNotifier.operationComplete(DelegatingChannelPromiseNotifier.java:57)
at io.netty.channel.DelegatingChannelPromiseNotifier.operationComplete(DelegatingChannelPromiseNotifier.java:31)
at io.netty.util.concurrent.DefaultPromise.notifyListener0(DefaultPromise.java:511)
at io.netty.util.concurrent.DefaultPromise.notifyListenersNow(DefaultPromise.java:485)
at io.netty.util.concurrent.DefaultPromise.notifyListeners(DefaultPromise.java:424)
at io.netty.util.concurrent.DefaultPromise.tryFailure(DefaultPromise.java:121)
at io.netty.util.internal.PromiseNotificationUtil.tryFailure(PromiseNotificationUtil.java:64)
at io.netty.channel.DelegatingChannelPromiseNotifier.operationComplete(DelegatingChannelPromiseNotifier.java:57)
at io.netty.channel.DelegatingChannelPromiseNotifier.operationComplete(DelegatingChannelPromiseNotifier.java:31)
at io.netty.util.concurrent.DefaultPromise.notifyListener0(DefaultPromise.java:511)
at io.netty.util.concurrent.DefaultPromise.notifyListeners0(DefaultPromise.java:504)
at io.netty.util.concurrent.DefaultPromise.notifyListenersNow(DefaultPromise.java:483)
at io.netty.util.concurrent.DefaultPromise.notifyListeners(DefaultPromise.java:424)
at io.netty.util.concurrent.DefaultPromise.tryFailure(DefaultPromise.java:121)
at io.netty.handler.ssl.SslHandler.wrap(SslHandler.java:808)
at io.netty.handler.ssl.SslHandler.wrapAndFlush(SslHandler.java:771)
at io.netty.handler.ssl.SslHandler.flush(SslHandler.java:752)
at io.netty.handler.ssl.SslHandler.flush(SslHandler.java:1625)
at io.netty.handler.ssl.SslHandler.closeOutboundAndChannel(SslHandler.java:1593)
at io.netty.handler.ssl.SslHandler.close(SslHandler.java:710)
at io.netty.channel.AbstractChannelHandlerContext.invokeClose(AbstractChannelHandlerContext.java:624)
at io.netty.channel.AbstractChannelHandlerContext.close(AbstractChannelHandlerContext.java:608)
at io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.close(CombinedChannelDuplexHandler.java:507)
at io.netty.channel.ChannelOutboundHandlerAdapter.close(ChannelOutboundHandlerAdapter.java:71)
at io.netty.channel.CombinedChannelDuplexHandler.close(CombinedChannelDuplexHandler.java:318)
at io.netty.channel.AbstractChannelHandlerContext.invokeClose(AbstractChannelHandlerContext.java:624)
at io.netty.channel.AbstractChannelHandlerContext.close(AbstractChannelHandlerContext.java:608)
at io.netty.channel.ChannelDuplexHandler.close(ChannelDuplexHandler.java:73)
at io.netty.channel.AbstractChannelHandlerContext.invokeClose(AbstractChannelHandlerContext.java:624)
at io.netty.channel.AbstractChannelHandlerContext.close(AbstractChannelHandlerContext.java:608)
at io.netty.channel.AbstractChannelHandlerContext.close(AbstractChannelHandlerContext.java:465)
at io.netty.channel.DefaultChannelPipeline.close(DefaultChannelPipeline.java:1003)
at io.netty.channel.AbstractChannel.close(AbstractChannel.java:238)
at reactor.ipc.netty.channel.FluxReceive.onInboundError(FluxReceive.java:356)
at reactor.ipc.netty.channel.ChannelOperations.onInboundError(ChannelOperations.java:428)
at reactor.ipc.netty.channel.ChannelOperationsHandler.exceptionCaught(ChannelOperationsHandler.java:180)
at io.netty.channel.AbstractChannelHandlerContext.invokeExceptionCaught(AbstractChannelHandlerContext.java:285)
at io.netty.channel.AbstractChannelHandlerContext.invokeExceptionCaught(AbstractChannelHandlerContext.java:264)
at io.netty.channel.AbstractChannelHandlerContext.fireExceptionCaught(AbstractChannelHandlerContext.java:256)
at io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireExceptionCaught(CombinedChannelDuplexHandler.java:426)
at io.netty.channel.ChannelHandlerAdapter.exceptionCaught(ChannelHandlerAdapter.java:87)
at io.netty.channel.CombinedChannelDuplexHandler$1.fireExceptionCaught(CombinedChannelDuplexHandler.java:147)
at io.netty.channel.ChannelInboundHandlerAdapter.exceptionCaught(ChannelInboundHandlerAdapter.java:131)
at io.netty.channel.CombinedChannelDuplexHandler.exceptionCaught(CombinedChannelDuplexHandler.java:233)
at io.netty.channel.AbstractChannelHandlerContext.invokeExceptionCaught(AbstractChannelHandlerContext.java:285)
at io.netty.channel.AbstractChannelHandlerContext.invokeExceptionCaught(AbstractChannelHandlerContext.java:264)
at io.netty.channel.AbstractChannelHandlerContext.fireExceptionCaught(AbstractChannelHandlerContext.java:256)
at io.netty.channel.ChannelInboundHandlerAdapter.exceptionCaught(ChannelInboundHandlerAdapter.java:131)
at io.netty.channel.AbstractChannelHandlerContext.invokeExceptionCaught(AbstractChannelHandlerContext.java:285)
at io.netty.channel.AbstractChannelHandlerContext.invokeExceptionCaught(AbstractChannelHandlerContext.java:264)
at io.netty.channel.AbstractChannelHandlerContext.fireExceptionCaught(AbstractChannelHandlerContext.java:256)
at io.netty.handler.ssl.SslHandler.exceptionCaught(SslHandler.java:1048)
at io.netty.channel.AbstractChannelHandlerContext.invokeExceptionCaught(AbstractChannelHandlerContext.java:285)
at io.netty.channel.AbstractChannelHandlerContext.invokeExceptionCaught(AbstractChannelHandlerContext.java:264)
at io.netty.channel.AbstractChannelHandlerContext.fireExceptionCaught(AbstractChannelHandlerContext.java:256)
at io.netty.channel.DefaultChannelPipeline$HeadContext.exceptionCaught(DefaultChannelPipeline.java:1401)
at io.netty.channel.AbstractChannelHandlerContext.invokeExceptionCaught(AbstractChannelHandlerContext.java:285)
at io.netty.channel.AbstractChannelHandlerContext.invokeExceptionCaught(AbstractChannelHandlerContext.java:264)
at io.netty.channel.DefaultChannelPipeline.fireExceptionCaught(DefaultChannelPipeline.java:953)
at io.netty.channel.epoll.AbstractEpollStreamChannel$EpollStreamUnsafe.handleReadException(AbstractEpollStreamChannel.java:745)
at io.netty.channel.epoll.AbstractEpollStreamChannel$EpollStreamUnsafe.epollInReady(AbstractEpollStreamChannel.java:834)
at io.netty.channel.epoll.EpollEventLoop.processReady(EpollEventLoop.java:417)
at io.netty.channel.epoll.EpollEventLoop.run(EpollEventLoop.java:317)
at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:884)
at java.lang.Thread.run(Thread.java:748)
Caused by: javax.net.ssl.SSLException: SSLEngine closed already
at io.netty.handler.ssl.SslHandler.wrap(...)(Unknown Source)
I don't think these errors are specific to the gateway. More likely reactor-netty
@smaldini or @violetagg?
Yesterday I've upgraded spring-cloud-gateway from 2.0.2.BUILD-SNAPSHOT to 2.1.0.M1 and spring-cloud-dependencies from Finchley.SR1 to Finchley.SR2, after this upgrade I started seeing this SSLEngine closed already exception.
The reason I upgraded this was that I was experiencing a problem with WebSocket connections not being properly closed (more about that here https://github.com/spring-cloud/spring-cloud-gateway/issues/260 & https://jira.spring.io/browse/SPR-16774).
Both problems somehow relate to Netty, I'll do some more experiments and let you guys know if I manage to fix it.
For now, thanks, everyone.
2.1.0.M1 is not compatible with Finchley or boot 2.0.x
Hey @spencergibb, thanks for answering so quick.
Which versions are known to work well with 2.1.0.M1?
Greenwich.M1 or (BUILD-SNAPSHOT if you like to live dangerously)
Thanks @ryanjbaxter
I just tried 2.1.0.M1 with Greenwich.M1 running on top of Spring Boot v2.0.6.RELEASE.
In my log I see these exceptions:
javax.net.ssl.SSLException: SSLEngine closed already
When I roll back to my previous version spring-cloud-gateway:2.0.2.BUILD-SNAPSHOT spring-cloud-dependencies:Finchley.SR1 running on top of Spring Boot v2.0.6.RELEASE, I get this exception:
io.netty.util.ResourceLeakDetector : LEAK: ByteBuf.release() was not called before it's garbage-collected.
// also..
r.ipc.netty.channel.ContextHandler : Error cannot be forwarded to user-facing Mono
I believe my servers running Spring Cloud Gateway are degrading over the week because the connections with WebSockets are not being closed properly as posted here: https://github.com/spring-cloud/spring-cloud-gateway/issues/260.
For now, I'm keeping the rolled back version because it degrades over time, but the first crashes after a few minutes.
I just tried 2.1.0.M1 with Greenwich.M1 running on top of Spring Boot v2.0.6.RELEASE.
This does not make sense.
Try using Boot 2.1.0.RELEASE and Greenwich.BUILD-SNAPSHOT and let us know what happens.
now 2.1.2.RELEASE and Greenwich.RELEASE
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.
I can confirm, that we are experiencing the similar issue on versions 2.1.2.RELEASE and Greenwich.RELEASE.
2019-02-06 13:20:56.557 ERROR 2763 --- [ctor-http-nio-3] r.netty.http.client.HttpClientConnect : [id: 0xe39acb63, L:/127.0.0.1:59202 - R:localhost/127.0.0.1:50111] The connection observed an error
javax.net.ssl.SSLException: SSLEngine closed already
at io.netty.handler.ssl.SslHandler.wrap(...)(Unknown Source) ~[netty-handler-4.1.31.Final.jar!/:4.1.31.Final]
@maniek45 Can you try with <reactor-bom.version>Californium-BUILD-SNAPSHOT</reactor-bom.version>
This version cannot be downloaded from default maven repositories I have in my build.gradle. Do I need to add additional repo in order to download this dependency?
@maniek45 https://repo.spring.io/snapshot
Thanks for response. On 'Californium-BUILD-SNAPSHOT' version we cannot see the 'SSLEngine closed already' issue, but there is another one. For some reason web browser websockets proxied via gateway are not being closed. Something similar to issue: https://github.com/spring-cloud/spring-cloud-gateway/issues/260.
@maniek45 Can you provide reproducible example?
I've created two github projects to reproduce issue:
- https://github.com/maniek45/gateway - spring cloud gateway
- https://github.com/maniek45/websocket - websocket server running on wildfly
All of the above can be run on localhost, wildfly should be started as follows:
# standalone.bat -Djboss.https.port=50334
The client is implemented as web page and can be accessed by following link: https://localhost:50222/
In order to trace the websocket state, I've used the Chrome browser and opened its Developer Tools. The "Time" column shows "Pending" if client websocket is connected and time if it has been closed.

The scenario which I've tested was as follows:
- Start wildfly application server and deploy war artifact from websocket project (description in project README)
- Start spring cloud gateway from gateway project (description in project README)
- Open chrome web browser and go to https://localhost:50222 web page
- Turn on the Developer Tools (Ctrl+F12)
- In Developer Tools select Network tab and then WS tabs (see the screenshot above)
- On the web page press "Open connection" button to open new websocket (in Developer Tools a new entry should be added)
- Type any text in "Text to send" field and press "Send text" button
- If everything is working then below "Server response:" label, the same text (prefixed by number) should be visible as many times as number of text's that have been send
- Press "Close connection" button
- Check what state the websocket in Developer Tools is shown, if it is a time then close was successful, if "Pending" then the issue happens (any after about 1 minute the socket is being closed likely by gateway timer)
I've attached also gateway log file (zipped): gateway.zip
Generally from the gateway log (contains only two websocket requests) I noticed that the issue happens when request is handled by two threads. See the lines with reactor.netty.channel.FluxReceive (lines 1927,1929). When the same two lines are handled on same thread (lines 2037, 2039) client websocket closes immediately.
ping @violetagg
@bcelenk @maniek45 There was some work done in reactor-netty that might have solved that issue; could you retry it on Gateway Greenwich.SR1and let us know if the issue still persists?
Thanks for info. I will try to re-run the examples I've prepared to reproduce the issue.
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.