[Bug] MetricBuffer overflow causes PanicException ("You must initialize the reference before using it") on a later retrieve_updates()
Maintainer antworten meist innerhalb von 1 Tag
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Anfängerfreundlichkeit
- 58/100
- Issue-Typ
- Bug
- Klarheit
- Klar beschrieben
- Aktivitätsstatus
- Aktiv
- Tech-Stack
- python
- Bereich
- backend, observability
Rechercherichtung
The panic is reported at sdk-core/crates/common/src/telemetry/metrics/core.rs:121:14, while the reproduction uses Python's MetricBuffer and retrieve_updates(). Start by tracing how overflow affects the metrics buffer reference and how retrieve_updates() drains it. Done means the buffer can overflow and later drains return updates without panicking, as described in the reproduction.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
What are you really trying to do?
Export SDK and workflow metrics through temporalio.runtime.MetricBuffer, draining it periodically with retrieve_updates() from a background asyncio task.
Describe the bug
When a MetricBuffer fills up between drains, core logs Core's metrics buffer is full! Dropping call to record metrics for each dropped update. That part is expected.
After an overflow:
- The first
retrieve_updates()returns only part of the updates. In the reproduction below, aMetricBuffer(2000)filled by 300 workflows each adding to one counter returns 695 updates containing 3 of the 300 counter increments. - A later
retrieve_updates()raisespyo3_runtime.PanicException: You must initialize the reference before using it, panicking atsdk-core/crates/common/src/telemetry/metrics/core.rs:121:14.
PanicException derives from BaseException, so an except Exception around the drain loop does not catch it. The drain task dies, the buffer is never drained again, and every later metric is dropped for the life of the process, with one ERROR log line per dropped update.
Expected: overflow drops updates (as logged), but later drains keep working and return consistent updates, with no panic.
The MetricBuffer docstring describes overflow as a drop plus a logged error:
It is important that the buffer size is set to a high number and that
retrieve_updatesis called regularly to drain the buffer. If the buffer is full, metric updates will be dropped and an error will be logged.
Minimal Reproduction
The script below uses a small buffer and doesn't drain while the first 300 workflows run, so that it overflows on purpose. We first hit it with MetricBuffer(50_000) drained every 60 seconds, when a burst of workflow activity filled the buffer between two drains.
Run with uv run --with temporalio==1.35.0 python -I repro.py. It uses WorkflowEnvironment.start_local(), so no separate server is needed.
import asyncio
from temporalio import workflow
from temporalio.runtime import MetricBuffer, Runtime, TelemetryConfig
from temporalio.testing import WorkflowEnvironment
from temporalio.worker import UnsandboxedWorkflowRunner, Worker
@workflow.defn
class MyWorkflow:
@workflow.run
async def run(self) -> None:
workflow.metric_meter().create_counter("my_counter").add(1)
async def main() -> None:
buffer = MetricBuffer(2000)
runtime = Runtime(telemetry=TelemetryConfig(metrics=buffer))
async with await WorkflowEnvironment.start_local(runtime=runtime) as env:
async with Worker(
env.client,
task_queue="my-task-queue",
workflows=[MyWorkflow],
workflow_runner=UnsandboxedWorkflowRunner(),
):
async def run_workflows(prefix: str, count: int) -> None:
await asyncio.gather(
*[
env.client.execute_workflow(
MyWorkflow.run,
id=f"{prefix}-{i}",
task_queue="my-task-queue",
)
for i in range(count)
]
)
await run_workflows("first", 300)
for attempt in (1, 2):
updates = buffer.retrieve_updates()
count = sum(1 for u in updates if u.metric.name == "my_counter")
print(f"retrieve_updates #{attempt}: {len(updates)} updates, my_counter={count}")
await run_workflows(f"after-{attempt}", 20)
asyncio.run(main())
Output (the Core's metrics buffer is full! ERROR lines, 8305 in my run, are omitted):
retrieve_updates #1: 695 updates, my_counter=3
thread '<unnamed>' panicked at sdk-core/crates/common/src/telemetry/metrics/core.rs:121:14:
...
pyo3_runtime.PanicException: You must initialize the reference before using it
The panic is raised by the second retrieve_updates(). In this script the first 300 workflows run without any drain, and a further 20 workflows run between the two drains.
Environment/Versions
- OS and processor: macOS arm64
- Temporal Version: temporalio 1.35.0 (Python SDK, from PyPI); Temporal CLI 1.9.1 dev server (Server 1.32.0) started by
WorkflowEnvironment.start_local() - Python: 3.14.2
- Are you using Docker or Kubernetes or building Temporal from source? No, PyPI wheel.
Additional context
None.
- Vorherrschende Sprache
- Python
- Sterne
- 1.2k
- Forks
- 285
- Ø Merge
- 1 T. 21 Std.
- Gemergte PRs (30 T.)
- 80
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Keine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus temporalio/sdk-python
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 18/100
temporalio/sdk-python#2080 ·
Maintainer antworten meist innerhalb von 1 Tag
-
[Bug] Sandboxed datetime hints can fail decoding and drop signalsEvtl. vergeben @VegetarianOrc hat das vor 3 Tagen übernommen. Offensdk-python
temporalio/sdk-python#2072 · 1 zugewiesene Person ·
Maintainer antworten meist innerhalb von 1 Tag
-
[Bug] TaskGroup cancellation of mixed Temporal operations can break replayEvtl. vergeben @VegetarianOrc hat das vor 3 Tagen übernommen. Offensdk-python
temporalio/sdk-python#2069 · 1 zugewiesene Person ·
Maintainer antworten meist innerhalb von 1 Tag
-
sdk-python
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 22/100
temporalio/sdk-python#2067 · 2 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
-
[Bug] lambda_worker otel.apply_defaults leaks a span exporter thread and gRPC channel on every warm invocationEvtl. vergeben @avanish-garg hat das vor 8 Tagen übernommen. Offenbug sdk-python
Schwierigkeit 4/5 1-2 Tage Anfängerfreundlichkeit 30/100
temporalio/sdk-python#2040 ·
Maintainer antworten meist innerhalb von 1 Tag
Alle Issues in temporalio/sdk-python
Ähnliche Issues
-
documentation good first issue
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 88/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 84/100
MarketSquare/robotframework-browser#5479 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Visual COBOL: missing 11.0 and 12.0, and 9.0 date differs from Rocket Software's lifecycle pageOffen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
endoflife-date/endoflife.date#11561 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
OCA/l10n-brazil#5602 ·
Maintainer antworten meist innerhalb von 1 Tag
-
documentation review-2.0.0
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
dkuenzel/meshcore-home-gateway#106 ·
Maintainer antworten meist innerhalb von 1 Tag