From f5b67b5d3d76abd26aed3348322fe6f1af25eb95 Mon Sep 17 00:00:00 2001 From: Mechiel Lukkien Date: Sat, 1 Mar 2025 18:42:36 +0100 Subject: [PATCH] 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. --- store/init.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/store/init.go b/store/init.go index 8d55912..9c3126c 100644 --- a/store/init.go +++ b/store/init.go @@ -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