1
0
mirror of https://github.com/jhillyerd/inbucket.git synced 2025-12-18 10:07:02 +00:00

datastore: Concurrency fix, closes #77

This commit is contained in:
James Hillyerd
2018-03-09 14:02:15 -08:00
parent a89b6bbca2
commit a3877e4f4b
6 changed files with 111 additions and 1 deletions

View File

@@ -402,7 +402,19 @@ func (ss *Session) dataHandler() {
if ss.server.storeMessages {
// Create a message for each valid recipient
for _, r := range recipients {
if ok := ss.deliverMessage(r, msgBuf); ok {
// TODO temporary hack to fix #77 until datastore revamp
mu, err := ss.server.dataStore.LockFor(r.localPart)
if err != nil {
ss.logError("Failed to get lock for %q: %s", r.localPart, err)
// Delivery failure
ss.send(fmt.Sprintf("451 Failed to store message for %v", r.localPart))
ss.reset()
return
}
mu.Lock()
ok := ss.deliverMessage(r, msgBuf)
mu.Unlock()
if ok {
expReceivedTotal.Add(1)
} else {
// Delivery failure