Skip to content

Commit

Permalink
fix shutdown race (keybase#23112)
Browse files Browse the repository at this point in the history
  • Loading branch information
mlsteele authored Mar 17, 2020
1 parent 967e4fd commit 37afd9c
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions go/ephemeral/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type EKLib struct {
clock clockwork.Clock
backgroundCreationTestCh chan bool
backgroundDeletionTestCh chan bool
stopCh chan struct{}
stopCh chan<- struct{}
}

var _ libkb.EKLib = (*EKLib)(nil)
Expand All @@ -55,15 +55,16 @@ func NewEKLib(mctx libkb.MetaContext) *EKLib {
// lru.New only panics if size <= 0
log.Panicf("Could not create lru cache: %v", err)
}
stopCh := make(chan struct{})
ekLib := &EKLib{
teamEKGenCache: nlru,
teambotEKMetadataCache: nlru2,
locktab: libkb.NewLockTable(),
clock: clockwork.NewRealClock(),
stopCh: make(chan struct{}),
stopCh: stopCh,
}
if !mctx.G().GetEnv().GetDisableEKBackgroundKeygen() {
go ekLib.backgroundKeygen(mctx)
go ekLib.backgroundKeygen(mctx, stopCh)
}
return ekLib
}
Expand All @@ -84,7 +85,7 @@ func (e *EKLib) Shutdown(mctx libkb.MetaContext) error {
return nil
}

func (e *EKLib) backgroundKeygen(mctx libkb.MetaContext) {
func (e *EKLib) backgroundKeygen(mctx libkb.MetaContext, stopCh <-chan struct{}) {
mctx = mctx.WithLogTag("EKBKG")
mctx.Debug("backgroundKeygen: starting up")
keygenInterval := time.Hour
Expand Down Expand Up @@ -123,7 +124,7 @@ func (e *EKLib) backgroundKeygen(mctx libkb.MetaContext) {
time.Sleep(libkb.RandomJitter(time.Second))
runIfNeeded(false /* force */)
}
case <-e.stopCh:
case <-stopCh:
ticker.Stop()
return
}
Expand Down

0 comments on commit 37afd9c

Please sign in to comment.