Search in sources :

Example 16 with ChannelException

use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelException in project flink by apache.

the class AkkaBootstrapTools method startRemoteActorSystem.

/**
 * Starts a remote Actor System at given address and specific port.
 *
 * @param configuration The Flink configuration.
 * @param actorSystemName Name of the started {@link ActorSystem}
 * @param externalAddress The external address to access the ActorSystem.
 * @param externalPort The external port to access the ActorSystem.
 * @param bindAddress The local address to bind to.
 * @param bindPort The local port to bind to.
 * @param logger the logger to output log information.
 * @param actorSystemExecutorConfiguration configuration for the ActorSystem's underlying
 *     executor
 * @param customConfig Custom Akka config to be combined with the config derived from Flink
 *     configuration.
 * @return The ActorSystem which has been started.
 * @throws Exception
 */
private static ActorSystem startRemoteActorSystem(Configuration configuration, String actorSystemName, String externalAddress, int externalPort, String bindAddress, int bindPort, Logger logger, Config actorSystemExecutorConfiguration, Config customConfig) throws Exception {
    String externalHostPortUrl = NetUtils.unresolvedHostAndPortToNormalizedString(externalAddress, externalPort);
    String bindHostPortUrl = NetUtils.unresolvedHostAndPortToNormalizedString(bindAddress, bindPort);
    logger.info("Trying to start actor system, external address {}, bind address {}.", externalHostPortUrl, bindHostPortUrl);
    try {
        Config akkaConfig = AkkaUtils.getAkkaConfig(configuration, new HostAndPort(externalAddress, externalPort), new HostAndPort(bindAddress, bindPort), actorSystemExecutorConfiguration);
        if (customConfig != null) {
            akkaConfig = customConfig.withFallback(akkaConfig);
        }
        return startActorSystem(akkaConfig, actorSystemName, logger);
    } catch (Throwable t) {
        if (t instanceof ChannelException) {
            Throwable cause = t.getCause();
            if (cause != null && t.getCause() instanceof BindException) {
                throw new IOException("Unable to create ActorSystem at address " + bindHostPortUrl + " : " + cause.getMessage(), t);
            }
        }
        throw new Exception("Could not create actor system", t);
    }
}
Also used : Config(com.typesafe.config.Config) BindException(java.net.BindException) IOException(java.io.IOException) IOException(java.io.IOException) BindException(java.net.BindException) ChannelException(org.apache.flink.shaded.netty4.io.netty.channel.ChannelException) ChannelException(org.apache.flink.shaded.netty4.io.netty.channel.ChannelException)

Example 17 with ChannelException

use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelException in project netty by netty.

the class SslHandler method handlerRemoved0.

@Override
public void handlerRemoved0(ChannelHandlerContext ctx) throws Exception {
    try {
        if (!pendingUnencryptedWrites.isEmpty()) {
            // Check if queue is not empty first because create a new ChannelException is expensive
            pendingUnencryptedWrites.releaseAndFailAll(ctx, new ChannelException("Pending write on removal of SslHandler"));
        }
        pendingUnencryptedWrites = null;
        SSLException cause = null;
        // pipeline.
        if (!handshakePromise.isDone()) {
            cause = new SSLHandshakeException("SslHandler removed before handshake completed");
            if (handshakePromise.tryFailure(cause)) {
                ctx.fireUserEventTriggered(new SslHandshakeCompletionEvent(cause));
            }
        }
        if (!sslClosePromise.isDone()) {
            if (cause == null) {
                cause = new SSLException("SslHandler removed before SSLEngine was closed");
            }
            notifyClosePromise(cause);
        }
    } finally {
        ReferenceCountUtil.release(engine);
    }
}
Also used : SSLException(javax.net.ssl.SSLException) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) ChannelException(io.netty.channel.ChannelException) ClosedChannelException(java.nio.channels.ClosedChannelException)

Example 18 with ChannelException

use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelException in project netty by netty.

the class EpollSocketChannelConfigTest method testGetOptionWhenClosed.

// For this test to pass, we are relying on the sockets file descriptor not being reused after the socket is closed.
// This is inherently racy, so we allow getSoLinger to throw ChannelException a few of times, but eventually we do
// want to see a ClosedChannelException for the test to pass.
@RepeatedIfExceptionsTest(repeats = 4)
public void testGetOptionWhenClosed() {
    ch.close().syncUninterruptibly();
    ChannelException e = assertThrows(ChannelException.class, new Executable() {

        @Override
        public void execute() throws Throwable {
            ch.config().getSoLinger();
        }
    });
    assertThat(e).hasCauseInstanceOf(ClosedChannelException.class);
}
Also used : Executable(org.junit.jupiter.api.function.Executable) ClosedChannelException(java.nio.channels.ClosedChannelException) ChannelException(io.netty.channel.ChannelException) RepeatedIfExceptionsTest(io.github.artsok.RepeatedIfExceptionsTest)

Example 19 with ChannelException

use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelException in project netty by netty.

the class NioEventLoop method openSelector.

private SelectorTuple openSelector() {
    final Selector unwrappedSelector;
    try {
        unwrappedSelector = provider.openSelector();
    } catch (IOException e) {
        throw new ChannelException("failed to open a new selector", e);
    }
    if (DISABLE_KEY_SET_OPTIMIZATION) {
        return new SelectorTuple(unwrappedSelector);
    }
    Object maybeSelectorImplClass = AccessController.doPrivileged(new PrivilegedAction<Object>() {

        @Override
        public Object run() {
            try {
                return Class.forName("sun.nio.ch.SelectorImpl", false, PlatformDependent.getSystemClassLoader());
            } catch (Throwable cause) {
                return cause;
            }
        }
    });
    if (!(maybeSelectorImplClass instanceof Class) || // ensure the current selector implementation is what we can instrument.
    !((Class<?>) maybeSelectorImplClass).isAssignableFrom(unwrappedSelector.getClass())) {
        if (maybeSelectorImplClass instanceof Throwable) {
            Throwable t = (Throwable) maybeSelectorImplClass;
            logger.trace("failed to instrument a special java.util.Set into: {}", unwrappedSelector, t);
        }
        return new SelectorTuple(unwrappedSelector);
    }
    final Class<?> selectorImplClass = (Class<?>) maybeSelectorImplClass;
    final SelectedSelectionKeySet selectedKeySet = new SelectedSelectionKeySet();
    Object maybeException = AccessController.doPrivileged(new PrivilegedAction<Object>() {

        @Override
        public Object run() {
            try {
                Field selectedKeysField = selectorImplClass.getDeclaredField("selectedKeys");
                Field publicSelectedKeysField = selectorImplClass.getDeclaredField("publicSelectedKeys");
                if (PlatformDependent.javaVersion() >= 9 && PlatformDependent.hasUnsafe()) {
                    // Let us try to use sun.misc.Unsafe to replace the SelectionKeySet.
                    // This allows us to also do this in Java9+ without any extra flags.
                    long selectedKeysFieldOffset = PlatformDependent.objectFieldOffset(selectedKeysField);
                    long publicSelectedKeysFieldOffset = PlatformDependent.objectFieldOffset(publicSelectedKeysField);
                    if (selectedKeysFieldOffset != -1 && publicSelectedKeysFieldOffset != -1) {
                        PlatformDependent.putObject(unwrappedSelector, selectedKeysFieldOffset, selectedKeySet);
                        PlatformDependent.putObject(unwrappedSelector, publicSelectedKeysFieldOffset, selectedKeySet);
                        return null;
                    }
                // We could not retrieve the offset, lets try reflection as last-resort.
                }
                Throwable cause = ReflectionUtil.trySetAccessible(selectedKeysField, true);
                if (cause != null) {
                    return cause;
                }
                cause = ReflectionUtil.trySetAccessible(publicSelectedKeysField, true);
                if (cause != null) {
                    return cause;
                }
                selectedKeysField.set(unwrappedSelector, selectedKeySet);
                publicSelectedKeysField.set(unwrappedSelector, selectedKeySet);
                return null;
            } catch (NoSuchFieldException e) {
                return e;
            } catch (IllegalAccessException e) {
                return e;
            }
        }
    });
    if (maybeException instanceof Exception) {
        selectedKeys = null;
        Exception e = (Exception) maybeException;
        logger.trace("failed to instrument a special java.util.Set into: {}", unwrappedSelector, e);
        return new SelectorTuple(unwrappedSelector);
    }
    selectedKeys = selectedKeySet;
    logger.trace("instrumented a special java.util.Set into: {}", unwrappedSelector);
    return new SelectorTuple(unwrappedSelector, new SelectedSelectionKeySetSelector(unwrappedSelector, selectedKeySet));
}
Also used : IOException(java.io.IOException) CancelledKeyException(java.nio.channels.CancelledKeyException) EventLoopException(io.netty.channel.EventLoopException) IOException(java.io.IOException) ChannelException(io.netty.channel.ChannelException) Field(java.lang.reflect.Field) Selector(java.nio.channels.Selector) ChannelException(io.netty.channel.ChannelException)

Example 20 with ChannelException

use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelException in project netty by netty.

the class EpollSocketChannelConfig method setSendBufferSize.

@Override
public EpollSocketChannelConfig setSendBufferSize(int sendBufferSize) {
    try {
        ((EpollSocketChannel) channel).socket.setSendBufferSize(sendBufferSize);
        calculateMaxBytesPerGatheringWrite();
        return this;
    } catch (IOException e) {
        throw new ChannelException(e);
    }
}
Also used : IOException(java.io.IOException) ChannelException(io.netty.channel.ChannelException)

Aggregations

ChannelException (io.netty.channel.ChannelException)23 IOException (java.io.IOException)10 LengthFieldBasedFrameDecoder (io.netty.handler.codec.LengthFieldBasedFrameDecoder)4 ClosedChannelException (java.nio.channels.ClosedChannelException)4 JSONObjectDecoder (de.jackwhite20.japs.shared.pipeline.handler.JSONObjectDecoder)3 JSONObjectEncoder (de.jackwhite20.japs.shared.pipeline.handler.JSONObjectEncoder)3 Channel (io.netty.channel.Channel)3 LengthFieldPrepender (io.netty.handler.codec.LengthFieldPrepender)3 RepeatedIfExceptionsTest (io.github.artsok.RepeatedIfExceptionsTest)2 ByteBuf (io.netty.buffer.ByteBuf)2 ChannelFuture (io.netty.channel.ChannelFuture)2 BindException (java.net.BindException)2 InetSocketAddress (java.net.InetSocketAddress)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 Send (com.github.ambry.network.Send)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 SessionResumptionSslHandler (com.linkedin.r2.netty.handler.common.SessionResumptionSslHandler)1 Config (com.typesafe.config.Config)1 PulsarClientException (com.yahoo.pulsar.client.api.PulsarClientException)1 Connection (de.jackwhite20.japs.server.network.Connection)1