1
0
mirror of https://github.com/alexedwards/scs.git synced 2025-07-13 01:00:17 +02:00

Merge pull request #230 from earthboundkid/cj-race-fix

sqlite3store: Fix race in StopCleanup
This commit is contained in:
Alex Edwards
2025-02-05 22:30:42 +01:00
committed by GitHub
2 changed files with 3 additions and 2 deletions

View File

@ -25,6 +25,7 @@ func New(db *sql.DB) *SQLite3Store {
func NewWithCleanupInterval(db *sql.DB, cleanupInterval time.Duration) *SQLite3Store {
p := &SQLite3Store{db: db}
if cleanupInterval > 0 {
p.stopCleanup = make(chan bool)
go p.startCleanup(cleanupInterval)
}
return p
@ -96,7 +97,6 @@ func (p *SQLite3Store) All() (map[string][]byte, error) {
}
func (p *SQLite3Store) startCleanup(interval time.Duration) {
p.stopCleanup = make(chan bool)
ticker := time.NewTicker(interval)
for {
select {

View File

@ -269,7 +269,6 @@ func TestCleanup(t *testing.T) {
}
p := NewWithCleanupInterval(db, 200*time.Millisecond)
defer p.StopCleanup()
err = p.Commit("session_token", []byte("encoded_data"), time.Now().Add(100*time.Millisecond))
if err != nil {
@ -287,6 +286,8 @@ func TestCleanup(t *testing.T) {
}
time.Sleep(300 * time.Millisecond)
p.StopCleanup()
row = db.QueryRow("SELECT COUNT(*) FROM sessions WHERE token = 'session_token'")
err = row.Scan(&count)
if err != nil {