# On\_shutdown node

**URL:** <https://community.livekit.io/t/on-shutdown-node/427>\
**Category:** Agents\
**Tags:** agent-development\
**Created:** [March 1, 2026, 8:08pm UTC](https://community.livekit.io/t/on-shutdown-node/427 "2026-03-01T20:08:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Isaac\_Huntsman](https://sea1.discourse-cdn.com/flex001/user_avatar/community.livekit.io/isaac_huntsman/32/323_2.png) [@Isaac\_Huntsman](https://community.livekit.io/u/Isaac_Huntsman)\
**Post date:** [March 1, 2026, 8:08pm UTC](https://community.livekit.io/t/on-shutdown-node/427/1 "2026-03-01T20:08:24Z")

</div>

Livekit team, is there official documentation on on\_shutdown anywhere? Kind of confusing, as it’s an async function, but it seems like I can’t trust it to execute all my code. I have 3 async functions within on\_shutdown, one makes a db call, another makes an llm chat completion call (standalone), and then one more fast db insert call.

should all execute in \<5s

How should I think about on\_shutdown vs on\_exit?

Seems like the only way I can trust it is by moving all code to an api endpoint and then doing a fire-and-forget in on\_shutdown. What about dirty stops, as in, client’s computer powers off mid-session?

---

<div class="post-metadata">

**Author:** ![darryncampbell](https://sea1.discourse-cdn.com/flex001/user_avatar/community.livekit.io/darryncampbell/32/20_2.png) [@darryncampbell](https://community.livekit.io/u/darryncampbell)\
**Post date:** [March 1, 2026, 11:37pm UTC](https://community.livekit.io/t/on-shutdown-node/427/2 "2026-03-01T23:37:47Z")

</div>

Did you see this? [Job lifecycle | LiveKit Documentation](https://docs.livekit.io/agents/server/job/#post-processing-and-cleanup)

You can adjust this value in the ServerOptions (code here: [agents/livekit-agents/livekit/agents/worker.py at main · livekit/agents · GitHub](https://github.com/livekit/agents/blob/main/livekit-agents/livekit/agents/worker.py#L184))

e.g. `server = AgentServer(shutdown_process_timeout=10)`

---

<div class="post-metadata">

**Author:** ![Isaac\_Huntsman](https://sea1.discourse-cdn.com/flex001/user_avatar/community.livekit.io/isaac_huntsman/32/323_2.png) [@Isaac\_Huntsman](https://community.livekit.io/u/Isaac_Huntsman)\
**Post date:** [March 2, 2026, 6:58am UTC](https://community.livekit.io/t/on-shutdown-node/427/3 "2026-03-02T06:58:53Z")

</div>

yeah I read that doc a few times, but didn’t realize there’s a ServerOptions config. Very helpful. It looks like when running the agent locally I get [Cannot write to closing transpor](https://stackoverflow.com/questions/54462271/what-does-cannot-write-to-closing-transport-mean)t error, but I’m deploying with lk agents create now and I expect it to work. This is very helpful, thank you!
