Search in sources :

Example 6 with IllegalReferenceCountException

use of org.apache.flink.shaded.netty4.io.netty.util.IllegalReferenceCountException in project netty by netty.

the class SslHandlerTest method newHandler.

private static ChannelHandler newHandler(final SslContext sslCtx, final Promise<Void> promise) {
    return new ChannelInitializer() {

        @Override
        protected void initChannel(final Channel ch) {
            final SslHandler sslHandler = sslCtx.newHandler(ch.alloc());
            sslHandler.setHandshakeTimeoutMillis(1000);
            ch.pipeline().addFirst(sslHandler);
            sslHandler.handshakeFuture().addListener(new FutureListener<Channel>() {

                @Override
                public void operationComplete(final Future<Channel> future) {
                    ch.pipeline().remove(sslHandler);
                    // Schedule the close so removal has time to propagate exception if any.
                    ch.eventLoop().execute(new Runnable() {

                        @Override
                        public void run() {
                            ch.close();
                        }
                    });
                }
            });
            ch.pipeline().addLast(new ChannelInboundHandlerAdapter() {

                @Override
                public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
                    if (cause instanceof CodecException) {
                        cause = cause.getCause();
                    }
                    if (cause instanceof IllegalReferenceCountException) {
                        promise.setFailure(cause);
                    }
                }

                @Override
                public void channelInactive(ChannelHandlerContext ctx) {
                    promise.trySuccess(null);
                }
            });
        }
    };
}
Also used : LocalServerChannel(io.netty.channel.local.LocalServerChannel) LocalChannel(io.netty.channel.local.LocalChannel) NioServerSocketChannel(io.netty.channel.socket.nio.NioServerSocketChannel) NioSocketChannel(io.netty.channel.socket.nio.NioSocketChannel) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) Channel(io.netty.channel.Channel) IllegalReferenceCountException(io.netty.util.IllegalReferenceCountException) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) CodecException(io.netty.handler.codec.CodecException) ChannelInitializer(io.netty.channel.ChannelInitializer) ChannelInboundHandlerAdapter(io.netty.channel.ChannelInboundHandlerAdapter)

Example 7 with IllegalReferenceCountException

use of org.apache.flink.shaded.netty4.io.netty.util.IllegalReferenceCountException in project netty by netty.

the class ReferenceCountUpdater method retryRelease0.

private boolean retryRelease0(T instance, int decrement) {
    for (; ; ) {
        int rawCnt = updater().get(instance), realCnt = toLiveRealRefCnt(rawCnt, decrement);
        if (decrement == realCnt) {
            if (tryFinalRelease0(instance, rawCnt)) {
                return true;
            }
        } else if (decrement < realCnt) {
            // all changes to the raw count are 2x the "real" change
            if (updater().compareAndSet(instance, rawCnt, rawCnt - (decrement << 1))) {
                return false;
            }
        } else {
            throw new IllegalReferenceCountException(realCnt, -decrement);
        }
        // this benefits throughput under high contention
        Thread.yield();
    }
}
Also used : IllegalReferenceCountException(io.netty.util.IllegalReferenceCountException)

Example 8 with IllegalReferenceCountException

use of org.apache.flink.shaded.netty4.io.netty.util.IllegalReferenceCountException in project flink by apache.

the class AbstractByteBufTest method assertDuplicateFailAfterRelease.

private static void assertDuplicateFailAfterRelease(ByteBuf... bufs) {
    for (ByteBuf buf : bufs) {
        if (buf.refCnt() > 0) {
            buf.release();
        }
    }
    for (ByteBuf buf : bufs) {
        try {
            assertEquals(0, buf.refCnt());
            buf.duplicate();
            fail();
        } catch (IllegalReferenceCountException ignored) {
        // as expected
        }
    }
}
Also used : IllegalReferenceCountException(org.apache.flink.shaded.netty4.io.netty.util.IllegalReferenceCountException) ByteBuf(org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf)

Example 9 with IllegalReferenceCountException

use of org.apache.flink.shaded.netty4.io.netty.util.IllegalReferenceCountException in project flink by apache.

the class AbstractByteBufTest method testMemoryAddressAfterRelease.

@Test
public void testMemoryAddressAfterRelease() {
    ByteBuf buf = releasedBuffer();
    if (buf.hasMemoryAddress()) {
        try {
            buf.memoryAddress();
            fail();
        } catch (IllegalReferenceCountException e) {
        // expected
        }
    }
}
Also used : IllegalReferenceCountException(org.apache.flink.shaded.netty4.io.netty.util.IllegalReferenceCountException) ByteBuf(org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf) Test(org.junit.Test)

Example 10 with IllegalReferenceCountException

use of org.apache.flink.shaded.netty4.io.netty.util.IllegalReferenceCountException in project flink by apache.

the class AbstractByteBufTest method testArrayAfterRelease.

@Test
public void testArrayAfterRelease() {
    ByteBuf buf = releasedBuffer();
    if (buf.hasArray()) {
        try {
            buf.array();
            fail();
        } catch (IllegalReferenceCountException e) {
        // expected
        }
    }
}
Also used : IllegalReferenceCountException(org.apache.flink.shaded.netty4.io.netty.util.IllegalReferenceCountException) ByteBuf(org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf) Test(org.junit.Test)

Aggregations

IllegalReferenceCountException (io.netty.util.IllegalReferenceCountException)6 ByteBuf (org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf)6 IllegalReferenceCountException (org.apache.flink.shaded.netty4.io.netty.util.IllegalReferenceCountException)6 Test (org.junit.Test)5 DrillBuf (io.netty.buffer.DrillBuf)2 ErrorResponse (discord4j.rest.json.response.ErrorResponse)1 Channel (io.netty.channel.Channel)1 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)1 ChannelInboundHandlerAdapter (io.netty.channel.ChannelInboundHandlerAdapter)1 ChannelInitializer (io.netty.channel.ChannelInitializer)1 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)1 LocalChannel (io.netty.channel.local.LocalChannel)1 LocalServerChannel (io.netty.channel.local.LocalServerChannel)1 NioServerSocketChannel (io.netty.channel.socket.nio.NioServerSocketChannel)1 NioSocketChannel (io.netty.channel.socket.nio.NioSocketChannel)1 CodecException (io.netty.handler.codec.CodecException)1 ClientConfiguration (org.apache.bookkeeper.conf.ClientConfiguration)1 BaseTest (org.apache.drill.test.BaseTest)1