File tree Expand file tree Collapse file tree 2 files changed +13
-1
lines changed
Expand file tree Collapse file tree 2 files changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -36,12 +36,14 @@ type Challenge struct {
3636
3737type UserChalenges struct {
3838 chalenges map [string ]Challenge
39+ stopChannel chan struct {}
3940 mu sync.RWMutex
4041}
4142
4243func NewUserChalenges () * UserChalenges {
4344 uc := & UserChalenges {
4445 chalenges : make (map [string ]Challenge ),
46+ stopChannel : make (chan struct {}),
4547 }
4648
4749 go uc .cleanupExpired ()
@@ -51,7 +53,8 @@ func NewUserChalenges() *UserChalenges {
5153func (uc * UserChalenges ) cleanupExpired () {
5254 t := time .Tick (time .Minute * 1 )
5355
54- for range t {
56+ select {
57+ case <- t :
5558 uc .mu .Lock ()
5659 for k , v := range uc .chalenges {
5760 if time .Since (v .Created ) >= challengeTimeToLive {
@@ -60,9 +63,16 @@ func (uc *UserChalenges) cleanupExpired() {
6063 }
6164 }
6265 uc .mu .Unlock ()
66+ case <- uc .stopChannel :
67+ return
6368 }
6469}
6570
71+ func (uc * UserChalenges ) ShutDown () {
72+ close (uc .stopChannel )
73+ slog .Info ("Cleaned up resourses" )
74+ }
75+
6676func (uc * UserChalenges ) Add () (string , string ) {
6777 uc .mu .Lock ()
6878 defer uc .mu .Unlock ()
Original file line number Diff line number Diff line change @@ -26,6 +26,8 @@ func main() {
2626
2727 passwordStore := render_folder .NewPasswordIdStore ()
2828 userChallenges := auth .NewUserChalenges ()
29+ defer userChallenges .ShutDown ()
30+
2931 mu := router .NewMutexHandler (passwordStore , userChallenges )
3032
3133 fs := http .FileServer (http .FS (clientAssets ))
You can’t perform that action at this time.
0 commit comments