io.netty.channel.unix.Errors Java Examples

The following examples show how to use io.netty.channel.unix.Errors. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ClientRequestReceiver.java    From zuul with Apache License 2.0 6 votes vote down vote up
private void fireWriteError(String requestPart, Throwable cause, ChannelHandlerContext ctx) throws Exception {

        final String errMesg = String.format("Error writing %s to client", requestPart);

        if (cause instanceof java.nio.channels.ClosedChannelException ||
                cause instanceof Errors.NativeIoException) {
            LOG.info(errMesg + " - client connection is closed.");
            if (zuulRequest != null) {
                zuulRequest.getContext().cancel();
                StatusCategoryUtils.storeStatusCategoryIfNotAlreadyFailure(zuulRequest.getContext(), ZuulStatusCategory.FAILURE_CLIENT_CANCELLED);
            }
        }
        else {
            LOG.error(errMesg, cause);
            ctx.fireExceptionCaught(new ZuulException(cause, errMesg, true));
        }
    }
 
Example #2
Source File: SwallowSomeHttp2ExceptionsHandler.java    From zuul with Apache License 2.0 6 votes vote down vote up
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception
{
    incrementExceptionCounter(cause);

    if (cause instanceof Http2Exception) {
        Http2Exception h2e = (Http2Exception) cause;
        if (h2e.error() == Http2Error.NO_ERROR
                && Http2Exception.ShutdownHint.GRACEFUL_SHUTDOWN.equals(h2e.shutdownHint())) {
            // This is the exception we threw ourselves to make the http2 codec gracefully close the connection. So just
            // swallow it so that it doesn't propagate and get logged.
            LOG.debug("Swallowed Http2Exception.ShutdownHint.GRACEFUL_SHUTDOWN ", cause);
        }
        else {
            super.exceptionCaught(ctx, cause);
        }
    }
    else if (cause instanceof Errors.NativeIoException) {
        LOG.debug("Swallowed NativeIoException", cause);
    }
    else {
        super.exceptionCaught(ctx, cause);
    }
}
 
Example #3
Source File: KQueueSocketRstTest.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
@Override
protected void assertRstOnCloseException(IOException cause, Channel clientChannel) {
    if (!AbstractKQueueChannel.class.isInstance(clientChannel)) {
        super.assertRstOnCloseException(cause, clientChannel);
        return;
    }

    assertTrue("actual [type, message]: [" + cause.getClass() + ", " + cause.getMessage() + "]",
               cause instanceof NativeIoException);
    assertEquals(Errors.ERRNO_ECONNRESET_NEGATIVE, ((NativeIoException) cause).expectedErr());
}
 
Example #4
Source File: EpollSocketRstTest.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
@Override
protected void assertRstOnCloseException(IOException cause, Channel clientChannel) {
    if (!AbstractEpollChannel.class.isInstance(clientChannel)) {
        super.assertRstOnCloseException(cause, clientChannel);
        return;
    }

    assertTrue("actual [type, message]: [" + cause.getClass() + ", " + cause.getMessage() + "]",
               cause instanceof NativeIoException);
    assertEquals(Errors.ERRNO_ECONNRESET_NEGATIVE, ((NativeIoException) cause).expectedErr());
}
 
Example #5
Source File: RpcServerHandler.java    From brpc-java with Apache License 2.0 5 votes vote down vote up
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
    if (ctx.channel().isActive()
            && !(cause instanceof Errors.NativeIoException)
            && !(cause instanceof IOException)) {
        log.info("service exception, ex={}", cause.getMessage());
    }
    log.debug("meet exception, may be connection is closed, msg={}", cause.getMessage());
    log.debug("remove from channel map");
    ChannelManager.getInstance().removeChannel(ctx.channel());
    ctx.close();
}
 
Example #6
Source File: DiscordUtils.java    From Shadbot with GNU General Public License v3.0 5 votes vote down vote up
/**
 * @param spec A {@link Consumer} that provides a "blank" {@link MessageCreateSpec} to be operated on.
 * @param channel The {@link MessageChannel} in which to send the message.
 * @param hasEmbed Whether or not the spec contains an embed.
 * @return A {@link Mono} where, upon successful completion, emits the created Message. If an error is received,
 * it is emitted through the Mono.
 */
public static Mono<Message> sendMessage(Consumer<MessageCreateSpec> spec, MessageChannel channel, boolean hasEmbed) {
    return Mono.zip(
            DiscordUtils.hasPermission(channel, channel.getClient().getSelfId(), Permission.SEND_MESSAGES),
            DiscordUtils.hasPermission(channel, channel.getClient().getSelfId(), Permission.EMBED_LINKS))
            .flatMap(TupleUtils.function((canSendMessage, canSendEmbed) -> {
                if (!canSendMessage) {
                    DEFAULT_LOGGER.info("{Channel ID: {}} Missing permission: {}",
                            channel.getId().asLong(), FormatUtils.capitalizeEnum(Permission.SEND_MESSAGES));
                    return Mono.empty();
                }

                if (!canSendEmbed && hasEmbed) {
                    DEFAULT_LOGGER.info("{Channel ID: {}} Missing permission: {}",
                            channel.getId().asLong(), FormatUtils.capitalizeEnum(Permission.EMBED_LINKS));
                    return DiscordUtils.sendMessage(String.format(Emoji.ACCESS_DENIED + " I cannot send embed" +
                                    " links.%nPlease, check my permissions "
                                    + "and channel-specific ones to verify that **%s** is checked.",
                            FormatUtils.capitalizeEnum(Permission.EMBED_LINKS)), channel);
                }

                return channel.createMessage(spec
                        .andThen(messageSpec -> messageSpec.setAllowedMentions(AllowedMentions.builder()
                                .parseType(AllowedMentions.Type.ROLE, AllowedMentions.Type.USER)
                                .build())));
            }))
            // 403 Forbidden means that the bot is not in the guild
            .onErrorResume(ClientException.isStatusCode(HttpResponseStatus.FORBIDDEN.code()), err -> Mono.empty())
            .retryWhen(Retry.backoff(3, Duration.ofSeconds(1))
                    .filter(err -> err instanceof PrematureCloseException || err instanceof Errors.NativeIoException));
}
 
Example #7
Source File: PassportStateServerHandler.java    From zuul with Apache License 2.0 5 votes vote down vote up
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception
{
    passport(ctx).add(PassportState.SERVER_CH_EXCEPTION);
    if (cause instanceof Errors.NativeIoException) {
        LOG.debug("PassportStateServerHandler Inbound NativeIoException " + cause);
        incrementExceptionCounter(cause, "PassportStateServerHandler.Inbound");
    } else {
        super.exceptionCaught(ctx, cause);
    }
}
 
Example #8
Source File: PassportStateServerHandler.java    From zuul with Apache License 2.0 5 votes vote down vote up
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception
{
    passport(ctx).add(PassportState.SERVER_CH_EXCEPTION);
    if (cause instanceof Errors.NativeIoException) {
        LOG.debug("PassportStateServerHandler Outbound NativeIoException " + cause);
        incrementExceptionCounter(cause, "PassportStateServerHandler.Outbound");
    } else {
        super.exceptionCaught(ctx, cause);
    }
}
 
Example #9
Source File: NettyRequestAttemptFactory.java    From zuul with Apache License 2.0 5 votes vote down vote up
public ErrorType mapNettyToOutboundErrorType(final Throwable t) {
    if (t instanceof ReadTimeoutException) {
        return READ_TIMEOUT;
    }

    if (t instanceof OriginConcurrencyExceededException) {
        return ORIGIN_CONCURRENCY_EXCEEDED;
    }

    if (t instanceof OriginConnectException) {
        return ((OriginConnectException) t).getErrorType();
    }

    if (t instanceof OutboundException) {
        return ((OutboundException) t).getOutboundErrorType();
    }

    if (t instanceof Errors.NativeIoException && Errors.ERRNO_ECONNRESET_NEGATIVE == ((Errors.NativeIoException) t).expectedErr()) {
        // This is a "Connection reset by peer" which we see fairly often happening when Origin servers are overloaded.
        LOG.warn("ERRNO_ECONNRESET_NEGATIVE mapped to RESET_CONNECTION", t);
        return RESET_CONNECTION;
    }

    if (t instanceof ClosedChannelException) {
        return RESET_CONNECTION;
    }

    final Throwable cause = t.getCause();
    if (cause instanceof IllegalStateException && cause.getMessage().contains("server")) {
        LOG.warn("IllegalStateException mapped to NO_AVAILABLE_SERVERS", cause);
        return NO_AVAILABLE_SERVERS;
    }

    return OTHER;
}
 
Example #10
Source File: ZuulFilterChainHandler.java    From zuul with Apache License 2.0 5 votes vote down vote up
private boolean isClientChannelClosed(Throwable cause) {
    if (cause instanceof ClosedChannelException ||
            cause instanceof Errors.NativeIoException) {
        LOG.error("ZuulFilterChainHandler::isClientChannelClosed - IO Exception");
        return true;
    }
    return false;
}