SpanBatcher serializes spans while holding its buffer lock

Ouverte
#8,023 1 commentaire 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 1 jour

Personne n'a encore pris cette issue.

  • #8170 par @ansh-rohilla — fermée sans fusion

Évaluation

Difficulté
4/5
Temps estimé
3-5 jours
Accessibilité débutants
18/100
Type d'issue
Bug
Clarté
Plutôt claire
Activité
Active
Stack technique
python
Domaine
observability

Piste de recherche

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.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

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.

Langage dominant
Python
Étoiles
2.2k
Forks
713
Merge moyen
1 j 16 min
PR mergées (30 j)
113

Préparer son environnement

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de getsentry/sentry-python

Toutes les issues de getsentry/sentry-python

Issues similaires

Plus d'issues Python

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.