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

[improve][broker] If there is a deadlock in the service, the probe should return a failure because the service may be unavailable #23634

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
c18aa62
[fix][broker]If there is a deadlock in the service, the probe should …
yyj8 Nov 23, 2024
90ff720
[fix][broker]If there is a deadlock in the service, the probe should …
yyj8 Nov 25, 2024
2b18156
[improvement][broker] If there is a deadlock in the service, the prob…
yyj8 Nov 26, 2024
70325c0
[improvement][broker] If there is a deadlock in the service, the prob…
yyj8 Nov 26, 2024
c230aa5
[improvement][broker] If there is a deadlock in the service, the prob…
yyj8 Nov 26, 2024
2c8819b
[improvement][broker] If there is a deadlock in the service, the prob…
yyj8 Nov 27, 2024
f17da50
[improvement][broker] If there is a deadlock in the service, the prob…
yyj8 Nov 27, 2024
dc53040
[improvement][broker] If there is a deadlock in the service, the prob…
yyj8 Dec 4, 2024
532e69f
[improvement][broker] If there is a deadlock in the service, the prob…
yyj8 Dec 4, 2024
e1a1dd5
[improvement][broker] If there is a deadlock in the service, the prob…
yyj8 Dec 4, 2024
69aba3e
[improvement][broker] If there is a deadlock in the service, the prob…
yyj8 Dec 8, 2024
5970dcc
[improvement][broker] If there is a deadlock in the service, the prob…
yyj8 Dec 22, 2024
830c01a
[improvement][broker] If there is a deadlock in the service, the prob…
yyj8 Dec 22, 2024
52ab050
[improvement][broker] If there is a deadlock in the service, the prob…
yyj8 Dec 24, 2024
5b0c2ec
[improvement][broker] If there is a deadlock in the service, the prob…
yyj8 Jan 3, 2025
b1eaedd
[improvement][broker] If there is a deadlock in the service, the prob…
yyj8 Jan 3, 2025
1a2f6aa
Fix checkstyle
lhotari Jan 3, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,33 @@ public class VipStatus {
// log a full thread dump when a deadlock is detected in status check once every 10 minutes
// to prevent excessive logging
private static final long LOG_THREADDUMP_INTERVAL_WHEN_DEADLOCK_DETECTED = 600000L;
private static volatile long threadDumpLoggedTimestamp;
private static volatile long lastCheckStatusTimestamp;

// Since the status endpoint doesn't have authentication, it will be necessary to have a solution to prevent
// introducing a new DoS vulnerability where calling the status endpoint in a tight loop could introduce
// significant load to the system. One way would be to check that the deadlock check is executed only
// when there's more than 1 seconds from the previous check.
// If it's less than that, the previous result of the deadlock check would be reused.
yyj8 marked this conversation as resolved.
Show resolved Hide resolved
private static final long DEADLOCK_DETECTED_INTERVAL = 1000L;
yyj8 marked this conversation as resolved.
Show resolved Hide resolved
private static volatile boolean brokerIsHealthy = true;
yyj8 marked this conversation as resolved.
Show resolved Hide resolved

@Context
protected ServletContext servletContext;

@GET
public String checkStatus() {
synchronized (VipStatus.class) {
lhotari marked this conversation as resolved.
Show resolved Hide resolved
if (System.currentTimeMillis() - lastCheckStatusTimestamp < DEADLOCK_DETECTED_INTERVAL) {
lastCheckStatusTimestamp = System.currentTimeMillis();
yyj8 marked this conversation as resolved.
Show resolved Hide resolved
if (brokerIsHealthy) {
return "OK";
} else {
throw new WebApplicationException(Status.SERVICE_UNAVAILABLE);
}
}
lastCheckStatusTimestamp = System.currentTimeMillis();
yyj8 marked this conversation as resolved.
Show resolved Hide resolved
}

String statusFilePath = (String) servletContext.getAttribute(ATTRIBUTE_STATUS_FILE_PATH);
@SuppressWarnings("unchecked")
Supplier<Boolean> isReadyProbe = (Supplier<Boolean>) servletContext.getAttribute(ATTRIBUTE_IS_READY_PROBE);
Expand All @@ -73,21 +93,23 @@ public String checkStatus() {
.map(threadInfo -> threadInfo.getThreadName()
+ "(tid=" + threadInfo.getThreadId() + ")")
.collect(Collectors.joining(", "));
if (System.currentTimeMillis() - threadDumpLoggedTimestamp
if (System.currentTimeMillis() - lastCheckStatusTimestamp
> LOG_THREADDUMP_INTERVAL_WHEN_DEADLOCK_DETECTED) {
String diagnosticResult = ThreadDumpUtil.buildThreadDiagnosticString();
log.error("Deadlock detected, service may be unavailable, "
+ "thread stack details are as follows: {}.", diagnosticResult);
threadDumpLoggedTimestamp = System.currentTimeMillis();
} else {
log.error("Deadlocked threads detected. {}", threadNames);
}
brokerIsHealthy = false;
throw new WebApplicationException(Status.SERVICE_UNAVAILABLE);
} else {
brokerIsHealthy = true;
return "OK";
}
}
}
brokerIsHealthy = false;
log.warn("Failed to access \"status.html\". The service is not ready");
throw new WebApplicationException(Status.NOT_FOUND);
}
Expand Down