add per-room mutex, possibly fixes #8
This commit is contained in:
@@ -22,6 +22,7 @@ type Bot struct {
|
|||||||
rooms sync.Map
|
rooms sync.Map
|
||||||
log *logger.Logger
|
log *logger.Logger
|
||||||
lp *linkpearl.Linkpearl
|
lp *linkpearl.Linkpearl
|
||||||
|
mu map[id.RoomID]*sync.Mutex
|
||||||
handledMembershipEvents sync.Map
|
handledMembershipEvents sync.Map
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -35,6 +36,7 @@ func New(lp *linkpearl.Linkpearl, log *logger.Logger, prefix, domain string, noo
|
|||||||
rooms: sync.Map{},
|
rooms: sync.Map{},
|
||||||
log: log,
|
log: log,
|
||||||
lp: lp,
|
lp: lp,
|
||||||
|
mu: map[id.RoomID]*sync.Mutex{},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -49,6 +49,8 @@ func (b *Bot) Send(ctx context.Context, email *utils.Email) error {
|
|||||||
if !ok {
|
if !ok {
|
||||||
return errors.New("room not found")
|
return errors.New("room not found")
|
||||||
}
|
}
|
||||||
|
b.lock(roomID)
|
||||||
|
defer b.unlock(roomID)
|
||||||
|
|
||||||
cfg, err := b.getSettings(roomID)
|
cfg, err := b.getSettings(roomID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
26
bot/mutext.go
Normal file
26
bot/mutext.go
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
package bot
|
||||||
|
|
||||||
|
import (
|
||||||
|
"sync"
|
||||||
|
|
||||||
|
"maunium.net/go/mautrix/id"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (b *Bot) lock(roomID id.RoomID) {
|
||||||
|
_, ok := b.mu[roomID]
|
||||||
|
if !ok {
|
||||||
|
b.mu[roomID] = &sync.Mutex{}
|
||||||
|
}
|
||||||
|
|
||||||
|
b.mu[roomID].Lock()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *Bot) unlock(roomID id.RoomID) {
|
||||||
|
_, ok := b.mu[roomID]
|
||||||
|
if !ok {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
b.mu[roomID].Unlock()
|
||||||
|
delete(b.mu, roomID)
|
||||||
|
}
|
||||||
8
e2e/send-stress
Executable file
8
e2e/send-stress
Executable file
@@ -0,0 +1,8 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
for i in {0..10..1}; do
|
||||||
|
echo "#${i}..."
|
||||||
|
ssmtp test@localhost < $1
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "done"
|
||||||
Reference in New Issue
Block a user