Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: reduce error logging on connection resets #424

Merged
merged 4 commits into from
Jun 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 6.1.4
- Fix: reduce error logging on connection resets [#424](https://github.com/logstash-plugins/logstash-input-beats/pull/424)

## 6.1.3
- Fix: safe-guard byte buf allocation [#420](https://github.com/logstash-plugins/logstash-input-beats/pull/420)
- Updated Jackson dependencies
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.1.3
6.1.4
34 changes: 26 additions & 8 deletions src/main/java/org/logstash/beats/BeatsHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.util.AttributeKey;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.io.IOException;
import java.net.InetSocketAddress;
import javax.net.ssl.SSLHandshakeException;

Expand Down Expand Up @@ -40,7 +40,7 @@ public void channelInactive(ChannelHandlerContext ctx) throws Exception {


@Override
public void channelRead0(ChannelHandlerContext ctx, Batch batch) throws Exception {
public void channelRead0(ChannelHandlerContext ctx, Batch batch) {
if(logger.isDebugEnabled()) {
logger.debug(format("Received a new payload"));
}
Expand Down Expand Up @@ -81,19 +81,37 @@ public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws E
if (!(cause instanceof SSLHandshakeException)) {
messageListener.onException(ctx, cause);
}
final Throwable realCause = extractCause(cause, 0);
if (logger.isDebugEnabled()){
logger.debug(format("Handling exception: " + cause + " (caused by: " + realCause + ")"), cause);
if (isNoisyException(cause)) {
if (logger.isDebugEnabled()) {
logger.info(format("closing"), cause);
} else {
logger.info(format("closing (" + cause.getMessage() + ")"));
}
} else {
logger.info(format("Handling exception: " + cause + " (caused by: " + realCause + ")"));
final Throwable realCause = extractCause(cause, 0);
if (logger.isDebugEnabled()){
logger.info(format("Handling exception: " + cause + " (caused by: " + realCause + ")"), cause);
} else {
logger.info(format("Handling exception: " + cause + " (caused by: " + realCause + ")"));
}
super.exceptionCaught(ctx, cause);
}
} finally{
super.exceptionCaught(ctx, cause);
} finally {
ctx.flush();
ctx.close();
}
}

private boolean isNoisyException(final Throwable ex) {
if (ex instanceof IOException) {
final String message = ex.getMessage();
if ("Connection reset by peer".equals(message)) {
return true;
}
}
return false;
}

private boolean needAck(Message message) {
return message.getSequence() == message.getBatch().getHighestSequence();
}
Expand Down