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

log connection read timeouts at info level #1514

Merged
merged 1 commit into from
Dec 29, 2024
Merged
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
20 changes: 17 additions & 3 deletions p2p/src/main/java/haveno/network/p2p/network/Connection.java
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ public static int getShutdownTimeout() {
private static int numThrottledInvalidRequestReports = 0;
private static long lastLoggedWarningTs = 0;
private static int numThrottledWarnings = 0;
private static long lastLoggedInfoTs = 0;
private static int numThrottledInfos = 0;

///////////////////////////////////////////////////////////////////////////////////////////
// Constructor
Expand Down Expand Up @@ -676,7 +678,7 @@ private void handleException(Throwable e) {
throttleWarn("SocketException (expected if connection lost). closeConnectionReason=" + closeConnectionReason + "; connection=" + this);
} else if (e instanceof SocketTimeoutException || e instanceof TimeoutException) {
closeConnectionReason = CloseConnectionReason.SOCKET_TIMEOUT;
throttleWarn("Shut down caused by exception " + e.getMessage() + " on connection=" + this);
throttleInfo("Shut down caused by exception " + e.getMessage() + " on connection=" + this);
} else if (e instanceof EOFException) {
closeConnectionReason = CloseConnectionReason.TERMINATED;
throttleWarn("Shut down caused by exception " + e.getMessage() + " on connection=" + this);
Expand Down Expand Up @@ -937,8 +939,8 @@ private String getSenderNodeAddressAsString(NetworkEnvelope networkEnvelope) {
}

private synchronized void throttleWarn(String msg) {
boolean logWarning = System.currentTimeMillis() - lastLoggedWarningTs > LOG_THROTTLE_INTERVAL_MS;
if (logWarning) {
boolean doLog = System.currentTimeMillis() - lastLoggedWarningTs > LOG_THROTTLE_INTERVAL_MS;
if (doLog) {
log.warn(msg);
if (numThrottledWarnings > 0) log.warn("{} warnings were throttled since the last log entry", numThrottledWarnings);
numThrottledWarnings = 0;
Expand All @@ -947,4 +949,16 @@ private synchronized void throttleWarn(String msg) {
numThrottledWarnings++;
}
}

private synchronized void throttleInfo(String msg) {
boolean doLog = System.currentTimeMillis() - lastLoggedInfoTs > LOG_THROTTLE_INTERVAL_MS;
if (doLog) {
log.info(msg);
if (numThrottledInfos > 0) log.info("{} info logs were throttled since the last log entry", numThrottledInfos);
numThrottledInfos = 0;
lastLoggedInfoTs = System.currentTimeMillis();
} else {
numThrottledInfos++;
}
}
}
Loading