Fix double membership=join event handling
This fixes the problem mentioned in 8e1aa5b11c.
Turns out that it's a long-standing Synapse bug:
https://github.com/matrix-org/synapse/issues/9768
This commit is contained in:
17
bot/bot.go
17
bot/bot.go
@@ -19,14 +19,15 @@ import (
|
||||
|
||||
// Bot represents matrix bot
|
||||
type Bot struct {
|
||||
noowner bool
|
||||
federation bool
|
||||
prefix string
|
||||
domain string
|
||||
rooms map[string]id.RoomID
|
||||
roomsmu *sync.Mutex
|
||||
log *logger.Logger
|
||||
lp *linkpearl.Linkpearl
|
||||
noowner bool
|
||||
federation bool
|
||||
prefix string
|
||||
domain string
|
||||
rooms map[string]id.RoomID
|
||||
roomsmu *sync.Mutex
|
||||
log *logger.Logger
|
||||
lp *linkpearl.Linkpearl
|
||||
handledEvents sync.Map
|
||||
}
|
||||
|
||||
// New creates a new matrix bot
|
||||
|
||||
12
bot/sync.go
12
bot/sync.go
@@ -12,10 +12,6 @@ func (b *Bot) initSync() {
|
||||
b.lp.OnEventType(
|
||||
event.StateMember,
|
||||
func(_ mautrix.EventSource, evt *event.Event) {
|
||||
// Trying to debug the membership=join event being handled twice here.
|
||||
eventJSON, _ := evt.MarshalJSON()
|
||||
b.log.Debug(string(eventJSON))
|
||||
|
||||
go b.onMembership(evt)
|
||||
},
|
||||
)
|
||||
@@ -108,6 +104,14 @@ func (b *Bot) onEncryptedMessage(evt *event.Event) {
|
||||
|
||||
// onBotJoin handles the "bot joined the room" event
|
||||
func (b *Bot) onBotJoin(evt *event.Event, hub *sentry.Hub) {
|
||||
// Workaround for membership=join events which are delivered to us twice,
|
||||
// as described in this bug report: https://github.com/matrix-org/synapse/issues/9768
|
||||
_, exists := b.handledEvents.LoadOrStore(evt.ID, true)
|
||||
if exists {
|
||||
b.log.Info("Suppressing already handled event %s", evt.ID)
|
||||
return
|
||||
}
|
||||
|
||||
ctx := sentry.SetHubOnContext(context.Background(), hub)
|
||||
span := sentry.StartSpan(ctx, "http.server", sentry.TransactionName("onBotJoin"))
|
||||
defer span.Finish()
|
||||
|
||||
Reference in New Issue
Block a user