Skip to content

Segmentation fault on 0.31.0 when inside a Temporal activity #1292

Description

@idevelop

I'm not sure if the root cause is with asyncpg or with temporal but this code works fine on 0.30.0, and crashes on 0.31.0 in await asyncpg.connect. Python 3.12.9.

#!/usr/bin/env pythonimportasyncioimportthreadingfromdatetimeimportdatetime, timedeltaimportasyncpgfromtemporalioimportactivity, workflowfromtemporalio.clientimportClientfromtemporalio.workerimportWorkerTASK_QUEUE="asyncpg-temporal-test"asyncdefdb_call(label: str) ->None:
"""Connect to Postgres and close."""loop=asyncio.get_running_loop()
print(f"[{label}] thread={threading.get_ident()} loop_id={id(loop)}{loop!r}")
conn=awaitasyncpg.connect(
host="localhost",
port=5432,
database="database",
user="andrei",
)
print(f"[{label}] connected to Postgres")
awaitconn.close()
@activity.defnasyncdefdb_activity() ->None:
returnawaitdb_call("activity")
@workflow.defnclassTestWorkflow:
@workflow.runasyncdefrun(self) ->None:
print("[workflow] starting db_activity")
returnawaitworkflow.execute_activity(
db_activity,
start_to_close_timeout=timedelta(seconds=30),
task_queue=TASK_QUEUE,
)
asyncdefmain() ->None:
# 1) Baseline: asyncpg on a fresh loop, no Temporalprint("=== 1) Direct asyncpg on fresh loop (no Temporal) ===")
awaitdb_call("direct")
# 2) Bring up Temporal client + worker and run a workflow that calls db_activityprint("\n=== 2) Temporal worker + workflow calling async activity ===")
client=awaitClient.connect("localhost:7233")
worker=Worker(
client,
task_queue=TASK_QUEUE,
workflows=[TestWorkflow],
activities=[db_activity],
)
asyncwithworker:
# This executes TestWorkflow.run, which in turn executes db_activityresult=awaitclient.execute_workflow(
TestWorkflow.run,
id=datetime.now().isoformat(),
task_queue=TASK_QUEUE,
)
print(f"[main] workflow result: {result}")
if__name__=="__main__":
asyncio.run(main())

Repro steps:

  1. Start a temporal server: temporal server start-dev
  2. In a separate terminal, run the code above:
% python test_asyncpg.py === 1) Direct asyncpg on fresh loop (no Temporal) ===
[direct] thread=8654430720 loop_id=4353195520 <_UnixSelectorEventLoop running=True closed=False debug=False>
[direct] connected to Postgres
=== 2) Temporal worker + workflow calling async activity ===
[workflow] starting db_activity
[activity] thread=8654430720 loop_id=4353195520 <_UnixSelectorEventLoop running=True closed=False debug=False>
zsh: segmentation fault python test_asyncpg.py

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions