* Prevent Confusing Blocked Thread Warnings in MockNioTransport * We can run into a race where the stacktrace collection and subsequent logging happens after the thread has already unblocked thus logging a confusing stacktrace of wherever the transport thread was after it became unblocked * Fixed this by comparing whether or not the recorded timestamp is still the same before and after the stacktrace was recorded and not logging if it already changed
This commit is contained in:
parent
e0b82e92f3
commit
099d52f3b0
|
@ -384,14 +384,17 @@ public class MockNioTransport extends TcpTransport {
|
||||||
|
|
||||||
private void logLongRunningExecutions() {
|
private void logLongRunningExecutions() {
|
||||||
for (Map.Entry<Thread, Long> entry : registry.entrySet()) {
|
for (Map.Entry<Thread, Long> entry : registry.entrySet()) {
|
||||||
final long elapsedTimeInNanos = threadPool.relativeTimeInNanos() - entry.getValue();
|
final Long blockedSinceInNanos = entry.getValue();
|
||||||
|
final long elapsedTimeInNanos = threadPool.relativeTimeInNanos() - blockedSinceInNanos;
|
||||||
if (elapsedTimeInNanos > warnThreshold) {
|
if (elapsedTimeInNanos > warnThreshold) {
|
||||||
final Thread thread = entry.getKey();
|
final Thread thread = entry.getKey();
|
||||||
|
final String stackTrace =
|
||||||
|
Arrays.stream(thread.getStackTrace()).map(Object::toString).collect(Collectors.joining("\n"));
|
||||||
|
final Thread.State threadState = thread.getState();
|
||||||
|
if (blockedSinceInNanos == registry.get(thread)) {
|
||||||
logger.warn("Potentially blocked execution on network thread [{}] [{}] [{} milliseconds]: \n{}",
|
logger.warn("Potentially blocked execution on network thread [{}] [{}] [{} milliseconds]: \n{}",
|
||||||
thread.getName(),
|
thread.getName(), threadState, TimeUnit.NANOSECONDS.toMillis(elapsedTimeInNanos), stackTrace);
|
||||||
thread.getState(),
|
}
|
||||||
TimeUnit.NANOSECONDS.toMillis(elapsedTimeInNanos),
|
|
||||||
Arrays.stream(thread.getStackTrace()).map(Object::toString).collect(Collectors.joining("\n")));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (stopped == false) {
|
if (stopped == false) {
|
||||||
|
|
Loading…
Reference in New Issue