File tree Expand file tree Collapse file tree
main/java/io/opentelemetry/sdk/trace
test/java/io/opentelemetry/sdk/trace Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -574,6 +574,7 @@ private void endInternal(long endEpochNanos) {
574574 }
575575 synchronized (lock ) {
576576 hasEnded = EndState .ENDED ;
577+ spanEndingThread = null ;
577578 }
578579 if (spanProcessor .isEndRequired ()) {
579580 spanProcessor .onEnd (this );
Original file line number Diff line number Diff line change @@ -144,6 +144,19 @@ void nothingChangedAfterEnd() {
144144 /* hasEnded= */ true );
145145 }
146146
147+ /**
148+ * {@code SdkSpan.spanEndingThread} prevents concurrent modification of spans while in the ending
149+ * phase such that only {@link ExtendedSpanProcessor#onEnding(ReadWriteSpan)} implementations can
150+ * modify. Here, we verify the thread ref is released so the thread can be garbage collected. This
151+ * is particularly important where processors hold refs to {@link ReadWriteSpan}.
152+ */
153+ @ Test
154+ void end_ReleasesSpanEndingThreadRef () {
155+ SdkSpan span = createTestSpan (SpanKind .INTERNAL );
156+ span .end ();
157+ assertThat (span ).extracting ("spanEndingThread" ).isNull ();
158+ }
159+
147160 @ Test
148161 void endSpanTwice_DoNotCrash () {
149162 SdkSpan span = createTestSpan (SpanKind .INTERNAL );
You can’t perform that action at this time.
0 commit comments