r2dbc / r2dbc-mssql

R2DBC Driver for Microsoft SQL Server using TDS (Tabular Data Stream) Protocol
Apache License 2.0
183 stars 32 forks source link

ReactorNettyClient$MssqlConnectionClosedException: Connection closed when closing the connection (R2dbcEntityTemplate) #207

Closed RomainPruvostMHH closed 3 years ago

RomainPruvostMHH commented 3 years ago

Bug Report

Versions

Current Behavior

We get an unexpected error with the following code. We don't know why because our code is very simple. It's just a "SELECT 1" to check if the database is up or not. I precise that it isn't a blocking error because it appears when closing the connection.

Any help would be appreciate.

@Service
public class StatutRepositoryImpl implements StatutRepository {

    private final R2dbcEntityTemplate template;

    public StatutRepositoryImpl(final DatabaseClient databaseClient) {
        template = new R2dbcEntityTemplate(databaseClient);
    }

    @Override
    public Mono<Integer> checkConnectivityWithDatabase() {
        return template.getDatabaseClient()
                .execute("SELECT 1")
                .fetch()
                .first()
                .flatMap(r -> Mono.just(1));
    }

}
Stack trace ``` 2021-05-12 15:24:43,886 [reactor-tcp-epoll-1] ERROR reactor.netty.channel.ChannelOperationsHandler - [id: 0x55c613df, L:/172.18.0.78:44940 ! R:VWC2BDD069/10.87.21.45:1678] Error was received while reading the incoming data. The connection will be closed. reactor.core.Exceptions$BubblingException: io.r2dbc.mssql.client.ReactorNettyClient$MssqlConnectionClosedException: Connection closed at reactor.core.Exceptions.bubble(Exceptions.java:173) at reactor.core.publisher.Operators.onErrorDropped(Operators.java:635) at io.r2dbc.mssql.util.FluxDiscardOnCancel$FluxDiscardOnCancelSubscriber.onError(FluxDiscardOnCancel.java:94) at reactor.core.publisher.FluxPeek$PeekSubscriber.onError(FluxPeek.java:214) at reactor.core.publisher.FluxFilter$FilterSubscriber.onError(FluxFilter.java:151) at reactor.core.publisher.FluxHandle$HandleConditionalSubscriber.onError(FluxHandle.java:406) at reactor.core.publisher.EmitterProcessor.checkTerminated(EmitterProcessor.java:489) at reactor.core.publisher.EmitterProcessor.drain(EmitterProcessor.java:356) at reactor.core.publisher.EmitterProcessor.onError(EmitterProcessor.java:286) at reactor.core.publisher.FluxPeek$PeekSubscriber.onError(FluxPeek.java:214) at reactor.core.publisher.FluxPeek$PeekSubscriber.onError(FluxPeek.java:214) at reactor.core.publisher.FluxPeek$PeekSubscriber.onError(FluxPeek.java:214) at reactor.core.publisher.FluxHandle$HandleSubscriber.onError(FluxHandle.java:196) at reactor.core.publisher.MonoFlatMapMany$FlatMapManyInner.onError(MonoFlatMapMany.java:247) at reactor.core.publisher.FluxPeek$PeekSubscriber.onError(FluxPeek.java:214) at reactor.core.publisher.EmitterProcessor.checkTerminated(EmitterProcessor.java:489) at reactor.core.publisher.EmitterProcessor.drain(EmitterProcessor.java:356) at reactor.core.publisher.EmitterProcessor.onError(EmitterProcessor.java:286) at io.r2dbc.mssql.client.ReactorNettyClient.drainError(ReactorNettyClient.java:597) at io.r2dbc.mssql.client.ReactorNettyClient.handleClose(ReactorNettyClient.java:582) at io.r2dbc.mssql.client.ReactorNettyClient.access$600(ReactorNettyClient.java:82) at io.r2dbc.mssql.client.ReactorNettyClient$2.onComplete(ReactorNettyClient.java:286) at reactor.core.publisher.Operators$MultiSubscriptionSubscriber.onComplete(Operators.java:2016) at reactor.core.publisher.FluxPeek$PeekSubscriber.onComplete(FluxPeek.java:252) at reactor.netty.channel.FluxReceive.terminateReceiver(FluxReceive.java:450) at reactor.netty.channel.FluxReceive.drainReceiver(FluxReceive.java:247) at reactor.netty.channel.FluxReceive.onInboundNext(FluxReceive.java:371) at reactor.netty.channel.ChannelOperations.onInboundNext(ChannelOperations.java:358) at reactor.netty.channel.ChannelOperationsHandler.channelRead(ChannelOperationsHandler.java:96) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357) at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:93) at io.r2dbc.mssql.client.ssl.TdsSslHandler.channelRead(TdsSslHandler.java:380) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357) at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365) at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919) at io.netty.channel.epoll.AbstractEpollStreamChannel$EpollStreamUnsafe.epollInReady(AbstractEpollStreamChannel.java:795) at io.netty.channel.epoll.EpollEventLoop.processReady(EpollEventLoop.java:480) at io.netty.channel.epoll.EpollEventLoop.run(EpollEventLoop.java:378) at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989) at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) at java.base/java.lang.Thread.run(Thread.java:834) Caused by: io.r2dbc.mssql.client.ReactorNettyClient$MssqlConnectionClosedException: Connection closed at io.r2dbc.mssql.client.ReactorNettyClient.lambda$static$1(ReactorNettyClient.java:90) ... 30 common frames omitted ```

Table schema

Input Code ```sql -- your SQL here; ```

Steps to reproduce

Input Code ```java // your code here; ```

Expected behavior/code

Possible Solution

Additional context

mp911de commented 3 years ago

Does this happen on a regular basis or just incidentally?

RomainPruvostMHH commented 3 years ago

It happens every time we call the service

mp911de commented 3 years ago

With the little context it's impossible to say what happened before. Can you check for any disconnects or proceeding errors?

mp911de commented 3 years ago

Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.