Skip to content

Commit fbb5d68

Browse files
authored
Fixed BodyCaptureImpl recycling (#3734)
1 parent b0c6af7 commit fbb5d68

File tree

3 files changed

+60
-1
lines changed

3 files changed

+60
-1
lines changed

apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/BodyCaptureImpl.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
/*
2+
* Licensed to Elasticsearch B.V. under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch B.V. licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
119
package co.elastic.apm.agent.impl.context;
220

321
import co.elastic.apm.agent.objectpool.Resetter;
@@ -56,6 +74,7 @@ public void resetState() {
5674
charset.setLength(0);
5775
if (bodyBuffer != null) {
5876
BYTE_BUFFER_POOL.recycle(bodyBuffer);
77+
bodyBuffer = null;
5978
}
6079
}
6180

apm-agent-core/src/test/java/co/elastic/apm/agent/impl/context/BodyCaptureTest.java renamed to apm-agent-core/src/test/java/co/elastic/apm/agent/impl/context/BodyCaptureImplTest.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
/*
2+
* Licensed to Elasticsearch B.V. under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch B.V. licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
119
package co.elastic.apm.agent.impl.context;
220

321
import org.junit.jupiter.api.Test;
@@ -8,7 +26,7 @@
826
import static co.elastic.apm.agent.testutils.assertions.Assertions.assertThat;
927
import static org.assertj.core.api.Assertions.assertThatThrownBy;
1028

11-
public class BodyCaptureTest {
29+
public class BodyCaptureImplTest {
1230

1331
@Test
1432
public void testAppendTruncation() {
@@ -52,5 +70,9 @@ public void testLifecycle() {
5270
// startCapture should return true only once
5371
assertThat(capture.startCapture("foobar", 42))
5472
.isFalse();
73+
74+
capture.resetState();
75+
assertThat(capture.getCharset()).isNull();
76+
assertThat(capture.getBody()).isNull();
5577
}
5678
}

apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/metadata/BodyCapture.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
/*
2+
* Licensed to Elasticsearch B.V. under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch B.V. licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
119
package co.elastic.apm.agent.tracer.metadata;
220

321
import javax.annotation.Nullable;

0 commit comments

Comments
 (0)