Skip to content
This repository was archived by the owner on Dec 12, 2022. It is now read-only.

Commit f460c73

Browse files
committed
Make LifecycleTracer thread-safe
The real world may expose the buffers to concurrent accesses even when this is not supposed to be supported.
1 parent 2f9aabc commit f460c73

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/main/java/io/netty/buffer/api/LifecycleTracer.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,12 @@ void acquire(int acquires) {
8383
}
8484

8585
void addTrace(Trace trace) {
86-
if (traces.size() == MAX_TRACE_POINTS) {
87-
traces.pollFirst();
86+
synchronized (traces) {
87+
if (traces.size() == MAX_TRACE_POINTS) {
88+
traces.pollFirst();
89+
}
90+
traces.addLast(trace);
8891
}
89-
traces.addLast(trace);
9092
}
9193

9294
@Override
@@ -118,9 +120,11 @@ public T transferOwnership(Drop<T> drop) {
118120

119121
@Override
120122
<E extends Throwable> E attachTrace(E throwable) {
121-
long timestamp = System.nanoTime();
122-
for (Trace trace : traces) {
123-
trace.attach(throwable, timestamp);
123+
synchronized (traces) {
124+
long timestamp = System.nanoTime();
125+
for (Trace trace : traces) {
126+
trace.attach(throwable, timestamp);
127+
}
124128
}
125129
return throwable;
126130
}

0 commit comments

Comments
 (0)