mirror of
https://github.com/mjl-/mox.git
synced 2025-06-28 07:48:13 +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 AuthDB *bstore.DB
|
||||||
var AuthDBTypes = []any{TLSPublicKey{}, LoginAttempt{}, LoginAttemptState{}}
|
var AuthDBTypes = []any{TLSPublicKey{}, LoginAttempt{}, LoginAttemptState{}}
|
||||||
|
|
||||||
|
var loginAttemptCleanerStop chan chan struct{}
|
||||||
|
|
||||||
// Init opens auth.db and starts the login writer.
|
// Init opens auth.db and starts the login writer.
|
||||||
func Init(ctx context.Context) error {
|
func Init(ctx context.Context) error {
|
||||||
if AuthDB != nil {
|
if AuthDB != nil {
|
||||||
@ -37,6 +39,7 @@ func Init(ctx context.Context) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
startLoginAttemptWriter()
|
startLoginAttemptWriter()
|
||||||
|
loginAttemptCleanerStop = make(chan chan struct{})
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
defer func() {
|
defer func() {
|
||||||
@ -57,6 +60,9 @@ func Init(ctx context.Context) error {
|
|||||||
pkglog.Check(err, "cleaning up old historic login attempts")
|
pkglog.Check(err, "cleaning up old historic login attempts")
|
||||||
|
|
||||||
select {
|
select {
|
||||||
|
case c := <-loginAttemptCleanerStop:
|
||||||
|
c <- struct{}{}
|
||||||
|
return
|
||||||
case <-t.C:
|
case <-t.C:
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
return
|
return
|
||||||
@ -77,6 +83,10 @@ func Close() error {
|
|||||||
writeLoginAttemptStop <- stopc
|
writeLoginAttemptStop <- stopc
|
||||||
<-stopc
|
<-stopc
|
||||||
|
|
||||||
|
stopc = make(chan struct{})
|
||||||
|
loginAttemptCleanerStop <- stopc
|
||||||
|
<-stopc
|
||||||
|
|
||||||
err := AuthDB.Close()
|
err := AuthDB.Close()
|
||||||
AuthDB = nil
|
AuthDB = nil
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user