Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lock during HandleOobm #21934

Merged
merged 2 commits into from
Jan 22, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions go/chat/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ type PushHandler struct {
globals.Contextified
utils.DebugLabeler
sync.Mutex
startMu sync.Mutex
eg errgroup.Group
started bool

Expand All @@ -229,8 +230,8 @@ func NewPushHandler(g *globals.Context) *PushHandler {

func (g *PushHandler) Start(ctx context.Context, _ gregor1.UID) {
defer g.Trace(ctx, func() error { return nil }, "Start")()
g.Lock()
defer g.Unlock()
g.startMu.Lock()
defer g.startMu.Unlock()
if g.started {
return
}
Expand All @@ -239,8 +240,8 @@ func (g *PushHandler) Start(ctx context.Context, _ gregor1.UID) {

func (g *PushHandler) Stop(ctx context.Context) chan struct{} {
defer g.Trace(ctx, func() error { return nil }, "Stop")()
g.Lock()
defer g.Unlock()
g.startMu.Lock()
defer g.startMu.Unlock()
ch := make(chan struct{})
if g.started {
g.started = false
Expand Down Expand Up @@ -1313,21 +1314,20 @@ func (g *PushHandler) SubteamRename(ctx context.Context, m gregor.OutOfBandMessa
}

func (g *PushHandler) HandleOobm(ctx context.Context, obm gregor.OutOfBandMessage) (bool, error) {
// Don't process messages if we have not started.
g.startMu.Lock()
defer g.startMu.Unlock()
if !g.started {
return false, nil
}

if g.testingIgnoreBroadcasts {
return false, errors.New("ignoring broadcasts for tests")
}
if obm.System() == nil {
return false, errors.New("nil system in out of band message")
}

// Don't process messages if we have not started.
g.Lock()
if !g.started {
g.Unlock()
return false, nil
}
g.Unlock()

switch obm.System().String() {
case types.PushActivity:
return true, g.Activity(ctx, obm)
Expand Down