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