Commit 2943f994 authored by Alberto Bertogli's avatar Alberto Bertogli

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.
parent a92497ae
......@@ -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(),
ctx, cancel := context.WithTimeout(context.Background(), p.Timeout)
defer cancel()
cmd := exec.CommandContext(ctx, p.Binary, args...)
cmd.Stdin = bytes.NewReader(data)
......@@ -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(),
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)
......@@ -743,8 +743,7 @@ func (c *Conn) runPostDataHook(data []byte) ([]byte, bool, error) {
defer tr.Finish()
ctx, cancel := context.WithDeadline(context.Background(),
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Minute)
defer cancel()
cmd := exec.CommandContext(ctx, c.postDataHook)
cmd.Stdin = bytes.NewReader(data)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment