diff --git a/sqlite3store/sqlite3store.go b/sqlite3store/sqlite3store.go index ff2860e..7b05ff0 100644 --- a/sqlite3store/sqlite3store.go +++ b/sqlite3store/sqlite3store.go @@ -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 { diff --git a/sqlite3store/sqlite3store_test.go b/sqlite3store/sqlite3store_test.go index 71908a5..dd809f1 100644 --- a/sqlite3store/sqlite3store_test.go +++ b/sqlite3store/sqlite3store_test.go @@ -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 {