-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Does not log while AgentHealthManager is locked. (#1599)
There could have been a deadlock if AgentHealthManager is invalidated while a change in Health is happening from different threads. Details see #1597
- Loading branch information
Showing
2 changed files
with
84 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
...a/rocks/inspectit/ocelot/core/selfmonitoring/AgentHealthManagerDeadlockGh1597IntTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package rocks.inspectit.ocelot.core.selfmonitoring; | ||
|
||
import org.awaitility.Awaitility; | ||
import org.checkerframework.checker.units.qual.A; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.Timeout; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.test.annotation.DirtiesContext; | ||
import rocks.inspectit.ocelot.core.SpringTestBase; | ||
import rocks.inspectit.ocelot.core.logging.logback.LogbackInitializer; | ||
|
||
import java.util.Random; | ||
import java.util.concurrent.Callable; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.concurrent.atomic.AtomicBoolean; | ||
|
||
/** | ||
* Regression test for <a href="https://github.com/inspectIT/inspectit-ocelot/issues/1597">Github issue 1597</a>. | ||
*/ | ||
@DirtiesContext | ||
public class AgentHealthManagerDeadlockGh1597IntTest extends SpringTestBase { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger("test-logger"); | ||
|
||
@Autowired | ||
private AgentHealthManager cut; | ||
|
||
@Test | ||
void testLogging() throws Exception { | ||
// This installs InternalProcessingAppender which together with AgentHealthManager caused a deadlock | ||
LogbackInitializer.initDefaultLogging(); | ||
|
||
int millisToRun = 500; | ||
Thread logThread = new Thread(() -> { | ||
long start = System.currentTimeMillis(); | ||
boolean shouldLogError = true; | ||
while (System.currentTimeMillis() - start < millisToRun) { | ||
if (shouldLogError) { | ||
logger.error("Reporting an error"); | ||
shouldLogError = false; | ||
} else { | ||
logger.info("Reporting an info"); | ||
shouldLogError = true; | ||
} | ||
|
||
} | ||
}); | ||
|
||
AtomicBoolean isInvalidationThreadDone = new AtomicBoolean(false); | ||
|
||
Thread invalidationThread = new Thread(() -> { | ||
long start = System.currentTimeMillis(); | ||
while (System.currentTimeMillis() - start < millisToRun) { | ||
cut.onInvalidationEvent(cut.getClass()); | ||
} | ||
isInvalidationThreadDone.getAndSet(true); | ||
}); | ||
|
||
// letting those two threads run for a while caused the deadlock on the developers machine before the fix. | ||
// This is far from an ideal test, but the best we came up with. | ||
logThread.start(); | ||
invalidationThread.start(); | ||
|
||
Awaitility.waitAtMost(millisToRun * 2, TimeUnit.MILLISECONDS).until(isInvalidationThreadDone::get); | ||
} | ||
|
||
} |