aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2020-03-13 10:49:42 +0100
committerAlex Auvolat <alex@adnab.me>2020-03-13 10:49:42 +0100
commit6292303a31e9098e8803c9544fc0785023d526fd (patch)
tree756463ffc8565e0906a8709ff211f1ae906b33d7
parent06929747d6ce8898e29e60fc3f53985416b5b1db (diff)
downloadeasybridge-6292303a31e9098e8803c9544fc0785023d526fd.tar.gz
easybridge-6292303a31e9098e8803c9544fc0785023d526fd.zip
Fix message duplication due to a race-condition
-rw-r--r--.gitignore1
-rw-r--r--account.go3
-rw-r--r--server.go4
3 files changed, 8 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
index f4f15a6..3aa79fd 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,3 +2,4 @@ easybridge
config.json
registration.yaml
easybridge.db
+__pycache__
diff --git a/account.go b/account.go
index 7071397..b0313a4 100644
--- a/account.go
+++ b/account.go
@@ -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)
diff --git a/server.go b/server.go
index b982e15..1654971 100644
--- a/server.go
+++ b/server.go
@@ -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",