tenacity icon indicating copy to clipboard operation
tenacity copied to clipboard

Statistics can be incorrectly initialized inside Temporal contexts

Open 2timesjay opened this issue 9 months ago • 1 comments

Within temporal, an asynchronous python workflow manager, statistics are not being correctly initialized. Given that statistics are on a local thread, my best guess is that a different thread is calling "next_action" than the one that initializes the AsyncRetrying object.

Temporal has a custom AsyncEventLoop, and a function to suspend a job and then "replay" it up to a point, which further complicates its interactions here.

My proposed solution is to either make statistics a normal attribute (I assume this would be pretty delicate), or to ensure we handle uninitialized elements of "statistics" robustly (see PR below)

{
  <...rest of big nested stack trace...>
    raise ApplicationError(
      "cause": {
        "message": "'idle_for'",
        "stackTrace": "  File "/app/venv/lib/python3.10/site-packages/ml/features/workflows.py", line 509, in online_ingest_feature_source
    async for attempt in retry_context:

  File "/app/venv/lib/python3.10/site-packages/tenacity/asyncio/__init__.py", line 166, in __anext__
    do = await self.iter(retry_state=self._retry_state)

  File "/app/venv/lib/python3.10/site-packages/tenacity/asyncio/__init__.py", line 153, in iter
    result = await action(retry_state)

  File "/app/venv/lib/python3.10/site-packages/tenacity/_utils.py", line 99, in inner
    return call(*args, **kwargs)

  File "/app/venv/lib/python3.10/site-packages/tenacity/__init__.py", line 428, in next_action
    self.statistics["idle_for"] += sleep
",
        "applicationFailureInfo": {
          "type": "KeyError"
        }
      },
      "applicationFailureInfo": {}
    },
    "applicationFailureInfo": {}
  },
  "applicationFailureInfo": {}
}

2timesjay avatar Jan 14 '25 14:01 2timesjay