Skip to content

Set expiry time for sessions loaded by Iterate - #275

Open
yxshee wants to merge 1 commit into
alexedwards:masterfrom
yxshee:fix/iterate-expiry
Open

yxshee wants to merge 1 commit into
alexedwards:masterfrom
yxshee:fix/iterate-expiry

Conversation

@yxshee

@yxshee yxshee commented Nov 9, 2026

Copy link
Copy Markdown

Iterate builds each sessionData from the store without setting expiry, so it is the zero time. Since 481af0a, Commit passes sd.expiry to the store instead of computing it, which means a session that is modified and committed inside the Iterate callback is written with an expiry of 0001-01-01 and is treated as expired on the next request.

// session already in the store with foo=bar
s.Iterate(ctx, func(ctx context.Context) error {
	s.Put(ctx, "baz", "qux")
	_, expiry, err := s.Commit(ctx) // expiry is 0001-01-01 00:00:00 +0000 UTC
	return err
})
// the next request with the same cookie gets an empty session

Iterate now sets the expiry the same way Load does (the deadline, capped by the idle timeout if one is set).

The new TestIterateCommit fails on master:

--- FAIL: TestIterateCommit (0.00s)
    session_test.go:377: got expiry 0001-01-01 00:00:00 +0000 UTC: expected 2026-11-10 08:42:40.620589 +0000 UTC
    session_test.go:387: want "barqux"; got ""

and passes with the fix. go test -race ./..., go vet and gofmt are clean.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant