Shareed2k / goth_fiber

Package goth_fiber provides a simple, clean, and idiomatic way to write authentication packages for fiber framework applications.
MIT License
88 stars 14 forks source link

could not find a matching session for this request when Fiber is preforked or scaled #55

Closed bangbaew closed 1 year ago

bangbaew commented 1 year ago

From what I understand, this module uses session based in memory, where the app retrieves the session id which is a uuid stored in browser cookie with key "_gothic_session", and the session id gets redeemed when passed into the app at CompleteUserAuth() function, however, the problem is when the app is preforked (native to gofiber) or scaled to multiple pods using Kubernetes, if the loadbalancer hits the right PID/pod where the session is stored, I'll get userinfo back correctly, but when it hits the different PID/pod where the session is not stored in, I'll get could not find a matching session for this request, (to demonstrate: if a session id was generated on PID 1, but it was sent to be redeemed on PID 2, this would fail because PID 2 couldn't find it, I have to press refresh until it hits the right instance)

How can I fix this scaling problem?

bangbaew commented 1 year ago

Solved by:

// Optionally, you can override the session store here:
    // goth_fiber.SessionStore = session.New(session.Config{
    //  KeyLookup:          "cookie:dinosaurus",
    //  CookieHTTPOnly: true,
    //  Storage:                sqlite3.New(),
    // })