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

panic: runtime error: invalid memory address or nil pointer dereference #4335

Closed
0michalsokolowski0 opened this issue Jul 18, 2023 · 10 comments · Fixed by #4353
Closed

panic: runtime error: invalid memory address or nil pointer dereference #4335

0michalsokolowski0 opened this issue Jul 18, 2023 · 10 comments · Fixed by #4353
Labels
bug Something isn't working

Comments

@0michalsokolowski0
Copy link

Description

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x78 pc=0xb7e584]

goroutine 46 [running]:
go.opentelemetry.io/otel/sdk/trace.(*forceFlushSpan).Resource(0x1217600?)
:1 +0x24
go.opentelemetry.io/otel/exporters/otlp/otlptrace/internal/tracetransform.Spans({0xc0002d6000, 0x2, 0xc0000966c0?})
/go/pkg/mod/go.opentelemetry.io/otel/exporters/otlp/otlptrace@v1.16.0/internal/tracetransform/span.go:47 +0x183
go.opentelemetry.io/otel/exporters/otlp/otlptrace.(*Exporter).ExportSpans(0xc0000a9d10, {0x164ebf0, 0xc003d17650}, {0xc0002d6000?, 0xc0002d9160?, 0xc00081ec00?})
/go/pkg/mod/go.opentelemetry.io/otel/exporters/otlp/otlptrace@v1.16.0/exporter.go:44 +0x3a
go.opentelemetry.io/otel/sdk/trace.(*batchSpanProcessor).exportSpans(0xc0002072c0, {0x164eb80, 0xc0039680f0?})
/go/pkg/mod/go.opentelemetry.io/otel/sdk@v1.16.0/trace/batch_span_processor.go:269 +0x264
go.opentelemetry.io/otel/sdk/trace.(*batchSpanProcessor).drainQueue(0xc0002072c0)
/go/pkg/mod/go.opentelemetry.io/otel/sdk@v1.16.0/trace/batch_span_processor.go:330 +0x275
go.opentelemetry.io/otel/sdk/trace.NewBatchSpanProcessor.func1()
/go/pkg/mod/go.opentelemetry.io/otel/sdk@v1.16.0/trace/batch_span_processor.go:129 +0x6f
created by go.opentelemetry.io/otel/sdk/trace.NewBatchSpanProcessor
/go/pkg/mod/go.opentelemetry.io/otel/sdk@v1.16.0/trace/batch_span_processor.go:126 +0x2ea

Environment

  • go.opentelemetry.io/otel v1.11.2
  • tlptrace v1.16.0

Expected behavior

No panic.

@0michalsokolowski0 0michalsokolowski0 added the bug Something isn't working label Jul 18, 2023
@dmathieu
Copy link
Member

It looks like your Tracer Provider has a nil resource.

func (s *recordingSpan) Resource() *resource.Resource {

Could you give us a short reproduction example? The way you configure your SDK is probably related to the error here.

@0michalsokolowski0
Copy link
Author

0michalsokolowski0 commented Jul 18, 2023

Could you give us a short reproduction example? The way you configure your SDK is probably related to the error here.

Thanks for the suggestion, I will check that.

Shouldn't there be nil check here? https://github.com/open-telemetry/opentelemetry-go/blob/main/exporters/otlp/otlptrace/internal/tracetransform/span.go#L47
Considering Resource() is pointer

@dmathieu
Copy link
Member

Usually, a provider with a nil resource would be considered an error. There should always be one, even if it's empty.

@pellared
Copy link
Member

@0michalsokolowski0 Any update?

@pellared pellared added the response needed Waiting on user input before progress can be made label Jul 21, 2023
@0michalsokolowski0
Copy link
Author


	res, err := getResource(ctx)
	if err != nil {}

	exporter, err := createExporter(ctx)
	if err != nil {}

	bsp := trace.NewBatchSpanProcessor(exporter)
        ...
}

func getResource(ctx context.Context) (*resource.Resource, error) {
	hostname, _ := os.Hostname()

	return resource.New(
		ctx,
		resource.WithDetectors(gcp.NewDetector()),
		resource.WithTelemetrySDK(),
		resource.WithContainer(),
		resource.WithFromEnv(),
		resource.WithAttributes(
			semconv.ServiceNameKey.String(config.ServiceName()),
			semconv.ServiceNamespaceKey.String("backend"),
			semconv.ServiceInstanceIDKey.String(hostname),
			semconv.DeploymentEnvironmentKey.String(config.EnvID()),
		),
	)
}

func createExporter(ctx context.Context) (*otlptrace.Exporter, error) {
	ctx, cancel := context.WithTimeout(ctx, 10*time.Second)
	defer cancel()

	conn, err := grpc.DialContext(
		ctx,
		config.String("tracing.collector_addr"),
		grpc.WithTransportCredentials(insecure.NewCredentials()),
		grpc.WithBlock(),
	)
	if err != nil {}
	
	exporter, err := otlptracegrpc.New(ctx, otlptracegrpc.WithGRPCConn(conn))
	if err != nil {
		return nil, err
	}

	return exporter, nil
}

@pellared
Copy link
Member

Can you please provide a working example?

@0michalsokolowski0
Copy link
Author

No, I cannot. It randomly killed two pods out of N and happened at least once.

Usually, a provider with a nil resource would be considered an error.

Triggering this seems like the easiest way to reproduce it to me.

@pellared
Copy link
Member

ider with a nil resource would be considered an error.

Triggering this seems like the easiest way to reproduce it to me.

Have you tried it? I do not think it is possible in the latest version.

@0michalsokolowski0
Copy link
Author

I am afraid I don't follow.
There is a pointer that shouldn't ever be nil, but surprisingly it is nil.
Afaik it should be fixed first. I don't have time to try to reproduce something happening randomly now and then.
If that's a problem, I can close the issue.

@pellared
Copy link
Member

pellared commented Jul 24, 2023

I have finally found the bug. See bb0f44f. Thanks for reporting 👍

@pellared pellared removed the response needed Waiting on user input before progress can be made label Jul 25, 2023
@MrAlias MrAlias added this to the v1.17.0/v0.40.0 milestone Aug 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants