Skip to content

invalid memory address or nil pointer dereference with log files larger than 1 MB #38289

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

Closed
pantanuj opened this issue Mar 2, 2025 · 6 comments · Fixed by #38354
Closed

invalid memory address or nil pointer dereference with log files larger than 1 MB #38289

pantanuj opened this issue Mar 2, 2025 · 6 comments · Fixed by #38354
Assignees
Labels
bug Something isn't working pkg/stanza/fileconsumer priority:p0 Critical receiver/otlpjsonfile release:blocker The issue must be resolved before cutting the next release

Comments

@pantanuj
Copy link

pantanuj commented Mar 2, 2025

Component(s)

receiver/otlpjsonfile

What happened?

Description

When the log file size being read exceeds 1 MB, collector errors out with invalid memory address or nil pointer dereference. The stack trace is

2025-03-02T17:07:03.725-0600    info    fileconsumer/file.go:265        Started watching file   {"otelcol.component.id": "otlpjsonfile", "otelcol.component.kind": "Receiver", "otelcol.signal": "traces", "component": "fileconsumer", "path": "C:\\otel-file-export\\logs-metrics.log"}
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x0 addr=0x8 pc=0x71d8005]

goroutine 29 [running]:
go.opentelemetry.io/collector/pdata/plog.Logs.ResourceLogs(...)
        go.opentelemetry.io/collector/[email protected]/plog/logs.go:60
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/otlpjsonfilereceiver.createLogsReceiver.func1({0xc1662f0?, 0xc0011d2690?}, {{0xc002040000?, 0x100000?, 0x0?}, 0xc0014065a0?})
        github.com/open-telemetry/opentelemetry-collector-contrib/receiver/[email protected]/file.go:92 +0x145
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/fileconsumer/internal/reader.(*Reader).readContents(0xc00197c270, {0xc1662f0, 0xc0011d2690})
        github.com/open-telemetry/opentelemetry-collector-contrib/pkg/[email protected]/fileconsumer/internal/reader/reader.go:221 +0x303
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/fileconsumer/internal/reader.(*Reader).ReadToEnd(0xc00197c270, {0xc1662f0, 0xc0011d2690})
        github.com/open-telemetry/opentelemetry-collector-contrib/pkg/[email protected]/fileconsumer/internal/reader/reader.go:117 +0x7c8
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/fileconsumer.(*Manager).consume.func1(0xc00197c270)
        github.com/open-telemetry/opentelemetry-collector-contrib/pkg/[email protected]/fileconsumer/file.go:169 +0x9e
created by github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/fileconsumer.(*Manager).consume in goroutine 86
        github.com/open-telemetry/opentelemetry-collector-contrib/pkg/[email protected]/fileconsumer/file.go:166 +0x1ea

Steps to Reproduce

Configure pipeline to export logs to disk using file exporter. Default settings with max_megabytes set to 2.
Try to read the logs using a separate pipeline with otlpjsonfile receiver. Exporting to debug console for testing.

Expected Result

Log files should be parsed and should be written to console

Actual Result

Log files are parsed if size is small ( less than 1 MB). For any higher size, nil pointer exception is thrown

Collector version

0.120.1

Environment information

Environment

OS: Windows 11

OpenTelemetry Collector configuration

receivers:
  otlpjsonfile:
    include:
      - "C:/otel-file-export/*.log"

processors:
  batch:

exporters:
  debug:
    verbosity: detailed

service:
  pipelines:
    metrics:
      receivers: [otlpjsonfile]
      processors: [batch]
      exporters: [debug]
    traces:
      receivers: [otlpjsonfile]
      processors: [batch]
      exporters: [debug]
    logs:
      receivers: [otlpjsonfile]
      processors: [batch]
      exporters: [debug]

Log output

Additional context

No response

@pantanuj pantanuj added bug Something isn't working needs triage New item requiring triage labels Mar 2, 2025
Copy link
Contributor

github-actions bot commented Mar 2, 2025

Pinging code owners:

See Adding Labels via Comments if you do not have permissions to add labels yourself.

@atoulme atoulme added pkg/stanza/fileconsumer and removed needs triage New item requiring triage labels Mar 3, 2025
Copy link
Contributor

github-actions bot commented Mar 3, 2025

Pinging code owners for pkg/stanza/fileconsumer: @djaglowski. See Adding Labels via Comments if you do not have permissions to add labels yourself. For example, comment '/label priority:p2 -needs-triaged' to set the priority and remove the needs-triaged label.

@VihasMakwana
Copy link
Contributor

@atoulme I'm marking this as a release blocker as it's a regression due to #36715.

@VihasMakwana VihasMakwana self-assigned this Mar 4, 2025
@VihasMakwana VihasMakwana added priority:p0 Critical release:blocker The issue must be resolved before cutting the next release labels Mar 4, 2025
@VihasMakwana
Copy link
Contributor

Fix: #38354

atoulme pushed a commit that referenced this issue Mar 4, 2025
…tric count is greater than 0 (#38354)

<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
#### Description

Fix nil pointer dereference due to empty token

<!-- Issue number (e.g. #1234) or full URL to issue, if applicable. -->
#### Link to tracking issue
Fixes
#38289

<!--Describe what testing was performed and which tests were added.-->
#### Testing

Added test which fails without the fix in place.
@VihasMakwana
Copy link
Contributor

@pantanuj can you please confirm the fix by taking the latest pull?

@pantanuj
Copy link
Author

pantanuj commented Mar 4, 2025

I don't have ability to currently compile the code but I was able to pull in the built binary from the pipeline and test it.

Image

Do not get the error anymore but for larger files it does not show any signals.

Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working pkg/stanza/fileconsumer priority:p0 Critical receiver/otlpjsonfile release:blocker The issue must be resolved before cutting the next release
Projects
None yet
3 participants