Make LifecycleTracer thread-safe

The real world may expose the buffers to concurrent accesses even when this is not supposed to be supported.
This commit is contained in:
Chris Vest 2021-03-09 11:57:49 +01:00
parent 2f9aabc915
commit f460c732d0

View File

@ -83,10 +83,12 @@ abstract class LifecycleTracer {
}
void addTrace(Trace trace) {
if (traces.size() == MAX_TRACE_POINTS) {
traces.pollFirst();
synchronized (traces) {
if (traces.size() == MAX_TRACE_POINTS) {
traces.pollFirst();
}
traces.addLast(trace);
}
traces.addLast(trace);
}
@Override
@ -118,9 +120,11 @@ abstract class LifecycleTracer {
@Override
<E extends Throwable> E attachTrace(E throwable) {
long timestamp = System.nanoTime();
for (Trace trace : traces) {
trace.attach(throwable, timestamp);
synchronized (traces) {
long timestamp = System.nanoTime();
for (Trace trace : traces) {
trace.attach(throwable, timestamp);
}
}
return throwable;
}