Skip to content

Commit 41df7fc

Browse files
authored
fix gregor client stop (keybase#17129)
* fix gregor client stop * buffer stopCh
1 parent 07d1483 commit 41df7fc

2 files changed

Lines changed: 9 additions & 7 deletions

File tree

‎go/gregor/client/client.go‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ type Client struct {
4040

4141
incomingClient func() gregor1.IncomingInterface
4242
outboxSendCh chan struct{}
43-
stopCh chan struct{}
43+
stopCh chan chan struct{}
4444
createSm func() gregor.StateMachine
4545

4646
// testing events
@@ -57,7 +57,7 @@ func NewClient(user gregor.UID, device gregor.DeviceID, createSm func() gregor.S
5757
Log: log,
5858
clock: clock,
5959
outboxSendCh: make(chan struct{}, 100),
60-
stopCh: make(chan struct{}),
60+
stopCh: make(chan chan struct{}, 10),
6161
incomingClient: incomingClient,
6262
createSm: createSm,
6363
}
@@ -159,8 +159,10 @@ func (c *Client) Restore(ctx context.Context) error {
159159
return nil
160160
}
161161

162-
func (c *Client) Stop() {
163-
close(c.stopCh)
162+
func (c *Client) Stop() chan struct{} {
163+
ch := make(chan struct{})
164+
c.stopCh <- ch
165+
return ch
164166
}
165167

166168
type ErrHashMismatch struct{}
@@ -455,7 +457,6 @@ func (c *Client) StateMachineState(ctx context.Context, t gregor.TimeOrOffset,
455457
}
456458

457459
func (c *Client) outboxSend() {
458-
c.Log.Debug("outboxSend: running")
459460
ctx := context.Background()
460461
msgs, err := c.Sm.Outbox(ctx, c.User)
461462
if err != nil {
@@ -507,7 +508,8 @@ func (c *Client) outboxSendLoop() {
507508
c.outboxSend()
508509
case <-c.outboxSendCh:
509510
c.outboxSend()
510-
case <-c.stopCh:
511+
case ch := <-c.stopCh:
512+
close(ch)
511513
return
512514
}
513515
deadline = now.Add(time.Minute)

‎go/gregor/interface.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ type StateMachine interface {
219219
Outbox(context.Context, UID) ([]Message, error)
220220
RemoveFromOutbox(context.Context, UID, MsgID) error
221221

222-
// PrependToOutbox adds a slice of messages to the beginning of the outbox
222+
// InitOutbox initializes a users outbox with the given messages
223223
InitOutbox(context.Context, UID, []Message) error
224224

225225
// ConsumeOutboxMessage add a message to the outbox

0 commit comments

Comments
 (0)