Browse Source

fix deadlock

flashmob 7 years ago
parent
commit
ef7478b42f
1 changed files with 7 additions and 0 deletions
  1. 7 0
      backends/gateway.go

+ 7 - 0
backends/gateway.go

@@ -147,6 +147,13 @@ func (gw *BackendGateway) Process(e *mail.Envelope) Result {
 		return NewResult(response.Canned.SuccessMessageQueued + status.queuedID)
 		return NewResult(response.Canned.SuccessMessageQueued + status.queuedID)
 	case <-time.After(gw.saveTimeout()):
 	case <-time.After(gw.saveTimeout()):
 		Log().Error("Backend has timed out while saving email")
 		Log().Error("Backend has timed out while saving email")
+		e.Lock() // lock the envelope - it's still processing here, we don't want the server to recycle it
+		go func() {
+			// keep waiting for the backend to finish processing
+			<-workerMsg.notifyMe
+			e.Unlock()
+			workerMsgPool.Put(workerMsg)
+		}()
 		return NewResult(response.Canned.FailBackendTimeout)
 		return NewResult(response.Canned.FailBackendTimeout)
 	}
 	}
 }
 }