Skip to content

Commit a4d0445

Browse files
committed
fix(core): Disable manifest URL caching when reading versions (JAVA-730)
ManifestVersionReader was retaining jar-backed inflater state while scanning META-INF/MANIFEST.MF entries. Disable URL caching for those reads and close the stream after parsing.
1 parent cfde326 commit a4d0445

2 files changed

Lines changed: 49 additions & 39 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141

4242
### Fixes
4343

44+
- Disable URL caching when reading `META-INF/MANIFEST.MF` files during version detection so that the SDK no longer keeps jar file handles open for the life of the process ([#XXXX](https://github.com/getsentry/sentry-java/pull/XXXX))
4445
- Keep resolving the server name after `Sentry.close()` or a re-init. Closing the SDK shut down the shared hostname cache for the life of the process, so `server_name` silently froze at the value it had last resolved ([#6119](https://github.com/getsentry/sentry-java/pull/6119))
4546
- Order breadcrumbs by the timestamp they carry rather than by when they were created in the current process, so breadcrumbs restored from disk or handed over by a hybrid SDK no longer sort as if they had just happened ([#6097](https://github.com/getsentry/sentry-java/pull/6097))
4647

‎sentry/src/main/java/io/sentry/internal/ManifestVersionReader.java‎

Lines changed: 48 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
import io.sentry.SentryIntegrationPackageStorage;
55
import io.sentry.util.AutoClosableReentrantLock;
66
import java.io.IOException;
7+
import java.io.InputStream;
78
import java.net.URL;
9+
import java.net.URLConnection;
810
import java.util.Enumeration;
911
import java.util.jar.Attributes;
1012
import java.util.jar.Manifest;
@@ -56,48 +58,55 @@ public void readManifestFiles() {
5658
ClassLoader.getSystemClassLoader().getResources("META-INF/MANIFEST.MF");
5759
while (resources.hasMoreElements()) {
5860
try {
59-
final @NotNull Manifest manifest = new Manifest(resources.nextElement().openStream());
60-
final @Nullable Attributes mainAttributes = manifest.getMainAttributes();
61-
if (mainAttributes != null) {
62-
final @Nullable String name = mainAttributes.getValue("Sentry-Opentelemetry-SDK-Name");
63-
final @Nullable String version = mainAttributes.getValue("Implementation-Version");
64-
final @Nullable String sdkName = mainAttributes.getValue("Sentry-SDK-Name");
65-
final @Nullable String packageName = mainAttributes.getValue("Sentry-SDK-Package-Name");
61+
final @NotNull URLConnection connection = resources.nextElement().openConnection();
62+
connection.setUseCaches(false);
63+
try (final @NotNull InputStream inputStream = connection.getInputStream()) {
64+
final @NotNull Manifest manifest = new Manifest(inputStream);
65+
final @Nullable Attributes mainAttributes = manifest.getMainAttributes();
66+
if (mainAttributes != null) {
67+
final @Nullable String name =
68+
mainAttributes.getValue("Sentry-Opentelemetry-SDK-Name");
69+
final @Nullable String version = mainAttributes.getValue("Implementation-Version");
70+
final @Nullable String sdkName = mainAttributes.getValue("Sentry-SDK-Name");
71+
final @Nullable String packageName =
72+
mainAttributes.getValue("Sentry-SDK-Package-Name");
6673

67-
if (name != null && version != null) {
68-
versionInfo.sdkName = name;
69-
versionInfo.sdkVersion = version;
70-
final @Nullable String otelVersion =
71-
mainAttributes.getValue("Sentry-Opentelemetry-Version-Name");
72-
if (otelVersion != null) {
73-
SentryIntegrationPackageStorage.getInstance()
74-
.addPackage("maven:io.opentelemetry:opentelemetry-sdk", otelVersion);
75-
SentryIntegrationPackageStorage.getInstance().addIntegration("OpenTelemetry");
74+
if (name != null && version != null) {
75+
versionInfo.sdkName = name;
76+
versionInfo.sdkVersion = version;
77+
final @Nullable String otelVersion =
78+
mainAttributes.getValue("Sentry-Opentelemetry-Version-Name");
79+
if (otelVersion != null) {
80+
SentryIntegrationPackageStorage.getInstance()
81+
.addPackage("maven:io.opentelemetry:opentelemetry-sdk", otelVersion);
82+
SentryIntegrationPackageStorage.getInstance().addIntegration("OpenTelemetry");
83+
}
84+
final @Nullable String otelJavaagentVersion =
85+
mainAttributes.getValue("Sentry-Opentelemetry-Javaagent-Version-Name");
86+
if (otelJavaagentVersion != null) {
87+
SentryIntegrationPackageStorage.getInstance()
88+
.addPackage(
89+
"maven:io.opentelemetry.javaagent:opentelemetry-javaagent",
90+
otelJavaagentVersion);
91+
SentryIntegrationPackageStorage.getInstance()
92+
.addIntegration("OpenTelemetry-Agent");
93+
}
94+
if (name.equals("sentry.java.opentelemetry.agentless")) {
95+
SentryIntegrationPackageStorage.getInstance()
96+
.addIntegration("OpenTelemetry-Agentless");
97+
}
98+
if (name.equals("sentry.java.opentelemetry.agentless-spring")) {
99+
SentryIntegrationPackageStorage.getInstance()
100+
.addIntegration("OpenTelemetry-Agentless-Spring");
101+
}
76102
}
77-
final @Nullable String otelJavaagentVersion =
78-
mainAttributes.getValue("Sentry-Opentelemetry-Javaagent-Version-Name");
79-
if (otelJavaagentVersion != null) {
80-
SentryIntegrationPackageStorage.getInstance()
81-
.addPackage(
82-
"maven:io.opentelemetry.javaagent:opentelemetry-javaagent",
83-
otelJavaagentVersion);
84-
SentryIntegrationPackageStorage.getInstance().addIntegration("OpenTelemetry-Agent");
85-
}
86-
if (name.equals("sentry.java.opentelemetry.agentless")) {
87-
SentryIntegrationPackageStorage.getInstance()
88-
.addIntegration("OpenTelemetry-Agentless");
89-
}
90-
if (name.equals("sentry.java.opentelemetry.agentless-spring")) {
91-
SentryIntegrationPackageStorage.getInstance()
92-
.addIntegration("OpenTelemetry-Agentless-Spring");
93-
}
94-
}
95103

96-
if (sdkName != null
97-
&& version != null
98-
&& packageName != null
99-
&& sdkName.startsWith("sentry.java")) {
100-
SentryIntegrationPackageStorage.getInstance().addPackage(packageName, version);
104+
if (sdkName != null
105+
&& version != null
106+
&& packageName != null
107+
&& sdkName.startsWith("sentry.java")) {
108+
SentryIntegrationPackageStorage.getInstance().addPackage(packageName, version);
109+
}
101110
}
102111
}
103112
} catch (Exception e) {

0 commit comments

Comments
 (0)