mirror of
https://github.com/mjl-/mox.git
synced 2025-06-28 01:48:15 +03:00
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:
parent
2beb30cc20
commit
f5b67b5d3d
@ -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
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user