Clean up the loginattemptclear goroutine with store.Close()

It is called a lot from the test code, so it would spawn lots of those goroutines.
This commit is contained in:
Mechiel Lukkien 2025-03-01 18:42:36 +01:00
parent 2beb30cc20
commit f5b67b5d3d
No known key found for this signature in database

View File

@ -21,6 +21,8 @@ import (
var AuthDB *bstore.DB
var AuthDBTypes = []any{TLSPublicKey{}, LoginAttempt{}, LoginAttemptState{}}
var loginAttemptCleanerStop chan chan struct{}
// Init opens auth.db and starts the login writer.
func Init(ctx context.Context) error {
if AuthDB != nil {
@ -37,6 +39,7 @@ func Init(ctx context.Context) error {
}
startLoginAttemptWriter()
loginAttemptCleanerStop = make(chan chan struct{})
go func() {
defer func() {
@ -57,6 +60,9 @@ func Init(ctx context.Context) error {
pkglog.Check(err, "cleaning up old historic login attempts")
select {
case c := <-loginAttemptCleanerStop:
c <- struct{}{}
return
case <-t.C:
case <-ctx.Done():
return
@ -77,6 +83,10 @@ func Close() error {
writeLoginAttemptStop <- stopc
<-stopc
stopc = make(chan struct{})
loginAttemptCleanerStop <- stopc
<-stopc
err := AuthDB.Close()
AuthDB = nil