SpanBatcher serializes spans while holding its buffer lock

Đang mở
#8,023 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

  • #8170 của @ansh-rohilla — đã đóng, không merge

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
18/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python
Lĩnh vực
observability

Hướng nghiên cứu

The lock problem lives in SpanBatcher._flush(), which holds _lock while calling _dynamic_sampling_context() and _to_transport_format(). Reproduce it by pausing _to_transport_format on a threading.Event and checking that _lock.acquire(blocking=False) fails from another thread. The author's branch and its three regression tests show the proposed shape, but the approach is still awaiting a maintainer decision, so do not start a patch before that. Done means serialization runs outside the lock and failed serialization restores spans ahead of newer ones.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Bug Python
Problem

SpanBatcher._flush() holds _lock while calling _dynamic_sampling_context() and serializing spans with _to_transport_format(). This blocks concurrent additions for the entire serialization step and leaves a possible re-entrant lock-order hazard. The related fix in #7776 explicitly excludes SpanBatcher.

Reproduction

Patch _to_transport_format to pause on a threading.Event, then try batcher._lock.acquire(blocking=False) from another thread. It fails while serialization is in progress on master.

Proposed fix

Detach selected per-trace buffers under the lock, serialize outside the lock, and restore detached spans ahead of newly arrived spans if serialization fails. Keep the existing per-trace envelope boundaries.

A small candidate patch and three regression tests are on this branch. Local focused tests against SDK 2.61.0: 3 failed on baseline, 3 passed with the patch. Full upstream CI has not been run.

Would this approach be acceptable? I'll hold the draft PR until a maintainer has weighed in, in line with CONTRIBUTING.md.

Ngôn ngữ chính
Python
Star
2.2k
Fork
713
Merge trung bình
1 ngày 16 phút
Pull request đã merge (30 ngày)
113

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của getsentry/sentry-python

Tất cả issue của getsentry/sentry-python

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.