Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switching to a different session store leaves memstore goroutine unreleased #222

Open
chucamphong opened this issue Oct 27, 2024 · 0 comments

Comments

@chucamphong
Copy link

chucamphong commented Oct 27, 2024

scs.New() automatically invokes memstore.New(), which creates a goroutine to handle expired session cleanup. Because memstore is the default store, switching to a different store (like gormstore) leaves the memstore goroutine active and unreleased

scs/session.go

Line 106 in 7e11d57

Store: memstore.New(),

// Initialize a new session manager and configure it to use gormstore as the session store.
sessionManager = scs.New()
if sessionManager.Store, err = gormstore.New(db); err != nil {
    log.Fatal(err)
}

Workaround solution:

if memStore, ok := sessionManager.Store.(*memstore.MemStore); ok {
    // HACK: Not sure why, but it seems a delay is needed before stopping the cleanup goroutine.
    time.Sleep(time.Second)
    memStore.StopCleanup()
}

if sessionManager.Store, err = gormstore.New(db); err != nil {
    log.Fatal(err)
}
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

No branches or pull requests

1 participant