Skip to content

Commit 9b9c1af

Browse files
committed
acme/autocert: fix context usage
Context.Err() is not valid before Context.Done(). Updates golang/go#19856 Change-Id: I7605bb227bfc4cb542ef3db49870d4928ce704d1 Reviewed-on: https://go-review.googlesource.com/40396 Run-TryBot: Brad Fitzpatrick <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Alex Vaghin <[email protected]>
1 parent 9ef620b commit 9b9c1af

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

acme/autocert/cache.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,13 @@ func (d DirCache) Put(ctx context.Context, name string, data []byte) error {
7777
if tmp, err = d.writeTempFile(name, data); err != nil {
7878
return
7979
}
80-
// prevent overwriting the file if the context was cancelled
81-
if ctx.Err() != nil {
82-
return // no need to set err
80+
select {
81+
case <-ctx.Done():
82+
// Don't overwrite the file if the context was canceled.
83+
default:
84+
newName := filepath.Join(string(d), name)
85+
err = os.Rename(tmp, newName)
8386
}
84-
name = filepath.Join(string(d), name)
85-
err = os.Rename(tmp, name)
8687
}()
8788
select {
8889
case <-ctx.Done():

0 commit comments

Comments
 (0)