Browse Source

Fix message duplication due to a race-condition

master
Alex 11 months ago
parent
commit
6292303a31
3 changed files with 8 additions and 0 deletions
  1. +1
    -0
      .gitignore
  2. +3
    -0
      account.go
  3. +4
    -0
      server.go

+ 1
- 0
.gitignore View File

@ -2,3 +2,4 @@ easybridge
config.json
registration.yaml
easybridge.db
__pycache__

+ 3
- 0
account.go View File

@ -453,6 +453,9 @@ func (a *Account) eventInternal(event *Event) error {
var cache_key string
if event.Id != "" {
dbLockSlot(mx_room_id)
defer dbUnlockSlot(mx_room_id)
// If the event has an ID, make sure it is processed only once
cache_key = fmt.Sprintf("%s/event_seen/%s/%s",
a.Protocol, mx_room_id, event.Id)

+ 4
- 0
server.go View File

@ -165,6 +165,10 @@ func handleTxnEvent(e *mxlib.Event) error {
if acct != nil {
ev.Author = acct.Conn.User()
ev.Room = room.RoomID
dbLockSlot(e.RoomId)
defer dbUnlockSlot(e.RoomId)
created_ev_id, err := acct.Conn.Send(ev)
if err == nil && created_ev_id != "" {
cache_key := fmt.Sprintf("%s/event_seen/%s/%s",

Loading…
Cancel
Save