Hi LangChain team, recently we are experiencing some issues related to some of our graph runs getting cancelled (asyncio.CancelledError) in the LangSmith tracing in our Production deployment.
After some debugging using the server log, we found out that during the time these runs getting cancelled, there were quite a few shutdown logs that appeared.
For example, at 7/7/2026, 12:09:26 PM:
[ERROR] The queue surpassed the grace period while shutting down. Some runs may still be running and will be canceled and retried on a healthy instance. The grace period is currently set to 180 seconds. If that is too low, adjust the BG_JOB_SHUTDOWN_GRACE_PERIOD_SECS environment variable to an appropriate value. Signaling shutdown
Traceback (most recent call last):
File "/usr/local/lib/python3.12/asyncio/tasks.py", line 520, in wait_for
return await fut
^^^^^^^^^
File "/api/langgraph_api/worker.py", line 505, in worker
File "/api/langgraph_api/worker.py", line 269, in worker
File "/usr/local/lib/python3.12/asyncio/tasks.py", line 520, in wait_for
return await fut
^^^^^^^^^
File "/api/langgraph_api/worker.py", line 207, in wrap_user_errors
File "/api/langgraph_api/stream.py", line 639, in consume
File "/api/langgraph_api/stream.py", line 665, in _consume_inline
File "/api/langgraph_api/stream.py", line 501, in astream_state
File "/api/langgraph_api/asyncio.py", line 86, in wait_if_not_done
File "/usr/local/lib/python3.12/asyncio/taskgroups.py", line 71, in __aexit__
return await self._aexit(et, exc)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/asyncio/taskgroups.py", line 153, in _aexit
raise propagate_cancellation_error
File "/api/langgraph_api/asyncio.py", line 94, in wait_if_not_done
File "/usr/local/lib/python3.12/site-packages/langgraph/pregel/main.py", line 3455, in astream
async for _ in runner.atick(
File "/usr/local/lib/python3.12/site-packages/langgraph/pregel/_runner.py", line 482, in atick
done, inflight = await asyncio.wait(
^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/asyncio/tasks.py", line 464, in wait
return await _wait(fs, timeout, return_when, loop)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/asyncio/tasks.py", line 550, in _wait
await waiter
asyncio.exceptions.CancelledError
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/storage/langgraph_runtime_postgres/lifespan.py", line 249, in queue_with_signal
File "/storage/langgraph_runtime_postgres/queue.py", line 404, in queue
File "/storage/langgraph_runtime_postgres/queue.py", line 197, in shutdown_queue
File "/usr/local/lib/python3.12/asyncio/tasks.py", line 519, in wait_for
async with timeouts.timeout(timeout):
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/asyncio/timeouts.py", line 115, in __aexit__
raise TimeoutError from exc_val
TimeoutError
We tried to locate the monitoring during that time period. Our hypothesis was that, for a brief moment, since the number of replicas were increasing very substantially and then also went down extremely fast after that, some workers that were executing the runs were getting shutdown. Some of these runs can take quite a decent amount of time (much longer than three minutes), they were getting cancelled and retried on another worker.
We can try to increase the BG_JOB_SHUTDOWN_GRACE_PERIOD_SECS but it won’t help much as a lot of our runs can take up to 20 mins to finish. These runs deal with a lot of user input data and thus the LLM take substantial amount of time to process.
I’m not sure if our diagnosis is correct. Please help us on this and any help is appreciated.
Thank you.
