gofiber / fiber

โšก๏ธ Express inspired web framework written in Go

Home Page:https://gofiber.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

๐Ÿ› [Bug]: memory session store calculating expirations with uint32

luisgarciaalanis opened this issue ยท comments

Bug Description

I added a large timeout because I did not want the session to expire, and this resulted in a situation were the GC() of the store was clearing the memory on its next tick.

How to Reproduce

var store = &SessionStore{
	store: session.New(session.Config{
		Expiration: time.Hour * 24 * 365 * 100,
		Storage: memory.New(),
	}),
}

Expected Behavior

session should not clear the cache.
maybe have a expiration const value like max int to never expire.
github.com/gofiber/fiber/v2 v2.52.4
github.com/gofiber/storage/memory v1.3.4
Probably v3

Fiber Version

v2.52.4

Code Snippet (optional)

var store = &SessionStore{
	store: session.New(session.Config{
		Expiration: time.Hour * 24 * 365 * 100,
		Storage: memory.New(),
	}),
}

var sess, err = store.Get(ctx.FiberCTX())
if err != nil {
    return err
}

sess.Set("data", data)
if err := sess.Save(); err != nil {
     return err
}

Checklist:

  • I agree to follow Fiber's Code of Conduct.
  • I have checked for existing issues that describe my problem prior to opening this one.
  • I understand that improperly formatted bug reports may be closed without explanation.
commented

100 years expire is a little bit to much and not really a real world case

I wanted a long exp to avoid expiration and found the issue. If you think this is not an issue its ok, I just changed my code to 10 years , the cache will expire on rerun of service, and on internal exp field. I use a internal field because I need to distinguish between no session and session expired.