Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MalformedInputException when /proc/self/mountinfo is not UTF-8 encoded #12418

Open
SoftlySplinter opened this issue Oct 9, 2024 · 0 comments · May be fixed by #12942
Open

MalformedInputException when /proc/self/mountinfo is not UTF-8 encoded #12418

SoftlySplinter opened this issue Oct 9, 2024 · 0 comments · May be fixed by #12942
Labels
bug Something isn't working needs triage New issue that requires triage

Comments

@SoftlySplinter
Copy link

Describe the bug

Running the OpenTelemetry Java Agent on a system that does not use the standard UTF-8 encoding causes a MalformedInputException.

Steps to reproduce

  1. Create the file /proc/self/mountinfo with a non-UTF-8 compatible character encoding.
  2. Run the Java agent, e.g.: java -javaagent:/tmp/opentelemetry-javaagent-2.8.0.jar -Dotel.service.name=myApp-jar myApp.jar

Expected behavior

The /proc/self/mountinfo file should be read in the default system charset without causing an exception.

Actual behavior

The /proc/self/mountinfo file is read in UTF-8.

[otel.javaagent 2024-10-09 09:59:01:490 +0100] [main] INFO io.opentelemetry.javaagent.tooling.VersionLogger - opentelemetry-javaagent - version: 2.8.0
OpenTelemetry Javaagent failed to start
java.lang.ExceptionInInitializerError
        at java.base/java.lang.J9VMInternals.ensureError(J9VMInternals.java:206)
        at java.base/java.lang.J9VMInternals.recordInitializationFailure(J9VMInternals.java:195)
        at io.opentelemetry.instrumentation.resources.ContainerResourceProvider.createResource(ContainerResourceProvider.java:18)
        at io.opentelemetry.sdk.autoconfigure.ResourceConfiguration.configureResource(ResourceConfiguration.java:106) 
        at io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdkBuilder.build(AutoConfiguredOpenTelemetrySdkBuilder.java:439)
        at io.opentelemetry.javaagent.tooling.OpenTelemetryInstaller.installOpenTelemetrySdk(OpenTelemetryInstaller.java:29)
        at io.opentelemetry.javaagent.tooling.AgentInstaller.installBytebuddyAgent(AgentInstaller.java:122)
        at io.opentelemetry.javaagent.tooling.AgentInstaller.installBytebuddyAgent(AgentInstaller.java:102)
        at io.opentelemetry.javaagent.tooling.AgentStarterImpl.start(AgentStarterImpl.java:101)
        at io.opentelemetry.javaagent.bootstrap.AgentInitializer$1.run(AgentInitializer.java:54)
        at io.opentelemetry.javaagent.bootstrap.AgentInitializer$1.run(AgentInitializer.java:48)
        at io.opentelemetry.javaagent.bootstrap.AgentInitializer.execute(AgentInitializer.java:70)
        at io.opentelemetry.javaagent.bootstrap.AgentInitializer.initialize(AgentInitializer.java:47)
        at io.opentelemetry.javaagent.OpenTelemetryAgent.startAgent(OpenTelemetryAgent.java:57)
        at io.opentelemetry.javaagent.OpenTelemetryAgent.premain(OpenTelemetryAgent.java:45)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)   
        at java.base/java.lang.reflect.Method.invoke(Method.java:575)
        at java.instrument/sun.instrument.InstrumentationImpl.loadClassAndStartAgent(InstrumentationImpl.java:491)    
        at java.instrument/sun.instrument.InstrumentationImpl.loadClassAndCallPremain(InstrumentationImpl.java:503)   
Caused by: java.io.UncheckedIOException: java.nio.charset.MalformedInputException: Input length = 1
        at java.base/java.io.BufferedReader$1.hasNext(BufferedReader.java:574)
        at java.base/java.util.Iterator.forEachRemaining(Iterator.java:132)
        at java.base/java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1845)
        at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:522)
        at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:512)
        at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921)
        at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:239)
        at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:682)
        at io.opentelemetry.instrumentation.resources.ContainerResource$Filesystem.lineList(ContainerResource.java:85)
        at io.opentelemetry.instrumentation.resources.CgroupV2ContainerIdExtractor.extractContainerId(CgroupV2ContainerIdExtractor.java:51)
        at io.opentelemetry.instrumentation.resources.ContainerResource.getContainerId(ContainerResource.java:63)     
        at io.opentelemetry.instrumentation.resources.ContainerResource.buildResource(ContainerResource.java:53)      
        at io.opentelemetry.instrumentation.resources.ContainerResource.buildSingleton(ContainerResource.java:34)     
        at io.opentelemetry.instrumentation.resources.ContainerResource.<clinit>(ContainerResource.java:30)
        ... 19 more
Caused by: java.nio.charset.MalformedInputException: Input length = 1
        at java.base/java.nio.charset.CoderResult.throwException(CoderResult.java:274)
        at java.base/sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:370)
        at java.base/sun.nio.cs.StreamDecoder.read(StreamDecoder.java:212)
        at java.base/java.io.InputStreamReader.read(InputStreamReader.java:194)
        at java.base/java.io.BufferedReader.fill(BufferedReader.java:162)
        at java.base/java.io.BufferedReader.readLine(BufferedReader.java:329)
        at java.base/java.io.BufferedReader.readLine(BufferedReader.java:396)
        at java.base/java.io.BufferedReader$1.hasNext(BufferedReader.java:571)
        ... 32 more

Javaagent or library instrumentation version

2.8.0

Environment

JDK: IBM Semeru Runtime Certified Edition for z/OS 17.0.12.1 (build 17.0.12+7)
OS: z/OS 02.05.00

Additional context

The root cause appears to be that Files.lines(Path) is equivalent to Files.lines(path, StandardCharsets.UTF_8).

Switching this to Files.lines(path, Charset.defaultCharset()) in ContainerResource gets me past this issue. Will raise a PR shortly.

@SoftlySplinter SoftlySplinter added bug Something isn't working needs triage New issue that requires triage labels Oct 9, 2024
@breedx-splk breedx-splk linked a pull request Dec 20, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs triage New issue that requires triage
Projects
None yet
1 participant