flashmob / go-guerrilla

Mini SMTP server written in golang
MIT License
2.78k stars 366 forks source link

Deadlock / race condition if Envelope gets recycled and re-used before the processing is finished #101

Closed flashmob closed 6 years ago

flashmob commented 6 years ago

To save allocating/deallocating RAM, The Envelopes get recycled for each email transaction. Each envelope is borrowed from a pool, and then returned once the middleware is finished saving the email(s). The problem was noticed when a server suffered hard disk degradation, causing each envelope to be processed for more than 30 seconds. This in turn triggered a gateway timeout (set by the gw_save_timeout config prop), which didn't wait for the Envelope to release the lock before continuing with a new transaction for the same connection. Because the Envelope was locked, this causes a race condition and quickly exhausted all envelopes, causing the server to freeze. Additionally, workerMsg were not being returned to the pool after a timeout

Todo