Skip to content

Commit

Permalink
Prevent sharing JarFile handles between telemetry and the application
Browse files Browse the repository at this point in the history
  • Loading branch information
smola committed Feb 29, 2024
1 parent 7324673 commit 48b9d37
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
import java.util.List;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Level;
import org.openjdk.jmh.annotations.Measurement;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.OutputTimeUnit;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.Warmup;

Expand All @@ -34,6 +36,11 @@ public class DependencyResolverBenchmark {
+ PROJECT_DIR
+ "/src/test/resources/datadog/telemetry/dependencies/spring-boot-app.jar!/BOOT-INF/lib/opentracing-util-0.33.0.jar!/");

@Setup(Level.Trial)
public void setup() {
org.springframework.boot.loader.jar.JarFile.registerUrlProtocolHandler();
}

@Benchmark
public void resolveSimpleJar() {
final List<Dependency> result = DependencyResolver.resolve(SIMPLE_JAR_URI);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,11 @@ private static List<Dependency> extractFromFile(final File jar) throws IOExcepti
private static List<Dependency> extractFromJarURI(final URI uri) throws IOException {
final URL url = uri.toURL();
final JarURLConnection conn = (JarURLConnection) url.openConnection();
// Prevent sharing of jar file handles, which can break Spring Boot's loader.
// https://github.com/DataDog/dd-trace-java/issues/6704
conn.setUseCaches(false);
try (final JarFile jar = conn.getJarFile();
final InputStream is = url.openStream()) {
final InputStream is = conn.getInputStream()) {
return extractFromJarFile(jar, is);
}
}
Expand Down

0 comments on commit 48b9d37

Please sign in to comment.