1
0
mirror of https://blitiri.com.ar/repos/chasquid synced 2025-12-17 14:37:02 +00:00

Use context.WithTimeout instead of context.WithDeadline

There are a few context.WithDeadline calls that can be simplified by
using context.WithTimeout.

At the time they were added, WithTimeout was too new so we didn't want
to depend on it. But now that the minimum Go version has been raised to
1.9, we can simplify the calls.

This patch does that simplification, which is purely mechanical, and
does not change the logic itself.
This commit is contained in:
Alberto Bertogli
2019-07-13 13:44:25 +01:00
parent a92497aef0
commit 2943f994e7
3 changed files with 3 additions and 6 deletions

View File

@@ -58,8 +58,7 @@ func (p *Procmail) Deliver(from string, to string, data []byte) (error, bool) {
}
tr.Debugf("%s %q", p.Binary, args)
ctx, cancel := context.WithDeadline(context.Background(),
time.Now().Add(p.Timeout))
ctx, cancel := context.WithTimeout(context.Background(), p.Timeout)
defer cancel()
cmd := exec.CommandContext(ctx, p.Binary, args...)
cmd.Stdin = bytes.NewReader(data)

View File

@@ -381,8 +381,7 @@ func (item *Item) deliver(q *Queue, rcpt *Recipient) (err error, permanent bool)
if len(c) == 0 {
return fmt.Errorf("empty pipe"), true
}
ctx, cancel := context.WithDeadline(context.Background(),
time.Now().Add(30*time.Second))
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
cmd := exec.CommandContext(ctx, c[0], c[1:]...)
cmd.Stdin = bytes.NewReader(item.Data)

View File

@@ -743,8 +743,7 @@ func (c *Conn) runPostDataHook(data []byte) ([]byte, bool, error) {
defer tr.Finish()
tr.Debugf("running")
ctx, cancel := context.WithDeadline(context.Background(),
time.Now().Add(1*time.Minute))
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Minute)
defer cancel()
cmd := exec.CommandContext(ctx, c.postDataHook)
cmd.Stdin = bytes.NewReader(data)