Skip to content

Commit

Permalink
Don't close message channel if client doesn't want to recive any long…
Browse files Browse the repository at this point in the history
…er (#541)
  • Loading branch information
hanzei authored Mar 1, 2022
1 parent 608024f commit 545a8f9
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 21 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/Masterminds/sprig/v3 v3.2.2
github.com/google/go-github/v41 v41.0.0
github.com/gorilla/mux v1.8.0
github.com/mattermost/mattermost-plugin-api v0.0.25-0.20220211190716-3a2a7cd9324a
github.com/mattermost/mattermost-plugin-api v0.0.26
github.com/mattermost/mattermost-server/v6 v6.3.0
github.com/microcosm-cc/bluemonday v1.0.18
github.com/pkg/errors v0.9.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -949,8 +949,8 @@ github.com/mattermost/ldap v0.0.0-20201202150706-ee0e6284187d h1:/RJ/UV7M5c7L2TQ
github.com/mattermost/ldap v0.0.0-20201202150706-ee0e6284187d/go.mod h1:HLbgMEI5K131jpxGazJ97AxfPDt31osq36YS1oxFQPQ=
github.com/mattermost/logr/v2 v2.0.15 h1:+WNbGcsc3dBao65eXlceB6dTILNJRIrvubnsTl3zBew=
github.com/mattermost/logr/v2 v2.0.15/go.mod h1:mpPp935r5dIkFDo2y9Q87cQWhFR/4xXpNh0k/y8Hmwg=
github.com/mattermost/mattermost-plugin-api v0.0.25-0.20220211190716-3a2a7cd9324a h1:ng2Y2ESXBY9K3eOjjsz+uIjFkda3ZXrjLOzofckPKl8=
github.com/mattermost/mattermost-plugin-api v0.0.25-0.20220211190716-3a2a7cd9324a/go.mod h1:MM+tZ+36Obm9jqcveoxY2RFbwLaZKZUgR1zUlc0UBYw=
github.com/mattermost/mattermost-plugin-api v0.0.26 h1:h43yUMkRbAmcFYtqbeUdIxxMKp6kRZUebVI6F9ezZpU=
github.com/mattermost/mattermost-plugin-api v0.0.26/go.mod h1:MM+tZ+36Obm9jqcveoxY2RFbwLaZKZUgR1zUlc0UBYw=
github.com/mattermost/mattermost-server/v6 v6.0.0-20220210052000-0d67995eb491 h1:OsIVqOSO2Dn6XNYKBHKbcFzDQIL5qwrocJwWTbTLAS8=
github.com/mattermost/mattermost-server/v6 v6.0.0-20220210052000-0d67995eb491/go.mod h1:5iM6uoWoD+Ywp/497R+iCP2cBt5dTpn8d96kX+EPwFA=
github.com/mattermost/rsc v0.0.0-20160330161541-bbaefb05eaa0/go.mod h1:nV5bfVpT//+B1RPD2JvRnxbkLmJEYXmRaaVl15fsXjs=
Expand Down
2 changes: 1 addition & 1 deletion server/plugin/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,6 @@ func (p *Plugin) HandleClusterEvent(ev model.PluginClusterEvent) {

p.oauthBroker.publishOAuthComplete(event.UserID, event.Err, true)
default:
p.API.LogWarn("unknown cluset event", "id", ev.Id)
p.API.LogWarn("unknown cluster event", "id", ev.Id)
}
}
19 changes: 11 additions & 8 deletions server/plugin/flows.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ const (

func cancelButton() flow.Button {
return flow.Button{
Name: "Cancel",
Name: "Cancel setup",
Color: flow.ColorDanger,
OnClick: flow.Goto(stepCancel),
}
Expand Down Expand Up @@ -470,7 +470,7 @@ You must first register the Mattermost GitHub Plugin as an authorized OAuth app.
return flow.NewStep(stepOAuthInfo).
WithPretext(oauthPretext).
WithText(oauthMessage).
WithImage(fm.pluginURL, "public/new-oauth-application.png").
WithImage("public/new-oauth-application.png").
WithButton(continueButton("")).
WithButton(cancelButton())
}
Expand Down Expand Up @@ -694,13 +694,16 @@ func (fm *FlowManager) submitWebhook(f *flow.Flow, submitted map[string]interfac
return "", nil, nil, errors.Wrap(err, "failed to create hook")
}

select {
case event := <-ch:
if *event.HookID == *hook.ID {
break
var found bool
for !found {
select {
case event, ok := <-ch:
if ok && event != nil && *event.HookID == *hook.ID {
found = true
}
case <-ctx.Done():
return "", nil, nil, errors.New("timed out waiting for webhook event. Please check if the webhook was correctly created")
}
case <-ctx.Done():
return "", nil, nil, errors.New("timed out waiting for webhook event. Please check if the webhook was correctly created")
}

fm.pingBroker.UnsubscribePings(ch)
Expand Down
13 changes: 5 additions & 8 deletions server/plugin/oauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ func (ob *OAuthBroker) UnsubscribeOAuthComplete(userID string, ch <-chan error)

for i, sub := range ob.oauthCompleteSubs[userID] {
if sub == ch {
close(sub)
ob.oauthCompleteSubs[userID] = append(ob.oauthCompleteSubs[userID][:i], ob.oauthCompleteSubs[userID][i+1:]...)
break
}
Expand All @@ -59,13 +58,11 @@ func (ob *OAuthBroker) publishOAuthComplete(userID string, err error, fromCluste
return
}

for _, userSubs := range ob.oauthCompleteSubs {
for _, sub := range userSubs {
// non-blocking send
select {
case sub <- err:
default:
}
for _, userSub := range ob.oauthCompleteSubs[userID] {
// non-blocking send
select {
case userSub <- err:
default:
}
}

Expand Down
1 change: 0 additions & 1 deletion server/plugin/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ func (wb *WebhookBroker) UnsubscribePings(ch <-chan *github.PingEvent) {

for i, sub := range wb.pingSubs {
if sub == ch {
close(sub)
wb.pingSubs = append(wb.pingSubs[:i], wb.pingSubs[i+1:]...)
break
}
Expand Down

0 comments on commit 545a8f9

Please sign in to comment.