Skip to content

Python 3.9 segfault in minimal tracing snippet #3801

Closed
@NullHypothesis

Description

@NullHypothesis

The following code reproducibly results in a segmentation fault:

#!/usr/bin/env python3.9

# pip install opentelemetry-sdk
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import (
    BatchSpanProcessor,
    ConsoleSpanExporter,
)

fd = open("foo.txt", "w")
tracer_provider = TracerProvider()
processor = BatchSpanProcessor(ConsoleSpanExporter(out=fd))
tracer_provider.add_span_processor(processor)

If you don't have a copy of Python 3.9 handy, you can use this Dockerfile:

FROM python:3.9.18-slim
RUN pip install opentelemetry-sdk
COPY file.py .
CMD ./file.py

Describe your environment
This happens on both macOS (Sonoma 14.3.1) and Linux (Ubuntu 23.10). As far as I can tell, Python <=3.9 is affected but not Python >=3.10.

Steps to reproduce
The segfault occurs under the following conditions:

  • BatchSpanProcessor must be used (does not happen with SimpleSpanProcessor)
  • out=fd must be passed to ConsoleSpanExporter (does not happen without)
  • fd must not be closed at the end of the file (does not happen with fd.close())

What is the expected behavior?
No segfault.

What is the actual behavior?
Segfault.

Additional context
I realize that Python 3.9 is close to its end-of-life but I figured that there's merit in reporting this issue regardless.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions