diff options
author | zeripath <art27@cantab.net> | 2020-05-03 00:04:31 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-03 00:04:31 +0100 |
commit | 4f9d59be17de6714b33e59d89a64c175aaed9381 (patch) | |
tree | b48c2091b12d8c07ef35618371505194b459ded0 /services | |
parent | 319eb8311204675aeb9ece3fbb8e25c8b3e8a98b (diff) | |
download | gitea-4f9d59be17de6714b33e59d89a64c175aaed9381.tar.gz gitea-4f9d59be17de6714b33e59d89a64c175aaed9381.zip |
Sendmail should create a process on the gitea system and have a default timeout (#11256)
* Make sure that sendmail processes register with the process manager
* Provide a timeout for these (initially of 5 minutes)
* Add configurable value and tie in to documentation
* Tie in to the admin config page.
Signed-off-by: Andrew Thornton <art27@cantab.net>
Diffstat (limited to 'services')
-rw-r--r-- | services/mailer/mailer.go | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/services/mailer/mailer.go b/services/mailer/mailer.go index 9ff1729104..2e7beffa15 100644 --- a/services/mailer/mailer.go +++ b/services/mailer/mailer.go @@ -7,6 +7,7 @@ package mailer import ( "bytes" + "context" "crypto/tls" "fmt" "io" @@ -20,6 +21,7 @@ import ( "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/graceful" "code.gitea.io/gitea/modules/log" + "code.gitea.io/gitea/modules/process" "code.gitea.io/gitea/modules/queue" "code.gitea.io/gitea/modules/setting" @@ -244,7 +246,14 @@ func (s *sendmailSender) Send(from string, to []string, msg io.WriterTo) error { args = append(args, setting.MailService.SendmailArgs...) args = append(args, to...) log.Trace("Sending with: %s %v", setting.MailService.SendmailPath, args) - cmd := exec.Command(setting.MailService.SendmailPath, args...) + + pm := process.GetManager() + desc := fmt.Sprintf("SendMail: %s %v", setting.MailService.SendmailPath, args) + + ctx, cancel := context.WithTimeout(graceful.GetManager().HammerContext(), setting.MailService.SendmailTimeout) + defer cancel() + + cmd := exec.CommandContext(ctx, setting.MailService.SendmailPath, args...) pipe, err := cmd.StdinPipe() if err != nil { @@ -255,12 +264,15 @@ func (s *sendmailSender) Send(from string, to []string, msg io.WriterTo) error { return err } + pid := pm.Add(desc, cancel) + _, err = msg.WriteTo(pipe) // we MUST close the pipe or sendmail will hang waiting for more of the message // Also we should wait on our sendmail command even if something fails closeError = pipe.Close() waitError = cmd.Wait() + pm.Remove(pid) if err != nil { return err } else if closeError != nil { |