# Session lifetime for retries

**URL:** <https://community.temporal.io/t/session-lifetime-for-retries/16146>\
**Category:** Community Support\
**Created:** [January 19, 2025, 3:21pm UTC](https://community.temporal.io/t/session-lifetime-for-retries/16146 "2025-01-19T15:21:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![vrcg](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/vrcg/32/6714_2.png) [@vrcg](https://community.temporal.io/u/vrcg)\
**Post date:** [January 19, 2025, 3:21pm UTC](https://community.temporal.io/t/session-lifetime-for-retries/16146/1 "2025-01-19T15:21:30Z")

</div>

Working on file processing, I’ve looked at the file processing example. If I create the session as follows - will the defer close the session on any error even a retriable one?

```
sessionCtx, err := workflow.CreateSession(ctx, &so)
if err != nil {
	return nil, err
}
defer workflow.CompleteSession(sessionCtx)

```

The behavior I want is to keep the session and file for retries, and clean them up on completion, non retryable error etc. How could I achieve that?

---

<div class="post-metadata">

**Author:** ![vrcg](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/vrcg/32/6714_2.png) [@vrcg](https://community.temporal.io/u/vrcg)\
**Post date:** [January 20, 2025, 2:37am UTC](https://community.temporal.io/t/session-lifetime-for-retries/16146/2 "2025-01-20T02:37:11Z")

</div>

I realized this is easier than it seems, activity retries are handled transparently before returning control flow to the workflow.
